From b3aa0d262a9b40144f9edcd5b99c7fab41b3b63b Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 11 Dec 2017 18:32:47 +0200 Subject: [PATCH] Add displaying favourites from group --- ...ntext_menu_controller_bg_dark_selected.xml | 13 ++++ ...text_menu_controller_bg_light_selected.xml | 13 ++++ .../plus/mapcontextmenu/MenuBuilder.java | 75 +++++++++++++------ .../builders/FavouritePointMenuBuilder.java | 19 ++++- 4 files changed, 97 insertions(+), 23 deletions(-) create mode 100644 OsmAnd/res/drawable/context_menu_controller_bg_dark_selected.xml create mode 100644 OsmAnd/res/drawable/context_menu_controller_bg_light_selected.xml diff --git a/OsmAnd/res/drawable/context_menu_controller_bg_dark_selected.xml b/OsmAnd/res/drawable/context_menu_controller_bg_dark_selected.xml new file mode 100644 index 0000000000..afdc69fa7d --- /dev/null +++ b/OsmAnd/res/drawable/context_menu_controller_bg_dark_selected.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/context_menu_controller_bg_light_selected.xml b/OsmAnd/res/drawable/context_menu_controller_bg_light_selected.xml new file mode 100644 index 0000000000..7525dfe68f --- /dev/null +++ b/OsmAnd/res/drawable/context_menu_controller_bg_light_selected.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index b1c9b017a4..cd919dae5e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -26,6 +26,7 @@ import android.widget.Toast; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.Amenity; +import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; @@ -681,6 +682,10 @@ public class MenuBuilder { } protected CollapsableView getCollapsableWikiView(Context context, boolean collapsed) { + return getCollapsableItemsView(context, collapsed, nearestWiki, null); + } + + protected CollapsableView getCollapsableItemsView(Context context, boolean collapsed, final List items, Object selectedObject) { final LinearLayout view = new LinearLayout(context); view.setOrientation(LinearLayout.VERTICAL); view.setVisibility(collapsed ? View.GONE : View.VISIBLE); @@ -698,31 +703,57 @@ public class MenuBuilder { context.getResources().getColor(light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n) } ); - for (final Amenity wiki : nearestWiki) { - TextViewEx wikiButton = new TextViewEx(new ContextThemeWrapper(view.getContext(), light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme)); + for (final Object item : items) { + TextViewEx button = new TextViewEx(new ContextThemeWrapper(view.getContext(), light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme)); LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) context.getResources().getDimension(R.dimen.context_menu_controller_height)); llWikiButtonParams.setMargins(0, 0, 0, dpToPx(8f)); - wikiButton.setLayoutParams(llWikiButtonParams); - wikiButton.setTypeface(FontCache.getRobotoMedium(context)); - wikiButton.setBackgroundResource(light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark); - int paddingSides = (int) context.getResources().getDimension(R.dimen.context_menu_button_padding_x); - wikiButton.setPadding(paddingSides, 0, paddingSides, 0); - wikiButton.setTextColor(buttonColorStateList); - wikiButton.setText(wiki.getName(preferredMapAppLang, transliterateNames)); + button.setLayoutParams(llWikiButtonParams); + button.setTypeface(FontCache.getRobotoMedium(context)); - wikiButton.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); - wikiButton.setSingleLine(true); - wikiButton.setEllipsize(TextUtils.TruncateAt.END); - wikiButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(wiki); - mapActivity.getContextMenu().show( - new LatLon(wiki.getLocation().getLatitude(), wiki.getLocation().getLongitude()), - pointDescription, wiki); - } - }); - view.addView(wikiButton); + boolean selected = selectedObject != null && selectedObject.equals(item); + int bg; + if (selected) { + bg = light ? R.drawable.context_menu_controller_bg_light_selected: R.drawable.context_menu_controller_bg_dark_selected; + } else { + bg = light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark; + } + button.setBackgroundResource(bg); + int paddingSides = (int) context.getResources().getDimension(R.dimen.context_menu_button_padding_x); + button.setPadding(paddingSides, 0, paddingSides, 0); + button.setTextColor(buttonColorStateList); + String name = ""; + if (item instanceof Amenity) { + name = ((Amenity) item).getName(preferredMapAppLang, transliterateNames); + } else if (item instanceof FavouritePoint) { + name = ((FavouritePoint) item).getName(); + } + button.setText(name); + + button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); + button.setSingleLine(true); + button.setEllipsize(TextUtils.TruncateAt.END); + if (!selected) { + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + LatLon latLon = null; + PointDescription pointDescription = null; + if (item instanceof Amenity) { + Amenity amenity = (Amenity) item; + latLon = new LatLon(amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude()); + pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(amenity); + } else if (item instanceof FavouritePoint) { + FavouritePoint fav = (FavouritePoint) item; + latLon = new LatLon(fav.getLatitude(), fav.getLongitude()); + pointDescription = new PointDescription(PointDescription.POINT_TYPE_FAVORITE, fav.getName()); + } + if (latLon != null && pointDescription != null) { + mapActivity.getContextMenu().show(latLon, pointDescription, item); + } + } + }); + } + view.addView(button); } return new CollapsableView(view, collapsed); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index e430ac5a0c..2dc9ba395e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapcontextmenu.builders; +import android.graphics.Color; import android.view.View; import net.osmand.ResultMatcher; @@ -9,10 +10,11 @@ import net.osmand.data.FavouritePoint; import net.osmand.data.QuadRect; import net.osmand.data.TransportStop; import net.osmand.osm.PoiCategory; +import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; -import net.osmand.plus.mapillary.MapillaryPlugin; +import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.util.List; @@ -60,6 +62,21 @@ public class FavouritePointMenuBuilder extends MenuBuilder { builder.setLight(light); builder.buildInternal(view); } + buildGroupFavsView(view); + } + + private void buildGroupFavsView(View view) { + FavoriteGroup favoriteGroup = app.getFavorites().getGroup(fav); + List groupFavs = favoriteGroup.points; + if (groupFavs.size() > 0) { + int color = favoriteGroup.color == 0 || favoriteGroup.color == Color.BLACK ? view.getResources().getColor(R.color.color_favorite) : favoriteGroup.color; + int disabledColor = light ? R.color.secondary_text_light : R.color.secondary_text_dark; + color = favoriteGroup.visible ? (color | 0xff000000) : view.getResources().getColor(disabledColor); + String name = Algorithms.isEmpty(favoriteGroup.name) ? view.getResources().getString(R.string.shared_string_favorites) : favoriteGroup.name; + buildRow(view, app.getIconsCache().getPaintedIcon(R.drawable.ic_action_folder, color), name, 0, + true, getCollapsableItemsView(view.getContext(), true, groupFavs, fav), + false, 0, false, null); + } } private Amenity findAmenity(String nameStringEn, double lat, double lon) {