Fix wrong category name in add/edit favorite

This commit is contained in:
Dima-1 2020-01-08 14:39:53 +02:00
parent 9a4f043a64
commit 19419d7d55
3 changed files with 9 additions and 8 deletions

View file

@ -83,6 +83,8 @@ public class FavouritesDbHelper {
public static String getDisplayName(String name, Context ctx) { public static String getDisplayName(String name, Context ctx) {
if (isPersonal(name)) { if (isPersonal(name)) {
return ctx.getString(R.string.personal_category_name); return ctx.getString(R.string.personal_category_name);
} else if (name.isEmpty()) {
return ctx.getString(R.string.shared_string_favorites);
} else { } else {
return name; return name;
} }
@ -108,7 +110,7 @@ public class FavouritesDbHelper {
return getDisplayName(name, ctx); return getDisplayName(name, ctx);
} }
public String convertDisplayNameToGroupIdName(Context context, String name) { public static String convertDisplayNameToGroupIdName(Context context, String name) {
if (name.equals(context.getString(R.string.personal_category_name))) { if (name.equals(context.getString(R.string.personal_category_name))) {
return PERSONAL_CATEGORY; return PERSONAL_CATEGORY;
} }

View file

@ -71,7 +71,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
View view = super.onCreateView(inflater, container, savedInstanceState); View view = super.onCreateView(inflater, container, savedInstanceState);
FavoritePointEditor editor = getFavoritePointEditor(); FavoritePointEditor editor = getFavoritePointEditor();
if (view != null && editor != null && editor.isNew()) { if (view != null && editor != null && editor.isNew()) {
Button replaceButton = (Button) view.findViewById(R.id.replace_button); Button replaceButton = view.findViewById(R.id.replace_button);
replaceButton.setTextColor(getResources().getColor(!editor.isLight() ? R.color.osmand_orange : R.color.map_widget_blue)); replaceButton.setTextColor(getResources().getColor(!editor.isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
replaceButton.setVisibility(View.VISIBLE); replaceButton.setVisibility(View.VISIBLE);
replaceButton.setOnClickListener(new View.OnClickListener() { replaceButton.setOnClickListener(new View.OnClickListener() {
@ -147,7 +147,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
public void setCategory(String name, int color) { public void setCategory(String name, int color) {
FavouritesDbHelper helper = getHelper(); FavouritesDbHelper helper = getHelper();
if (helper != null) { if (helper != null) {
FavoriteGroup group = helper.getGroup(name); FavoriteGroup group = helper.getGroup(FavouritesDbHelper.FavoriteGroup.convertDisplayNameToGroupIdName(requireContext(), name));
this.group = group; this.group = group;
super.setCategory(name, group.getColor()); super.setCategory(name, group.getColor());
} }
@ -310,7 +310,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
@Override @Override
public String getCategoryInitValue() { public String getCategoryInitValue() {
FavouritePoint favorite = getFavorite(); FavouritePoint favorite = getFavorite();
return favorite == null || favorite.getCategory().length() == 0 ? getDefaultCategoryName() : favorite.getCategoryDisplayName(getContext()); return favorite == null || favorite.getCategory().length() == 0 ? getDefaultCategoryName() : favorite.getCategoryDisplayName(requireContext());
} }
@Override @Override

View file

@ -132,14 +132,13 @@ public class SelectCategoryDialogFragment extends DialogFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
FragmentActivity a = getActivity(); FragmentActivity a = getActivity();
if (a != null && a instanceof MapActivity) { if (a instanceof MapActivity) {
String categoryInternalName = categoryName.equals(a.getString(R.string.personal_category_name)) ? PERSONAL_CATEGORY : categoryName;
PointEditor pointEditor = ((MapActivity) a).getContextMenu().getPointEditor(editorTag); PointEditor pointEditor = ((MapActivity) a).getContextMenu().getPointEditor(editorTag);
if (pointEditor != null) { if (pointEditor != null) {
pointEditor.setCategory(categoryInternalName, categoryColor); pointEditor.setCategory(categoryName, categoryColor);
} }
if (selectionListener != null) { if (selectionListener != null) {
selectionListener.onCategorySelected(categoryInternalName, categoryColor); selectionListener.onCategorySelected(categoryName, categoryColor);
} }
} }
dismiss(); dismiss();