Translate category names.
This commit is contained in:
parent
a7828bcb9e
commit
ff946f6a7d
@ -58,7 +58,7 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade
|
|||||||
|
|
||||||
void bindModel(@NonNull String categoryName) {
|
void bindModel(@NonNull String categoryName) {
|
||||||
currentCategory = categoryName;
|
currentCategory = categoryName;
|
||||||
heading.setText(categoryName);
|
heading.setText(translateCategory(categoryName));
|
||||||
viewAll.setVisibility(View.INVISIBLE);
|
viewAll.setVisibility(View.INVISIBLE);
|
||||||
loaderManager.initLoader(currentCategory.hashCode(), null, this);
|
loaderManager.initLoader(currentCategory.hashCode(), null, this);
|
||||||
loaderManager.initLoader(currentCategory.hashCode() + 1, null, this);
|
loaderManager.initLoader(currentCategory.hashCode() + 1, null, this);
|
||||||
@ -66,6 +66,16 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade
|
|||||||
background.setBackgroundColor(getBackgroundColour(categoryName));
|
background.setBackgroundColor(getBackgroundColour(categoryName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to translate category name with fallback to default name if no translation available
|
||||||
|
*/
|
||||||
|
private String translateCategory(@NonNull String categoryName) {
|
||||||
|
String resId = categoryName.replace(" & ", "_").replace(" ", "_").replace("'", "");
|
||||||
|
int id = activity.getResources().getIdentifier("category_" + resId, "string", activity.getPackageName());
|
||||||
|
return id == 0 ? categoryName : activity.getString(id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static int getBackgroundColour(@NonNull String categoryName) {
|
public static int getBackgroundColour(@NonNull String categoryName) {
|
||||||
// Seed based on the categoryName, so that each time we try to choose a colour for the same
|
// Seed based on the categoryName, so that each time we try to choose a colour for the same
|
||||||
// category it will look the same for each different user, and each different session.
|
// category it will look the same for each different user, and each different session.
|
||||||
@ -130,6 +140,7 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade
|
|||||||
appCardsAdapter.setAppCursor(null);
|
appCardsAdapter.setAppCursor(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
private final View.OnClickListener onViewAll = new View.OnClickListener() {
|
private final View.OnClickListener onViewAll = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user