From 0d3f0711fdec43bcb7370419610f19928f9da5e6 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Wed, 8 Apr 2020 13:50:21 +0300 Subject: [PATCH] Wikipedia Poi (Fixes 2) --- .../osmand/plus/dialogs/ConfigureMapMenu.java | 12 +++++++- .../plus/wikipedia/WikipediaPoiMenu.java | 28 +++++++++++++------ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index d036379d6d..6552a37ac1 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -27,6 +27,7 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; import net.osmand.AndroidUtils; +import net.osmand.CallbackWithObject; import net.osmand.GPXUtilities; import net.osmand.PlatformUtil; import net.osmand.core.android.MapRendererContext; @@ -245,7 +246,16 @@ public class ConfigureMapMenu { showGpxSelectionDialog(adapter, adapter.getItem(pos)); } } else if (itemId == R.string.shared_string_wikipedia) { - WikipediaPoiMenu.toggleWikipediaPoi(ma, isChecked, true); + WikipediaPoiMenu.toggleWikipediaPoi(ma, isChecked, true, + new CallbackWithObject() { + @Override + public boolean processResult(Boolean result) { + item.setSelected(result); + item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + adapter.notifyDataSetChanged(); + return true; + } + }); } else if (itemId == R.string.map_markers) { settings.SHOW_MAP_MARKERS.set(isChecked); } else if (itemId == R.string.layer_map) { diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java index 4baf24a982..ec7ca88d26 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java @@ -59,6 +59,14 @@ public class WikipediaPoiMenu { adapter.setProfileDependent(true); adapter.setNightMode(nightMode); + final CallbackWithObject callback = new CallbackWithObject() { + @Override + public boolean processResult(Boolean result) { + mapActivity.getDashboard().refreshContent(true); + return true; + } + }; + ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() { @Override public boolean onContextMenuClick(final ArrayAdapter adapter, @@ -67,11 +75,11 @@ public class WikipediaPoiMenu { app.runInUIThread(new Runnable() { @Override public void run() { - toggleWikipediaPoi(mapActivity, !enabled, true); + toggleWikipediaPoi(mapActivity, !enabled, true, callback); } }); } else if (itemId == languageActionStringId) { - showLanguagesDialog(mapActivity, appMode, true, true); + showLanguagesDialog(mapActivity, appMode, true, true, callback); } return false; } @@ -225,7 +233,8 @@ public class WikipediaPoiMenu { private static void showLanguagesDialog(@NonNull final MapActivity mapActivity, @NonNull final ApplicationMode appMode, final boolean usedOnMap, - final boolean refresh) { + final boolean refresh, + final CallbackWithObject callback) { final OsmandApplication app = mapActivity.getMyApplication(); SelectWikiLanguagesBottomSheet.showInstance(mapActivity, appMode, usedOnMap, new CallbackWithObject() { @@ -239,10 +248,10 @@ public class WikipediaPoiMenu { if (refresh) { refreshWikiPoi(mapActivity, globalWikiEnabled); } else { - toggleWikipediaPoi(mapActivity, true, usedOnMap); + toggleWikipediaPoi(mapActivity, true, usedOnMap, callback); } } else { - toggleWikipediaPoi(mapActivity, false, usedOnMap); + toggleWikipediaPoi(mapActivity, false, usedOnMap, callback); } } return true; @@ -293,7 +302,8 @@ public class WikipediaPoiMenu { return bundle; } - public static void toggleWikipediaPoi(final MapActivity mapActivity, boolean enable, boolean usedOnMap) { + public static void toggleWikipediaPoi(final MapActivity mapActivity, boolean enable, + boolean usedOnMap, CallbackWithObject callback) { OsmandApplication app = mapActivity.getMyApplication(); OsmandSettings settings = app.getSettings(); if (enable) { @@ -304,13 +314,15 @@ public class WikipediaPoiMenu { showWikiOnMap(app, globalWikiEnabled); } else { ApplicationMode appMode = settings.getApplicationMode(); - showLanguagesDialog(mapActivity, appMode, usedOnMap, false); + showLanguagesDialog(mapActivity, appMode, usedOnMap, false, callback); } } else { settings.SHOW_WIKIPEDIA_POI.set(false); hideWikiFromMap(app); } - mapActivity.getDashboard().refreshContent(true); + if (callback != null) { + callback.processResult(settings.SHOW_WIKIPEDIA_POI.get()); + } mapActivity.refreshMap(); }