From 1f8cb06786d5f6e084685b1b68e2f569dee646e2 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 19 May 2020 18:41:23 +0300 Subject: [PATCH] Fix elevation duplicates --- .../plus/mapcontextmenu/MenuBuilder.java | 57 +++---------------- .../builders/AmenityMenuBuilder.java | 13 ++--- 2 files changed, 13 insertions(+), 57 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 37aa0197e2..14829330bc 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -21,7 +21,6 @@ import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -44,7 +43,6 @@ import net.osmand.osm.PoiCategory; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -70,6 +68,7 @@ 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; @@ -281,7 +280,7 @@ public class MenuBuilder { } protected void buildNearestWikiRow(View view) { - if (processNearstWiki() && nearestWiki.size() > 0) { + 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); @@ -697,15 +696,15 @@ public class MenuBuilder { } - protected CollapsableView getDistanceCollapsableView(Map distanceData) { + protected CollapsableView getDistanceCollapsableView(Set distanceData) { LinearLayout llv = buildCollapsableContentView(mapActivity, true, true); - for (final Map.Entry line : distanceData.entrySet()) { + for (final String distance : distanceData) { TextView button = buildButtonInCollapsableView(mapActivity, false, false); - button.setText(line.getValue()); + button.setText(distance); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - copyToClipboard(line.getValue(), mapActivity); + copyToClipboard(distance, mapActivity); } }); llv.addView(button); @@ -713,48 +712,6 @@ public class MenuBuilder { return new CollapsableView(llv, this, true); } - protected void buildButtonRow(final View view, Drawable buttonIcon, String text, OnClickListener onClickListener) { - LinearLayout ll = new LinearLayout(view.getContext()); - ll.setOrientation(LinearLayout.HORIZONTAL); - LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - ll.setLayoutParams(llParams); - ll.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground)); - - // Empty - LinearLayout llIcon = new LinearLayout(view.getContext()); - llIcon.setOrientation(LinearLayout.HORIZONTAL); - llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(62f), dpToPx(58f))); - llIcon.setGravity(Gravity.CENTER_VERTICAL); - ll.addView(llIcon); - - - // Button - LinearLayout llButton = new LinearLayout(view.getContext()); - llButton.setOrientation(LinearLayout.VERTICAL); - ll.addView(llButton); - - Button buttonView = new Button(view.getContext()); - LinearLayout.LayoutParams llBtnParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - buttonView.setLayoutParams(llBtnParams); - AndroidUtils.setPadding(buttonView, dpToPx(10f), 0, dpToPx(10f), 0); - buttonView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); - //buttonView.setTextSize(view.getResources().getDimension(resolveAttribute(view.getContext(), R.dimen.default_desc_text_size))); - buttonView.setTextColor(view.getResources().getColor(AndroidUtils.resolveAttribute(view.getContext(), R.attr.contextMenuButtonColor))); - buttonView.setText(text); - - if (buttonIcon != null) { - buttonView.setCompoundDrawablesWithIntrinsicBounds(buttonIcon, null, null, null); - buttonView.setCompoundDrawablePadding(dpToPx(8f)); - } - llButton.addView(buttonView); - - ((LinearLayout) view).addView(ll); - - ll.setOnClickListener(onClickListener); - - rowBuilt(); - } - public void buildRowDivider(View view) { View horizontalLine = new View(view.getContext()); LinearLayout.LayoutParams llHorLineParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(1f)); @@ -1027,7 +984,7 @@ public class MenuBuilder { return button; } - protected boolean processNearstWiki() { + protected boolean processNearestWiki() { if (showNearestWiki && latLon != null) { QuadRect rect = MapUtils.calculateLatLonBbox( latLon.getLatitude(), latLon.getLongitude(), 250); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index eda5de7c16..aae282d18e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -28,16 +28,16 @@ import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.FontCache; -import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.CollapsableView; +import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.poi.PoiUIFilter; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants; import net.osmand.plus.views.POIMapLayer; import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.tools.ClickableSpanTouchListener; @@ -529,10 +529,9 @@ public class AmenityMenuBuilder extends MenuBuilder { if ("ele".equals(key)) { try { float distance = Float.parseFloat(vl); + vl = OsmAndFormatter.getFormattedDistance(distance, app, true, metricSystem); Map distanceData = OsmAndFormatter.getDistanceData(app, distance); - MetricsConstants currentFormat = app.getSettings().METRIC_SYSTEM.get(); - vl = OsmAndFormatter.getFormattedDistance(distance, app, true, currentFormat); - collapsableView = getDistanceCollapsableView(distanceData); + collapsableView = getDistanceCollapsableView(new LinkedHashSet<>(distanceData.values())); collapsable = true; } catch (NumberFormatException ex) { LOG.error(ex); @@ -654,7 +653,7 @@ public class AmenityMenuBuilder extends MenuBuilder { buildAmenityRow(view, info); } - if (processNearstWiki() && nearestWiki.size() > 0) { + 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),