From b9119fb2b2c6e565bb4675f1c80436997ec29fc6 Mon Sep 17 00:00:00 2001 From: sergosm Date: Thu, 27 Aug 2020 16:22:45 +0300 Subject: [PATCH 1/2] Fix #9636 --- .../editors/SelectCategoryDialogFragment.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java index 8875949d3f..2af96e1cb3 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java @@ -93,6 +93,9 @@ public class SelectCategoryDialogFragment extends DialogFragment { if (category.isVisible()) { ll.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()), category.getColor())); + } else { + ll.addView(createCategoryItemHidden(activity, nightMode, category.getDisplayName(getContext()), + category.getColor())); } } } @@ -153,6 +156,32 @@ public class SelectCategoryDialogFragment extends DialogFragment { return itemView; } + private View createCategoryItemHidden(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor) { + View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_category_dialog_item, null); + Button button = (Button)itemView.findViewById(R.id.button); + button.setCompoundDrawablesWithIntrinsicBounds(getIcon(activity, R.drawable.ic_action_hide), null, null, null); + button.setCompoundDrawablePadding(AndroidUtils.dpToPx(activity,15f)); + String name = categoryName.length() == 0 ? getString(R.string.shared_string_favorites) : categoryName; + button.setText(name); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FragmentActivity a = getActivity(); + if (a instanceof MapActivity) { + PointEditor pointEditor = ((MapActivity) a).getContextMenu().getPointEditor(editorTag); + if (pointEditor != null) { + pointEditor.setCategory(categoryName, categoryColor); + } + if (selectionListener != null) { + selectionListener.onCategorySelected(categoryName, categoryColor); + } + } + dismiss(); + } + }); + return itemView; + } + public static SelectCategoryDialogFragment createInstance(String editorTag) { SelectCategoryDialogFragment fragment = new SelectCategoryDialogFragment(); Bundle bundle = new Bundle(); From f42c78b3f73e2b995aa4007ab14f05dc895d5d32 Mon Sep 17 00:00:00 2001 From: sergosm Date: Thu, 3 Sep 2020 13:41:56 +0300 Subject: [PATCH 2/2] remove_duplicate_code --- .../editors/SelectCategoryDialogFragment.java | 56 +++++-------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java index 2af96e1cb3..09ca84550b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java @@ -84,21 +84,17 @@ public class SelectCategoryDialogFragment extends DialogFragment { if (gpxCategories != null) { for (Map.Entry e : gpxCategories.entrySet()) { String categoryName = e.getKey(); - ll.addView(createCategoryItem(activity, nightMode, categoryName, e.getValue())); + ll.addView(createCategoryItem(activity, nightMode, categoryName, e.getValue(), false)); } } } else { List gs = helper.getFavoriteGroups(); for (final FavouritesDbHelper.FavoriteGroup category : gs) { - if (category.isVisible()) { - ll.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()), - category.getColor())); - } else { - ll.addView(createCategoryItemHidden(activity, nightMode, category.getDisplayName(getContext()), - category.getColor())); - } + ll.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()), + category.getColor(), !category.isVisible())); } } + View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_category_dialog_item, null); Button button = (Button)itemView.findViewById(R.id.button); button.setCompoundDrawablesWithIntrinsicBounds(getIcon(activity, R.drawable.ic_zoom_in), null, null, null); @@ -123,43 +119,21 @@ public class SelectCategoryDialogFragment extends DialogFragment { return builder.create(); } - private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor) { + private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, boolean isHidden) { View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_category_dialog_item, null); Button button = (Button)itemView.findViewById(R.id.button); - if (categoryColor != 0) { - button.setCompoundDrawablesWithIntrinsicBounds( - getIcon(activity, R.drawable.ic_action_folder, categoryColor), null, null, null); + if(isHidden){ + button.setCompoundDrawablesWithIntrinsicBounds(getIcon(activity, R.drawable.ic_action_hide), null, null, null); } else { - button.setCompoundDrawablesWithIntrinsicBounds( - getIcon(activity, R.drawable.ic_action_folder, ContextCompat.getColor(activity, - gpxFile != null ? R.color.gpx_color_point : R.color.color_favorite)), null, null, null); - } - button.setCompoundDrawablePadding(AndroidUtils.dpToPx(activity,15f)); - String name = categoryName.length() == 0 ? getString(R.string.shared_string_favorites) : categoryName; - button.setText(name); - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - FragmentActivity a = getActivity(); - if (a instanceof MapActivity) { - PointEditor pointEditor = ((MapActivity) a).getContextMenu().getPointEditor(editorTag); - if (pointEditor != null) { - pointEditor.setCategory(categoryName, categoryColor); - } - if (selectionListener != null) { - selectionListener.onCategorySelected(categoryName, categoryColor); - } - } - dismiss(); + if (categoryColor != 0) { + button.setCompoundDrawablesWithIntrinsicBounds( + getIcon(activity, R.drawable.ic_action_folder, categoryColor), null, null, null); + } else { + button.setCompoundDrawablesWithIntrinsicBounds( + getIcon(activity, R.drawable.ic_action_folder, ContextCompat.getColor(activity, + gpxFile != null ? R.color.gpx_color_point : R.color.color_favorite)), null, null, null); } - }); - return itemView; - } - - private View createCategoryItemHidden(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor) { - View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_category_dialog_item, null); - Button button = (Button)itemView.findViewById(R.id.button); - button.setCompoundDrawablesWithIntrinsicBounds(getIcon(activity, R.drawable.ic_action_hide), null, null, null); + } button.setCompoundDrawablePadding(AndroidUtils.dpToPx(activity,15f)); String name = categoryName.length() == 0 ? getString(R.string.shared_string_favorites) : categoryName; button.setText(name);