diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index f6bb1866e7..4b9dc43eb3 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -679,6 +679,16 @@ public class FavouritesDbHelper { return favoriteGroups; } + public boolean isGroupVisible(String name) { + String nameLowercase = name.toLowerCase(); + for (String groupName : flatGroups.keySet()) { + if (groupName.toLowerCase().equals(nameLowercase) || FavoriteGroup.getDisplayName(context, groupName).equals(name)) { + return flatGroups.get(groupName).isVisible(); + } + } + return false; + } + public boolean groupExists(String name) { String nameLowercase = name.toLowerCase(); for (String groupName : flatGroups.keySet()) { @@ -800,10 +810,12 @@ public class FavouritesDbHelper { public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) { if (color != 0 && group.color != color) { FavoriteGroup gr = flatGroups.get(group.name); - group.color = color; for (FavouritePoint p : gr.points) { - p.setColor(color); + if (p.getColor() == group.color) { + p.setColor(color); + } } + group.color = color; runSyncWithMarkers(gr); } if (group.visible != visible) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java index 2362252307..b3159922cf 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java @@ -97,7 +97,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { } }); if (editor != null && editor.isNew()) { - ImageView toolbarAction = (ImageView) view.findViewById(R.id.toolbar_action); + ImageView toolbarAction = view.findViewById(R.id.toolbar_action); toolbarAction.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -460,30 +460,36 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { @Override public Set getCategories() { Set categories = new LinkedHashSet<>(); + Set categoriesHidden = new LinkedHashSet<>(); FavouritesDbHelper helper = getHelper(); if (helper != null && editor != null) { OsmandApplication app = getMyApplication(); - if (editor.isNew()) { - FavoriteGroup lastUsedGroup = helper.getGroup(getLastUsedGroup()); - if (lastUsedGroup != null && lastUsedGroup.isVisible()) { - categories.add(lastUsedGroup.getDisplayName(app)); - } - for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) { - if (!fg.equals(lastUsedGroup) && fg.isVisible()) { - categories.add(fg.getDisplayName(app)); - } - } - } else { - for (FavoriteGroup fg : helper.getFavoriteGroups()) { + FavoriteGroup lastUsedGroup = helper.getGroup(getLastUsedGroup()); + if (lastUsedGroup != null) { + categories.add(lastUsedGroup.getDisplayName(app)); + } + for (FavouritesDbHelper.FavoriteGroup fg : helper.getFavoriteGroups()) { + if (!fg.equals(lastUsedGroup)) { if (fg.isVisible()) { categories.add(fg.getDisplayName(app)); + } else { + categoriesHidden.add(fg.getDisplayName(app)); } } } + categories.addAll(categoriesHidden); } return categories; } + @Override + public boolean isCategoryVisible(String name) { + if (getHelper() != null) { + return getHelper().isGroupVisible(name); + } + return true; + } + @Override public int getCategoryPointsCount(String category) { FavouritesDbHelper helper = getHelper(); @@ -498,6 +504,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { } @Override + @ColorInt public int getCategoryColor(String category) { FavouritesDbHelper helper = getHelper(); if (helper != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java index 70697426ed..68ada0922b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -5,6 +5,7 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.graphics.Rect; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Build; @@ -675,6 +676,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { public void setCategory(String name, int color) { setSelectedItemWithScroll(name); + updateColorSelector(color, groupRecyclerView.getRootView()); } private void setSelectedItemWithScroll(String name) { @@ -732,6 +734,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { public abstract String getToolbarTitle(); + @ColorInt public abstract int getCategoryColor(String category); public abstract int getCategoryPointsCount(String category); @@ -762,6 +765,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { public abstract Set getCategories(); + protected boolean isCategoryVisible(String name) { + return true; + } + + ; + String getNameTextValue() { EditText nameEdit = view.findViewById(R.id.name_edit); return nameEdit.getText().toString().trim(); @@ -885,16 +894,13 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { public void onClick(View view) { int previousSelectedPosition = getItemPosition(selectedItemName); selectedItemName = items.get(holder.getAdapterPosition()); + updateColorSelector(getCategoryColor(selectedItemName), groupRecyclerView.getRootView()); notifyItemChanged(holder.getAdapterPosition()); notifyItemChanged(previousSelectedPosition); } }); final String group = items.get(position); holder.groupName.setText(group); - int categoryColor = getCategoryColor(group); - int color = categoryColor == 0 ? getDefaultColor() : categoryColor; - holder.groupIcon.setImageDrawable(UiUtilities.tintDrawable( - AppCompatResources.getDrawable(app, R.drawable.ic_action_folder), color)); holder.pointsCounter.setText(String.valueOf(getCategoryPointsCount(group))); int strokeColor; int strokeWidth; @@ -913,6 +919,20 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), strokeColor); holder.groupButton.setImageDrawable(rectContourDrawable); } + int color; + int iconID; + if (!isCategoryVisible(group)) { + color = ContextCompat.getColor(app, R.color.text_color_secondary_light); + iconID = R.drawable.ic_action_hide; + holder.groupName.setTypeface(null, Typeface.ITALIC); + } else { + int categoryColor = getCategoryColor(group); + color = categoryColor == 0 ? getDefaultColor() : categoryColor; + iconID = R.drawable.ic_action_folder; + holder.groupName.setTypeface(null, Typeface.NORMAL); + } + holder.groupIcon.setImageDrawable(UiUtilities.tintDrawable( + AppCompatResources.getDrawable(app, iconID), color)); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AndroidUtils.setBackground(app, holder.groupButton, nightMode, R.drawable.ripple_solid_light_6dp, diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java index e74539a06a..94ecff5478 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java @@ -8,6 +8,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.view.View; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; @@ -454,6 +455,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { } @Override + @ColorInt public int getCategoryColor(String category) { if (categoriesMap != null) { Integer color = categoriesMap.get(category);