From d9437f89dff4ff663fd2cfbd3b154efda954b1e3 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Tue, 13 Apr 2021 14:13:50 +0300 Subject: [PATCH] For redo --- .../plus/mapcontextmenu/MenuBuilder.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 1cf77252e2..f3776b8afa 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -101,7 +101,10 @@ public class MenuBuilder { protected static final String[] arrowChars = new String[]{"=>", " - "}; protected final String NEAREST_WIKI_KEY = "nearest_wiki_key"; protected final String NEAREST_POI_KEY = "nearest_poi_key"; - private static final int LIMIT = 10000; + private static final int POI_COUNT = 10; + private static final int MINIMUM_RADIUS = 100; + private static final int MAXIMUM_RADIUS = 1000; + private static final int FACTOR = 2; protected MapActivity mapActivity; protected MapContextMenu mapContextMenu; @@ -1244,17 +1247,14 @@ public class MenuBuilder { } PoiUIFilter filter = getPoiFilterForType(nearestPoiType); - boolean isPoiFilter = nearestPoiType.equals(NEAREST_POI_KEY); - if (filter != null && nearestPoi.size() > 0) { - view.addView(createShowAllButton(context, filter)); - } - if (isPoiFilter && nearestPoi.size() == 0) { - view.addView(createSearchMoreButton(context, filter)); + if (filter != null && nearestAmenities.size() == POI_COUNT) { + view.addView(createShowOnMap(context, filter)); } + view.addView(createSearchMoreButton(context, filter)); return new CollapsableView(view, this, collapsed); } - private View createShowAllButton(Context context, final PoiUIFilter filter) { + private View createShowOnMap(Context context, final PoiUIFilter filter) { TextViewEx buttonShowAll = buildButtonInCollapsableView(context, false, false); buttonShowAll.setText(app.getString(R.string.shared_string_show_on_map)); buttonShowAll.setOnClickListener(new View.OnClickListener() { @@ -1400,18 +1400,15 @@ public class MenuBuilder { } private List getSortedAmenities(PoiUIFilter filter, final LatLon latLon) { - int radius = 250; - QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), radius); + QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), MINIMUM_RADIUS); List nearestAmenities = getAmenities(rect, filter); - nearestAmenities.remove(amenity); - boolean isWikiFilter = filter.getFilterId().equals("std_osmwiki"); - - for (; nearestAmenities.size() < 10 && !isWikiFilter; radius += 10) { + for (int radius = MINIMUM_RADIUS; nearestAmenities.size() - 1 <= POI_COUNT && radius <= MAXIMUM_RADIUS; radius *= FACTOR) { rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), radius); nearestAmenities = getAmenities(rect, filter); } + nearestAmenities.remove(amenity); Collections.sort(nearestAmenities, new Comparator() { @@ -1423,7 +1420,7 @@ public class MenuBuilder { } }); - return nearestAmenities; + return nearestAmenities.subList(0, Math.min(POI_COUNT, nearestAmenities.size())); } private List getAmenities(QuadRect rect, PoiUIFilter filter) {