From 29edac0125e9b92b5e54c0a3e1a11dddb4053735 Mon Sep 17 00:00:00 2001 From: Skalii Date: Tue, 5 Jan 2021 12:36:02 +0200 Subject: [PATCH 1/5] add option to copy address; --- OsmAnd/res/values/strings.xml | 1 + .../osmand/plus/mapcontextmenu/other/ShareMenu.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a78818557b..fb403c340c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,7 @@ --> + Copy address Allow intermittent water ways Allow intermittent water ways Allow streams and drains diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenu.java index 7323e52b5d..aba6ca8277 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenu.java @@ -36,6 +36,7 @@ public class ShareMenu extends BaseMenuController { public enum ShareItem { MESSAGE(R.drawable.ic_action_message, R.string.shared_string_send), CLIPBOARD(R.drawable.ic_action_copy, R.string.shared_string_copy), + ADDRESS(R.drawable.ic_action_copy, R.string.copy_address), NAME(R.drawable.ic_action_copy, R.string.copy_location_name), COORDINATES(R.drawable.ic_action_copy, R.string.copy_coordinates), GEO(R.drawable.ic_world_globe_dark, R.string.share_geo), @@ -66,6 +67,7 @@ public class ShareMenu extends BaseMenuController { List list = new LinkedList<>(); list.add(ShareItem.MESSAGE); list.add(ShareItem.CLIPBOARD); + list.add(ShareItem.ADDRESS); list.add(ShareItem.NAME); list.add(ShareItem.COORDINATES); list.add(ShareItem.GEO); @@ -121,6 +123,15 @@ public class ShareMenu extends BaseMenuController { case CLIPBOARD: ShareDialog.sendToClipboard(mapActivity, sms); break; + case ADDRESS: + if (!Algorithms.isEmpty(address)) { + ShareDialog.sendToClipboard(mapActivity, address); + } else { + Toast.makeText(mapActivity, + R.string.no_address_found, + Toast.LENGTH_LONG).show(); + } + break; case NAME: if (!Algorithms.isEmpty(title)) { ShareDialog.sendToClipboard(mapActivity, title); From de2704a62709e006746079a3f786ae48b8feb046 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 6 Jan 2021 04:36:21 +0200 Subject: [PATCH 2/5] add to context menu option to show nearby poi with the same type; --- OsmAnd/res/values/strings.xml | 1 + .../plus/mapcontextmenu/MenuBuilder.java | 108 ++++++++++++++---- .../builders/AmenityMenuBuilder.java | 16 ++- .../builders/FavouritePointMenuBuilder.java | 4 +- .../controllers/AmenityMenuController.java | 2 +- 5 files changed, 102 insertions(+), 29 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index fb403c340c..1e8391a3d8 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,7 @@ --> + Nearby POI Copy address Allow intermittent water ways Allow intermittent water ways diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 1d419a6b09..d4f60024f6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -41,6 +41,8 @@ import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.*; import net.osmand.plus.activities.ActivityResultListener; @@ -51,6 +53,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask; import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard; +import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; import net.osmand.plus.openplacereviews.AddPhotosBottomSheetDialogFragment; import net.osmand.plus.openplacereviews.OPRConstants; @@ -92,12 +95,15 @@ public class MenuBuilder { protected boolean matchWidthDivider; protected boolean light; private long objectId; + private String objectType; private LatLon latLon; private boolean hidden; private boolean showTitleIfTruncated = true; private boolean showNearestWiki = false; + private boolean showNearestPoi = false; private boolean showOnlinePhotos = true; protected List nearestWiki = new ArrayList<>(); + protected List nearestPoi = new ArrayList<>(); private List menuPlugins = new ArrayList<>(); @Nullable private CardsRowBuilder onlinePhotoCardsRow; @@ -208,10 +214,18 @@ public class MenuBuilder { return showNearestWiki; } + public boolean isShowNearestPoi() { + return showNearestPoi; + } + public void setShowNearestWiki(boolean showNearestWiki) { this.showNearestWiki = showNearestWiki; } + public void setShowNearestPoi(boolean showNearestPoi) { + this.showNearestPoi = showNearestPoi; + } + public void setShowTitleIfTruncated(boolean showTitleIfTruncated) { this.showTitleIfTruncated = showTitleIfTruncated; } @@ -229,6 +243,11 @@ public class MenuBuilder { this.showNearestWiki = showNearestWiki; } + public void setShowNearestPoi(boolean showNearestPoi, String objectType) { + this.objectType = objectType; + this.showNearestPoi = showNearestPoi; + } + public void addMenuPlugin(OsmandPlugin plugin) { menuPlugins.add(plugin); } @@ -246,6 +265,7 @@ public class MenuBuilder { buildTitleRow(view); } buildNearestWikiRow(view); + buildNearestPoiRow(view); if (needBuildPlainMenuItems()) { buildPlainMenuItems(view); } @@ -325,10 +345,20 @@ public class MenuBuilder { } protected void buildNearestWikiRow(View view) { - if (processNearestWiki() && nearestWiki.size() > 0) { - buildRow(view, R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", 0, - true, getCollapsableWikiView(view.getContext(), true), - false, 0, false, null, false); + buildNearestRow(view, nearestWiki, processNearestWiki(), + R.drawable.ic_action_wikipedia, app.getString(R.string.wiki_around)); + } + + protected void buildNearestPoiRow(View view) { + buildNearestRow(view, nearestPoi, processNearestPoi(), + nearestPoi.isEmpty() ? 0 : AmenityMenuController.getRightIconId(nearestPoi.get(0)), + app.getString(R.string.poi_around)); + } + + protected void buildNearestRow(View view, List nearestAmenities, boolean process, int iconId, String text) { + if (process && nearestAmenities.size() > 0) { + buildRow(view, iconId, null, text + " (" + nearestAmenities.size() + ")", 0, true, + getCollapsableView(view.getContext(), true, nearestAmenities), false, 0, false, null, false); } } @@ -1118,20 +1148,25 @@ public class MenuBuilder { return new CollapsableView(textView, this, collapsed); } - protected CollapsableView getCollapsableWikiView(Context context, boolean collapsed) { + protected CollapsableView getCollapsableView(Context context, boolean collapsed, List nearestAmenities) { LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true); - for (final Amenity wiki : nearestWiki) { + for (final Amenity poi : nearestAmenities) { TextViewEx button = buildButtonInCollapsableView(context, false, false); - String name = wiki.getName(preferredMapAppLang, transliterateNames); + String name = poi.getName(preferredMapAppLang, transliterateNames); + if (Algorithms.isBlank(name)) { + PoiCategory pc = poi.getType(); + PoiType pt = pc.getPoiTypeByKeyName(poi.getSubType()); + name = pt.getTranslation(); + } button.setText(name); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - LatLon latLon = new LatLon(wiki.getLocation().getLatitude(), wiki.getLocation().getLongitude()); - PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(wiki); - mapActivity.getContextMenu().show(latLon, pointDescription, wiki); + LatLon latLon = new LatLon(poi.getLocation().getLatitude(), poi.getLocation().getLongitude()); + PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi); + mapActivity.getContextMenu().show(latLon, pointDescription, poi); } }); view.addView(button); @@ -1192,21 +1227,7 @@ public class MenuBuilder { protected boolean processNearestWiki() { if (showNearestWiki && latLon != null) { - QuadRect rect = MapUtils.calculateLatLonBbox( - latLon.getLatitude(), latLon.getLongitude(), 250); - PoiUIFilter wikiPoiFilter = app.getPoiFilters().getTopWikiPoiFilter(); - - nearestWiki = getAmenities(rect, wikiPoiFilter); - - Collections.sort(nearestWiki, new Comparator() { - - @Override - public int compare(Amenity o1, Amenity o2) { - double d1 = MapUtils.getDistance(latLon, o1.getLocation()); - double d2 = MapUtils.getDistance(latLon, o2.getLocation()); - return Double.compare(d1, d2); - } - }); + nearestWiki = getSortedAmenities(app.getPoiFilters().getTopWikiPoiFilter()); Long id = objectId; List wikiList = new ArrayList<>(); for (Amenity wiki : nearestWiki) { @@ -1220,6 +1241,43 @@ public class MenuBuilder { return false; } + protected boolean processNearestPoi() { + if (showNearestPoi && latLon != null) { + nearestPoi = getSortedAmenities(app.getPoiFilters().getShowAllPOIFilter()); + Long id = objectId; + String type = objectType; + List poiList = new ArrayList<>(); + for (Amenity poi : nearestPoi) { + if (poi.getId().equals(id) || !Algorithms.stringsEqual(poi.getSubType(), type)) { + poiList.add(poi); + } + } + nearestPoi.removeAll(poiList); + return true; + } + return false; + } + + private List getSortedAmenities(PoiUIFilter filter) { + final LatLon latLon = getLatLon(); + QuadRect rect = MapUtils.calculateLatLonBbox( + latLon.getLatitude(), latLon.getLongitude(), 250); + + List nearestAmenities = getAmenities(rect, filter); + + Collections.sort(nearestAmenities, new Comparator() { + + @Override + public int compare(Amenity o1, Amenity o2) { + double d1 = MapUtils.getDistance(latLon, o1.getLocation()); + double d2 = MapUtils.getDistance(latLon, o2.getLocation()); + return Double.compare(d1, d2); + } + }); + + return nearestAmenities; + } + private List getAmenities(QuadRect rect, PoiUIFilter wikiPoiFilter) { return wikiPoiFilter.searchAmenities(rect.top, rect.left, rect.bottom, rect.right, -1, null); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 12b1b0d497..b72c1a60f5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -35,6 +35,7 @@ import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.mapcontextmenu.CollapsableView; import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.views.layers.POIMapLayer; @@ -79,6 +80,7 @@ public class AmenityMenuBuilder extends MenuBuilder { super(mapActivity); this.amenity = amenity; setShowNearestWiki(true, amenity.getId()); + setShowNearestPoi(true, amenity.getSubType()); metricSystem = mapActivity.getMyApplication().getSettings().METRIC_SYSTEM.get(); } @@ -86,6 +88,10 @@ public class AmenityMenuBuilder extends MenuBuilder { protected void buildNearestWikiRow(View view) { } + @Override + protected void buildNearestPoiRow(View view) { + } + private void buildRow(View view, int iconId, String text, String textPrefix, boolean collapsable, final CollapsableView collapsableView, int textColor, boolean isWiki, boolean isText, boolean needLinks, @@ -664,11 +670,19 @@ public class AmenityMenuBuilder extends MenuBuilder { if (processNearestWiki() && nearestWiki.size() > 0) { AmenityInfoRow wikiInfo = new AmenityInfoRow( "nearest_wiki", R.drawable.ic_plugin_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", true, - getCollapsableWikiView(view.getContext(), true), + getCollapsableView(view.getContext(), true, nearestWiki), 0, false, false, false, 1000, null, false, false, false, 0); buildAmenityRow(view, wikiInfo); } + if (processNearestPoi() && nearestPoi.size() > 0) { + AmenityInfoRow poiInfo = new AmenityInfoRow( + "nearest_poi", AmenityMenuController.getRightIconId(amenity), null, app.getString(R.string.poi_around) + " (" + nearestPoi.size() + ")", true, + getCollapsableView(view.getContext(), true, nearestPoi), + 0, false, false, false, 1000, null, false, false, false, 0); + buildAmenityRow(view, poiInfo); + } + if (osmEditingEnabled && amenity.getId() != null && amenity.getId() > 0 && (amenity.getId() % 2 == 0 || (amenity.getId() >> 1) < Integer.MAX_VALUE)) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 1e6df280a3..03110c8b32 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -59,9 +59,9 @@ public class FavouritePointMenuBuilder extends MenuBuilder { } @Override - protected void buildNearestWikiRow(View view) { + protected void buildNearestRow(View view, List nearestAmenities, boolean process, int iconId, String text) { if (originObject == null || !(originObject instanceof Amenity)) { - super.buildNearestWikiRow(view); + super.buildNearestRow(view, nearestAmenities, process, iconId, text); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 11564a1b73..e67b8dc11b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -116,7 +116,7 @@ public class AmenityMenuController extends MenuController { return getRightIconId(amenity); } - private static int getRightIconId(Amenity amenity) { + public static int getRightIconId(Amenity amenity) { String id = null; PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); if (st != null) { From 599544e7ba31faf7db06a717e4eb060668b6ca41 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 6 Jan 2021 12:00:17 +0200 Subject: [PATCH 3/5] recovering deleted string value after merge --- OsmAnd/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 492d9d1428..df56f768f2 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -4027,6 +4027,6 @@ Prefer routes of this difficulty, although routing over harder or easier pistes is still possible if shorter. Off-piste \'Freeride\' and \'Off-piste\' are unofficial routes and passages. Typically ungroomed, unmaintained and not checked in the evening. Enter at your own risk. - + Voice prompts times From 190d33681d87d8f4041df970d455d0bfb0f95e57 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 6 Jan 2021 18:12:18 +0200 Subject: [PATCH 4/5] add amenity field to MenuBuilder; remove excess R.string.poi_around; code reduction; --- OsmAnd/res/values/strings.xml | 1 - .../plus/mapcontextmenu/MenuBuilder.java | 41 ++++--------------- .../builders/AmenityMenuBuilder.java | 7 ++-- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index df56f768f2..4991659469 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,7 +12,6 @@ --> - Nearby POI Copy address Error, recheck parameters Car diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index d4f60024f6..227411a5dc 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -94,8 +94,7 @@ public class MenuBuilder { private boolean firstRow; protected boolean matchWidthDivider; protected boolean light; - private long objectId; - private String objectType; + private Amenity amenity; private LatLon latLon; private boolean hidden; private boolean showTitleIfTruncated = true; @@ -238,14 +237,8 @@ public class MenuBuilder { this.showOnlinePhotos = showOnlinePhotos; } - public void setShowNearestWiki(boolean showNearestWiki, long objectId) { - this.objectId = objectId; - this.showNearestWiki = showNearestWiki; - } - - public void setShowNearestPoi(boolean showNearestPoi, String objectType) { - this.objectType = objectType; - this.showNearestPoi = showNearestPoi; + public void setAmenity(Amenity amenity) { + this.amenity = amenity; } public void addMenuPlugin(OsmandPlugin plugin) { @@ -352,7 +345,7 @@ public class MenuBuilder { protected void buildNearestPoiRow(View view) { buildNearestRow(view, nearestPoi, processNearestPoi(), nearestPoi.isEmpty() ? 0 : AmenityMenuController.getRightIconId(nearestPoi.get(0)), - app.getString(R.string.poi_around)); + app.getString(R.string.speak_poi)); } protected void buildNearestRow(View view, List nearestAmenities, boolean process, int iconId, String text) { @@ -1155,9 +1148,7 @@ public class MenuBuilder { TextViewEx button = buildButtonInCollapsableView(context, false, false); String name = poi.getName(preferredMapAppLang, transliterateNames); if (Algorithms.isBlank(name)) { - PoiCategory pc = poi.getType(); - PoiType pt = pc.getPoiTypeByKeyName(poi.getSubType()); - name = pt.getTranslation(); + name = AmenityMenuController.getTypeStr(poi); } button.setText(name); @@ -1228,14 +1219,6 @@ public class MenuBuilder { protected boolean processNearestWiki() { if (showNearestWiki && latLon != null) { nearestWiki = getSortedAmenities(app.getPoiFilters().getTopWikiPoiFilter()); - Long id = objectId; - List wikiList = new ArrayList<>(); - for (Amenity wiki : nearestWiki) { - if (wiki.getId().equals(id)) { - wikiList.add(wiki); - } - } - nearestWiki.removeAll(wikiList); return true; } return false; @@ -1243,16 +1226,9 @@ public class MenuBuilder { protected boolean processNearestPoi() { if (showNearestPoi && latLon != null) { - nearestPoi = getSortedAmenities(app.getPoiFilters().getShowAllPOIFilter()); - Long id = objectId; - String type = objectType; - List poiList = new ArrayList<>(); - for (Amenity poi : nearestPoi) { - if (poi.getId().equals(id) || !Algorithms.stringsEqual(poi.getSubType(), type)) { - poiList.add(poi); - } - } - nearestPoi.removeAll(poiList); + PoiCategory pc = amenity.getType(); + PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); + nearestPoi = getSortedAmenities(app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + pt.getKeyName())); return true; } return false; @@ -1264,6 +1240,7 @@ public class MenuBuilder { latLon.getLatitude(), latLon.getLongitude(), 250); List nearestAmenities = getAmenities(rect, filter); + nearestAmenities.remove(amenity); Collections.sort(nearestAmenities, new Comparator() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index b72c1a60f5..4a31a750e6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -79,8 +79,9 @@ public class AmenityMenuBuilder extends MenuBuilder { public AmenityMenuBuilder(@NonNull MapActivity mapActivity, final @NonNull Amenity amenity) { super(mapActivity); this.amenity = amenity; - setShowNearestWiki(true, amenity.getId()); - setShowNearestPoi(true, amenity.getSubType()); + setAmenity(amenity); + setShowNearestWiki(true); + setShowNearestPoi(true); metricSystem = mapActivity.getMyApplication().getSettings().METRIC_SYSTEM.get(); } @@ -677,7 +678,7 @@ public class AmenityMenuBuilder extends MenuBuilder { if (processNearestPoi() && nearestPoi.size() > 0) { AmenityInfoRow poiInfo = new AmenityInfoRow( - "nearest_poi", AmenityMenuController.getRightIconId(amenity), null, app.getString(R.string.poi_around) + " (" + nearestPoi.size() + ")", true, + "nearest_poi", AmenityMenuController.getRightIconId(amenity), null, app.getString(R.string.speak_poi) + " (" + nearestPoi.size() + ")", true, getCollapsableView(view.getContext(), true, nearestPoi), 0, false, false, false, 1000, null, false, false, false, 0); buildAmenityRow(view, poiInfo); From 7a59047a5df0d23241e4777db0ac5538a6a60c16 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 6 Jan 2021 19:42:13 +0200 Subject: [PATCH 5/5] Fix nearest wiki --- .../plus/mapcontextmenu/MenuBuilder.java | 46 +++++++++++++------ .../builders/AmenityMenuBuilder.java | 2 +- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 227411a5dc..d11d27d34c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -29,12 +29,14 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.view.ContextThemeWrapper; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; + import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.data.Amenity; @@ -44,7 +46,12 @@ import net.osmand.data.QuadRect; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiType; import net.osmand.osm.io.NetworkUtils; -import net.osmand.plus.*; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.Version; import net.osmand.plus.activities.ActivityResultListener; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.FontCache; @@ -68,6 +75,7 @@ import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.tools.ClickableSpanTouchListener; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; + import org.apache.commons.logging.Log; import org.openplacereviews.opendb.util.exception.FailedVerificationException; @@ -75,7 +83,13 @@ import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener; @@ -214,8 +228,8 @@ public class MenuBuilder { } public boolean isShowNearestPoi() { - return showNearestPoi; - } + return showNearestPoi; + } public void setShowNearestWiki(boolean showNearestWiki) { this.showNearestWiki = showNearestWiki; @@ -1217,27 +1231,31 @@ public class MenuBuilder { } protected boolean processNearestWiki() { - if (showNearestWiki && latLon != null) { - nearestWiki = getSortedAmenities(app.getPoiFilters().getTopWikiPoiFilter()); - return true; + if (showNearestWiki && latLon != null && amenity != null) { + PoiUIFilter filter = app.getPoiFilters().getTopWikiPoiFilter(); + if (filter != null) { + nearestWiki = getSortedAmenities(filter, latLon); + return true; + } } return false; } protected boolean processNearestPoi() { - if (showNearestPoi && latLon != null) { + if (showNearestPoi && latLon != null && amenity != null) { PoiCategory pc = amenity.getType(); PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); - nearestPoi = getSortedAmenities(app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + pt.getKeyName())); - return true; + PoiUIFilter filter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + pt.getKeyName()); + if (filter != null) { + nearestPoi = getSortedAmenities(filter, latLon); + return true; + } } return false; } - private List getSortedAmenities(PoiUIFilter filter) { - final LatLon latLon = getLatLon(); - QuadRect rect = MapUtils.calculateLatLonBbox( - latLon.getLatitude(), latLon.getLongitude(), 250); + private List getSortedAmenities(PoiUIFilter filter, final LatLon latLon) { + QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 250); List nearestAmenities = getAmenities(rect, filter); nearestAmenities.remove(amenity); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 4a31a750e6..c0db653e3e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -81,7 +81,7 @@ public class AmenityMenuBuilder extends MenuBuilder { this.amenity = amenity; setAmenity(amenity); setShowNearestWiki(true); - setShowNearestPoi(true); + setShowNearestPoi(!amenity.getType().isWiki()); metricSystem = mapActivity.getMyApplication().getSettings().METRIC_SYSTEM.get(); }