From 889ac143d35c59d9255824e1df3e8118eea54769 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 17 Mar 2020 14:49:20 +0200 Subject: [PATCH] Fix background type. --- .../res/drawable/bg_point_circle_contour.xml | 7 ++ .../res/drawable/bg_point_rhomb_contour.xml | 10 +++ .../res/drawable/bg_point_square_contour.xml | 10 +++ .../src/net/osmand/data/FavouritePoint.java | 2 +- .../net/osmand/plus/FavouritesDbHelper.java | 8 +- .../FavoritePointEditorFragmentNew.java | 59 +++++++++++--- .../editors/PointEditorFragmentNew.java | 77 ++++++++----------- 7 files changed, 117 insertions(+), 56 deletions(-) create mode 100644 OsmAnd/res/drawable/bg_point_circle_contour.xml create mode 100644 OsmAnd/res/drawable/bg_point_rhomb_contour.xml create mode 100644 OsmAnd/res/drawable/bg_point_square_contour.xml diff --git a/OsmAnd/res/drawable/bg_point_circle_contour.xml b/OsmAnd/res/drawable/bg_point_circle_contour.xml new file mode 100644 index 0000000000..46d0f51ec8 --- /dev/null +++ b/OsmAnd/res/drawable/bg_point_circle_contour.xml @@ -0,0 +1,7 @@ + + + + diff --git a/OsmAnd/res/drawable/bg_point_rhomb_contour.xml b/OsmAnd/res/drawable/bg_point_rhomb_contour.xml new file mode 100644 index 0000000000..8e1affcaf8 --- /dev/null +++ b/OsmAnd/res/drawable/bg_point_rhomb_contour.xml @@ -0,0 +1,10 @@ + + + diff --git a/OsmAnd/res/drawable/bg_point_square_contour.xml b/OsmAnd/res/drawable/bg_point_square_contour.xml new file mode 100644 index 0000000000..1f492681f1 --- /dev/null +++ b/OsmAnd/res/drawable/bg_point_square_contour.xml @@ -0,0 +1,10 @@ + + + diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index e23d8868c0..66f1635776 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -206,7 +206,7 @@ public class FavouritePoint implements Serializable, LocationPoint { return backgroundType; } - private void setBackgroundType(BackgroundType backgroundType) { + public void setBackgroundType(BackgroundType backgroundType) { this.backgroundType = backgroundType; } diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 5e050a601f..a61083d7d2 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -302,7 +302,9 @@ public class FavouritesDbHelper { if (FavouritePoint.SpecialPointType.PARKING.equals(p.getSpecialPointType())) { p.setColor(ContextCompat.getColor(context, R.color.map_widget_blue)); } else { - p.setColor(group.color); + if (p.getColor() == 0) { + p.setColor(group.color); + } } group.points.add(p); cachedFavoritePoints.add(p); @@ -440,7 +442,9 @@ public class FavouritesDbHelper { if (FavouritePoint.SpecialPointType.PARKING.equals(p.getSpecialPointType())) { p.setColor(ContextCompat.getColor(context, R.color.map_widget_blue)); } else { - p.setColor(pg.color); + if (p.getColor() == 0) { + p.setColor(pg.color); + } } pg.points.add(p); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java index 630495d51a..20babe18cd 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java @@ -10,6 +10,8 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import androidx.annotation.ColorInt; +import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; @@ -38,8 +40,10 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { private FavouritePoint favorite; @Nullable private FavoriteGroup group; - private int color; + private int iconId; + @NonNull + private FavouritePoint.BackgroundType backgroundType = FavouritePoint.BackgroundType.CIRCLE; @Nullable FavouritesDbHelper helper; @@ -71,6 +75,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { this.favorite = favorite; this.group = helper.getGroup(favorite); this.color = favorite.getColor(); + this.backgroundType = favorite.getBackgroundType(); + this.iconId = favorite.getIconId(); } } @@ -176,7 +182,16 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { @Override public void setColor(int color) { this.color = color; + } + @Override + public void setBackgroundType(@NonNull FavouritePoint.BackgroundType backgroundType) { + this.backgroundType = backgroundType; + } + + @Override + public void setIcon(int iconId) { + this.iconId = iconId; } @Override @@ -226,11 +241,12 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), getNameTextValue(), getCategoryTextValue()); point.setDescription(getDescriptionTextValue()); + point.setColor(color); + point.setBackgroundType(backgroundType); + point.setIconId(iconId); AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity()); - if (favorite.getName().equals(point.getName()) && - favorite.getCategory().equals(point.getCategory()) && - Algorithms.stringsEqual(favorite.getDescription(), point.getDescription())) { + if (isChanged(favorite, point)) { if (needDismiss) { dismiss(false); @@ -242,24 +258,39 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss); + doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), + point.getColor(), point.getBackgroundType(), point.getIconId(), needDismiss); } }); builder.create().show(); } else { - doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss); + doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), + point.getColor(), point.getBackgroundType(), point.getIconId(), needDismiss); } saved = true; } } - private void doSave(FavouritePoint favorite, String name, String category, String description, boolean needDismiss) { + private boolean isChanged(FavouritePoint favorite, FavouritePoint point) { + return favorite.getColor() == point.getColor() && + favorite.getIconId() == point.getIconId() && + favorite.getName().equals(point.getName()) && + favorite.getCategory().equals(point.getCategory()) && + favorite.getBackgroundType().equals(point.getBackgroundType()) && + Algorithms.stringsEqual(favorite.getDescription(), point.getDescription()); + } + + private void doSave(FavouritePoint favorite, String name, String category, String description, + @ColorInt int color, FavouritePoint.BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) { FavouritesDbHelper helper = getHelper(); FavoritePointEditor editor = getFavoritePointEditor(); if (editor != null && helper != null) { if (editor.isNew()) { - doAddFavorite(name, category, description); + doAddFavorite(name, category, description, color, backgroundType, iconId); } else { + favorite.setColor(color); + favorite.setBackgroundType(backgroundType); + favorite.setIconId(iconId); helper.editFavouriteName(favorite, name, category, description); } } @@ -279,7 +310,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { } } - private void doAddFavorite(String name, String category, String description) { + private void doAddFavorite(String name, String category, String description, @ColorInt int color, + FavouritePoint.BackgroundType backgroundType, @DrawableRes int iconId) { OsmandApplication app = getMyApplication(); FavouritesDbHelper helper = getHelper(); FavouritePoint favorite = getFavorite(); @@ -287,6 +319,9 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { favorite.setName(name); favorite.setCategory(category); favorite.setDescription(description); + favorite.setColor(color); + favorite.setBackgroundType(backgroundType); + favorite.setIconId(iconId); app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(category); helper.addFavourite(favorite); } @@ -374,6 +409,12 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { return color; } + @Override + @NonNull + public FavouritePoint.BackgroundType getBackgroundType() { + return backgroundType; + } + private int getColor() { return color; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java index 04cc362f7b..265562b305 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -68,7 +68,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { private Button addDelDescription; private boolean cancelled; private boolean nightMode; - private String selectedIcon; + private int selectedIcon; @ColorInt private int selectedColor; private FavouritePoint.BackgroundType selectedShape = FavouritePoint.BackgroundType.CIRCLE; @@ -91,6 +91,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { editor.updateNightMode(); selectedColor = 0xb4FFFFFF & getPointColor(); + selectedShape = getBackgroundType(); + selectedIcon = R.drawable.mx_special_star; Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); toolbar.setTitle(getToolbarTitle()); @@ -115,10 +117,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { replaceIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_replace, activeColorResId)); ImageView deleteIcon = (ImageView) view.findViewById(R.id.delete_action_icon); deleteIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId)); - -// ((TextView)view.findViewById(R.id.replace_action_title)).setTextColor(ContextCompat.getColor(app,activeColorResId)); -// ((TextView)view.findViewById(R.id.replace_action_description)).setTextColor(ContextCompat.getColor(app,activeColorResId)); -// ((TextView)view.findViewById(R.id.delete_action_title)).setTextColor(ContextCompat.getColor(app,activeColorResId)); View groupList = view.findViewById(R.id.group_list_button); groupList.setOnClickListener(new View.OnClickListener() { @Override @@ -239,16 +237,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { private void createGroupSelector(OsmandApplication app) { GroupAdapter groupListAdapter = new GroupAdapter(app); - groupListAdapter.setItemClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { -// int position = groupListAdapter.getChildAdapterPosition(v); -// if (position == RecyclerView.NO_POSITION) { -// return; -// } -// selectFavorite(favouritePoints.get(position)); - } - }); groupListAdapter.setSelectedItemName(getCategoryInitValue()); RecyclerView groupRecyclerView = view.findViewById(R.id.group_recycler_view); groupRecyclerView.setAdapter(groupListAdapter); @@ -256,6 +244,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { groupListAdapter.notifyDataSetChanged(); } + private void selectIconGroup() { + } + private void createColorSelector() { FlowLayout selectColor = view.findViewById(R.id.select_color); for (int color : ColorDialogs.pallette) { @@ -289,19 +280,13 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { icon.setImageDrawable(UiUtilities.tintDrawable(icon.getDrawable(), R.color.icon_color_default_light)); } rootView.findViewWithTag(color).findViewById(R.id.outline).setVisibility(View.VISIBLE); - View icon = rootView.findViewWithTag(selectedIcon); - if (icon != null) { - ImageView iconImage = icon.findViewById(R.id.icon); - iconImage.setImageDrawable(UiUtilities.tintDrawable(iconImage.getDrawable(), R.color.white_50_transparent)); - ImageView backgroundCircle = view.findViewById(R.id.background); - AndroidUtils.setBackground(backgroundCircle, - UiUtilities.tintDrawable(ContextCompat.getDrawable(view.getContext(), selectedShape.getIconId()), color)); - } + ((TextView) view.findViewById(R.id.color_name)).setText(ColorDialogs.getColorName(color)); selectedColor = color; setColor(color); updateNameIcon(); - updateShapeSelector(); + updateShapeSelector(selectedShape, view); + updateIconSelector(selectedIcon, view); } private void createShapeSelector() { @@ -339,10 +324,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { return app.getUIUtilities().getIcon(iconRes, R.color.divider_color_light); } - private void updateShapeSelector() { - updateShapeSelector(selectedShape, view); - } - private void updateShapeSelector(FavouritePoint.BackgroundType backgroundType, View rootView) { View oldShape = rootView.findViewWithTag(selectedShape); if (oldShape != null) { @@ -360,6 +341,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { UiUtilities.tintDrawable(ContextCompat.getDrawable(requireMyApplication(), backgroundType.getIconId()), selectedColor)); selectedShape = backgroundType; + setBackgroundType(backgroundType); } private void createIconSelector() { @@ -375,7 +357,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { } catch (JSONException e) { e.printStackTrace(); } - String selectedIconCategory = group.keySet().iterator().next(); FlowLayout selectIcon = view.findViewById(R.id.select_icon); JSONArray iconJsonArray = group.get(selectedIconCategory); @@ -388,14 +369,12 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { e.printStackTrace(); } } - GroupNameAdapter groupNameListAdapter = new GroupNameAdapter(); groupNameListAdapter.setItems(new ArrayList<>(group.keySet())); RecyclerView groupNameRecyclerView = view.findViewById(R.id.group_name_recycler_view); groupNameRecyclerView.setAdapter(groupNameListAdapter); groupNameRecyclerView.setLayoutManager(new LinearLayoutManager(requireMyApplication(), RecyclerView.HORIZONTAL, false)); groupNameListAdapter.notifyDataSetChanged(); - for (String name : iconNameList) { selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0)); } @@ -420,24 +399,32 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { updateIconSelector(iconRes, rootView); } }); - iconItemView.setTag(String.valueOf(iconRes)); + iconItemView.setTag(iconRes); return iconItemView; } - private void updateIconSelector(int iconRes, ViewGroup rootView) { -// setIconNewColor(iconRes); + private void updateIconSelector(int iconRes, View rootView) { View oldIcon = rootView.findViewWithTag(selectedIcon); if (oldIcon != null) { oldIcon.findViewById(R.id.outline).setVisibility(View.INVISIBLE); + ImageView background = oldIcon.findViewById(R.id.background); + AndroidUtils.setBackground(background, + UiUtilities.tintDrawable(ContextCompat.getDrawable(requireMyApplication(), R.drawable.bg_point_circle), + ContextCompat.getColor(requireMyApplication(), R.color.divider_color_light))); } - rootView.findViewWithTag(String.valueOf(iconRes)).findViewById(R.id.outline).setVisibility(View.VISIBLE); -// checkMark.setImageDrawable(app.getUIUtilities().getIcon(changedProfile.iconRes, R.color.icon_color_default_light)); -// AndroidUtils.setBackground(oldIcon.findViewById(R.id.backgroundCircle), -// UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), -// UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f))); - selectedIcon = String.valueOf(iconRes); + View icon = rootView.findViewWithTag(iconRes); + if (icon != null) { + ImageView iconImage = icon.findViewById(R.id.icon); + icon.findViewById(R.id.outline).setVisibility(View.VISIBLE); + iconImage.setImageDrawable(UiUtilities.tintDrawable(iconImage.getDrawable(), R.color.white_50_transparent)); + ImageView backgroundCircle = icon.findViewById(R.id.background); + AndroidUtils.setBackground(backgroundCircle, + UiUtilities.tintDrawable(ContextCompat.getDrawable(view.getContext(), R.drawable.bg_point_circle), selectedColor)); + } + selectedIcon = iconRes; updateNameIcon(); + setIcon(iconRes); } private void updateNameIcon() { @@ -586,6 +573,10 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { public abstract void setColor(int color); + public abstract void setBackgroundType(FavouritePoint.BackgroundType backgroundType); + + public abstract void setIcon(int iconId); + protected String getDefaultCategoryName() { return getString(R.string.shared_string_none); } @@ -636,6 +627,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { public abstract int getPointColor(); + public abstract FavouritePoint.BackgroundType getBackgroundType(); + public abstract Set getCategories(); String getNameTextValue() { @@ -759,10 +752,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { return items == null ? 0 : items.size() + 1; } - void setItemClickListener(View.OnClickListener listener) { - this.listener = listener; - } - String getSelectedItem() { return selectedItemName; }