diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index ae8af82440..4074785025 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -65,8 +65,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map.Entry; -import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; - /** * Object is responsible to maintain layers using by map activity */ @@ -273,7 +271,9 @@ public class MapActivityLayers { final ContextMenuAdapter adapter = new ContextMenuAdapter(app); final List list = new ArrayList<>(); for (PoiUIFilter f : poiFilters.getSortedPoiFilters(true)) { - addFilterToList(adapter, list, f, true); + if (!f.isTopWikiFilter()) { + addFilterToList(adapter, list, f, true); + } } list.add(poiFilters.getCustomPOIFilter()); adapter.setProfileDependent(true); @@ -306,9 +306,9 @@ public class MapActivityLayers { if (filter.isStandardFilter()) { filter.removeUnsavedFilterByName(); } - poiFilters.addSelectedPoiFilter(PoiTemplateList.POI, filter); + poiFilters.addSelectedPoiFilter(filter); } else { - poiFilters.removeSelectedPoiFilter(PoiTemplateList.POI, filter); + poiFilters.removeSelectedPoiFilter(filter); } } mapView.refreshMap(); @@ -351,7 +351,9 @@ public class MapActivityLayers { final List list = new ArrayList<>(); list.add(poiFilters.getCustomPOIFilter()); for (PoiUIFilter f : poiFilters.getSortedPoiFilters(true)) { - addFilterToList(adapter, list, f, false); + if (!f.isTopWikiFilter()) { + addFilterToList(adapter, list, f, false); + } } final ArrayAdapter listAdapter = adapter.createListAdapter(activity, !isNightMode(app)); @@ -370,8 +372,9 @@ public class MapActivityLayers { if (pf.isStandardFilter()) { pf.removeUnsavedFilterByName(); } - poiFilters.clearSelectedPoiFilters(PoiTemplateList.POI); - poiFilters.addSelectedPoiFilter(PoiTemplateList.POI, pf); + PoiUIFilter wiki = poiFilters.getTopWikiPoiFilter(); + poiFilters.clearSelectedPoiFilters(wiki); + poiFilters.addSelectedPoiFilter(pf); mapView.refreshMap(); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 6f446d40b1..727c67ce43 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -78,8 +78,6 @@ import java.util.TreeMap; import gnu.trove.set.hash.TLongHashSet; -import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; - /** * Search poi activity */ @@ -166,7 +164,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa public boolean onMenuItemClick(MenuItem item) { OsmandSettings settings = app.getSettings(); filter.setFilterByName(searchFilter.getText().toString().trim()); - app.getPoiFilters().addSelectedPoiFilter(PoiTemplateList.POI, filter); + app.getPoiFilters().addSelectedPoiFilter(filter); if (location != null) { settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15); } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index b3e11e54b6..1ea1502fcf 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -46,6 +46,7 @@ import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.poi.PoiFiltersHelper; +import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.settings.backend.OsmandSettings; @@ -101,7 +102,6 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.TEXT_SIZE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID; import static net.osmand.plus.ContextMenuAdapter.makeDeleteAction; -import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_DENSITY_ATTR; import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_ATTR; import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_SCHEME_ATTR; @@ -255,7 +255,8 @@ public class ConfigureMapMenu { } @Override - public boolean onContextMenuClick(final ArrayAdapter adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) { + public boolean onContextMenuClick(final ArrayAdapter adapter, int itemId, + final int pos, boolean isChecked, int[] viewCoordinates) { final OsmandSettings settings = ma.getMyApplication().getSettings(); final PoiFiltersHelper poiFiltersHelper = ma.getMyApplication().getPoiFilters(); final ContextMenuItem item = cm.getItem(pos); @@ -263,12 +264,13 @@ public class ConfigureMapMenu { item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); } if (itemId == R.string.layer_poi) { - poiFiltersHelper.clearSelectedPoiFilters(PoiTemplateList.POI); + PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter(); + poiFiltersHelper.clearSelectedPoiFilters(wiki); if (isChecked) { showPoiFilterDialog(adapter, adapter.getItem(pos)); } else { adapter.getItem(pos).setDescription( - poiFiltersHelper.getSelectedPoiFiltersName(PoiTemplateList.POI)); + poiFiltersHelper.getSelectedPoiFiltersName(wiki)); } } else if (itemId == R.string.layer_amenity_label) { settings.SHOW_POI_LABEL.set(isChecked); @@ -283,17 +285,17 @@ public class ConfigureMapMenu { showGpxSelectionDialog(adapter, adapter.getItem(pos)); } } else if (itemId == R.string.shared_string_wikipedia) { - WikipediaPoiMenu.toggleWikipediaPoi(ma, isChecked, true, - new CallbackWithObject() { - @Override - public boolean processResult(Boolean selected) { - item.setSelected(selected); - item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); - item.setDescription(selected ? WikipediaPoiMenu.getLanguagesSummary(ma.getMyApplication()) : null); - adapter.notifyDataSetChanged(); - return true; - } - }); + WikipediaPoiMenu.toggleWikipediaPoi(ma, isChecked, new CallbackWithObject() { + @Override + public boolean processResult(Boolean selected) { + item.setSelected(selected); + item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + item.setDescription(selected ? + WikipediaPoiMenu.getLanguagesSummary(ma.getMyApplication()) : null); + adapter.notifyDataSetChanged(); + return true; + } + }); } else if (itemId == R.string.rendering_category_transport) { boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication()); TransportLinesMenu.toggleTransportLines(ma, !selected, new CallbackWithObject() { @@ -343,19 +345,20 @@ public class ConfigureMapMenu { protected void showPoiFilterDialog(final ArrayAdapter adapter, final ContextMenuItem item) { final PoiFiltersHelper poiFiltersHelper = ma.getMyApplication().getPoiFilters(); + final PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter(); MapActivityLayers.DismissListener dismissListener = new MapActivityLayers.DismissListener() { @Override public void dismiss() { PoiFiltersHelper pf = ma.getMyApplication().getPoiFilters(); - boolean selected = pf.isShowingAnyPoi(PoiTemplateList.POI); + boolean selected = pf.isShowingAnyPoi(wiki); item.setSelected(selected); - item.setDescription(pf.getSelectedPoiFiltersName(PoiTemplateList.POI)); + item.setDescription(pf.getSelectedPoiFiltersName(wiki)); item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); adapter.notifyDataSetChanged(); } }; - if (poiFiltersHelper.isShowingAnyPoi(PoiTemplateList.POI)) { + if (poiFiltersHelper.isShowingAnyPoi(wiki)) { ma.getMapLayers().showMultichoicePoiFilterDialog(ma.getMapView(), dismissListener); } else { @@ -387,12 +390,13 @@ public class ConfigureMapMenu { .setItemDeleteAction(makeDeleteAction(settings.SHOW_FAVORITES)) .setListener(l) .createItem()); - selected = app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.POI); + PoiUIFilter wiki = app.getPoiFilters().getTopWikiPoiFilter(); + selected = app.getPoiFilters().isShowingAnyPoi(wiki); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(POI_OVERLAY_ID) .setTitleId(R.string.layer_poi, activity) .setSelected(selected) - .setDescription(app.getPoiFilters().getSelectedPoiFiltersName(PoiTemplateList.POI)) + .setDescription(app.getPoiFilters().getSelectedPoiFiltersName(wiki)) .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_action_info_dark) .setSecondaryIcon(R.drawable.ic_action_additional_option) @@ -428,7 +432,7 @@ public class ConfigureMapMenu { .setSecondaryIcon(R.drawable.ic_action_additional_option) .setListener(l).createItem()); - selected = app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.WIKI); + selected = app.getPoiFilters().isTopWikiFilterSelected(); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(WIKIPEDIA_ID) .setTitleId(R.string.shared_string_wikipedia, activity) @@ -437,7 +441,6 @@ public class ConfigureMapMenu { .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_plugin_wikipedia) .setSecondaryIcon(R.drawable.ic_action_additional_option) - .setItemDeleteAction(makeDeleteAction(settings.SHOW_WIKIPEDIA_POI)) .setListener(l).createItem()); selected = settings.SHOW_MAP_MARKERS.get(); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 8e30fb274f..1a71eea836 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -13,7 +13,6 @@ import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiType; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; @@ -38,10 +37,11 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import java.util.TreeSet; import static net.osmand.osm.MapPoiTypes.WIKI_PLACE; +import static net.osmand.plus.wikipedia.WikipediaPoiMenu.ENABLED_WIKI_POI_LANGUAGES_KEY; +import static net.osmand.plus.wikipedia.WikipediaPoiMenu.GLOBAL_WIKI_POI_ENABLED_KEY; public class PoiFiltersHelper { @@ -55,10 +55,9 @@ public class PoiFiltersHelper { private PoiUIFilter customPOIFilter; private PoiUIFilter showAllPOIFilter; private PoiUIFilter localWikiPoiFilter; - private PoiUIFilter globalWikiPoiFilter; + private PoiUIFilter topWikiPoiFilter; private List cacheTopStandardFilters; - private List cacheWikipediaFilters; - private Map> selectedPoiFilters = new TreeMap<>(); + private Set selectedPoiFilters = new TreeSet<>(); private static final String UDF_CAR_AID = "car_aid"; private static final String UDF_FOR_TOURISTS = "for_tourists"; @@ -75,10 +74,6 @@ public class PoiFiltersHelper { UDF_CAR_AID, UDF_FOR_TOURISTS, UDF_FOOD_SHOP, UDF_FUEL, UDF_SIGHTSEEING, UDF_EMERGENCY, UDF_PUBLIC_TRANSPORT, UDF_ACCOMMODATION, UDF_RESTAURANTS, UDF_PARKING }; - - public enum PoiTemplateList { - POI, WIKI - } public PoiFiltersHelper(OsmandApplication application) { this.application = application; @@ -139,56 +134,42 @@ public class PoiFiltersHelper { return localWikiPoiFilter; } - public PoiUIFilter getGlobalWikiPoiFilter() { - if (globalWikiPoiFilter == null) { + public void prepareTopWikiFilter(@NonNull PoiUIFilter wiki) { + boolean prepareByDefault = true; + Bundle wikiSettings = WikipediaPoiMenu.getWikiPoiSettings(application); + if (wikiSettings != null) { + boolean allLanguages = wikiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); + List languages = wikiSettings + .getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY); + if (!allLanguages && languages != null) { + prepareByDefault = false; + String wikiLang = "wiki:lang:"; + StringBuilder sb = new StringBuilder(); + for (String lang : languages) { + if (sb.length() > 1) { + sb.append(" "); + } + sb.append(wikiLang).append(lang); + } + wiki.setFilterByName(sb.toString()); + } + } + if (prepareByDefault) { + wiki.setFilterByName(null); + } + } + + public PoiUIFilter getTopWikiPoiFilter() { + if (topWikiPoiFilter == null) { String wikiFilterId = PoiUIFilter.STD_PREFIX + "osmwiki"; for (PoiUIFilter filter : getTopDefinedPoiFilters()) { if (wikiFilterId.equals(filter.getFilterId())) { - globalWikiPoiFilter = filter; + topWikiPoiFilter = filter; break; } } } - return globalWikiPoiFilter; - } - - public List getLocalWikipediaPoiFilters(boolean onlyActiveLocales) { - String wikiLang = "wiki:lang:"; - if (cacheWikipediaFilters == null) { - List wikipediaFilters = new ArrayList<>(); - PoiType place = application.getPoiTypes().getPoiTypeByKey(WIKI_PLACE); - if (place != null) { - for (String locale : application.getPoiTypes().getAllAvailableWikiLocales()) { - PoiUIFilter filter = new PoiUIFilter(place, application, " " + - WikipediaPoiMenu.getTranslation(application, locale)); - filter.setSavedFilterByName(wikiLang + locale); - filter.setStandardFilter(true); - wikipediaFilters.add(filter); - } - } - cacheWikipediaFilters = wikipediaFilters; - } - if (onlyActiveLocales && cacheWikipediaFilters.size() > 0) { - List onlyActiveLocalFilters = new ArrayList<>(); - Bundle wikiPoiSettings = WikipediaPoiMenu.getWikiPoiSettings(application); - if (wikiPoiSettings != null) { - List enabledWikipediaPoiLocales = - wikiPoiSettings.getStringArrayList(WikipediaPoiMenu.ENABLED_WIKI_POI_LANGUAGES_KEY); - if (enabledWikipediaPoiLocales != null) { - for (PoiUIFilter filter : cacheWikipediaFilters) { - for (String locale : enabledWikipediaPoiLocales) { - String filterId = filter.getSavedFilterByName(); - String filterLocale = filterId.substring(wikiLang.length()); - if (locale.equalsIgnoreCase(filterLocale)) { - onlyActiveLocalFilters.add(filter); - } - } - } - } - } - return onlyActiveLocalFilters; - } - return cacheWikipediaFilters; + return topWikiPoiFilter; } public PoiUIFilter getShowAllPOIFilter() { @@ -235,13 +216,9 @@ public class PoiFiltersHelper { return f; } } - for (PoiUIFilter f : getLocalWikipediaPoiFilters(true)) { - if (f.getFilterId().equals(filterId)) { - return f; - } - } PoiUIFilter ff = getFilterById(filterId, getCustomPOIFilter(), getSearchByNamePOIFilter(), - getGlobalWikiPoiFilter(), getShowAllPOIFilter(), getNominatimPOIFilter(), getNominatimAddressFilter()); + getTopWikiPoiFilter(), getLocalWikiPOIFilter(), getShowAllPOIFilter(), + getNominatimPOIFilter(), getNominatimAddressFilter()); if (ff != null) { return ff; } @@ -306,6 +283,9 @@ public class PoiFiltersHelper { List top = new ArrayList<>(); // user defined top.addAll(getUserDefinedPoiFilters(true)); + if (getLocalWikiPOIFilter() != null) { + top.add(getLocalWikiPOIFilter()); + } // default MapPoiTypes poiTypes = application.getPoiTypes(); for (AbstractPoiType t : poiTypes.getTopVisibleFilters()) { @@ -505,79 +485,68 @@ public class PoiFiltersHelper { return false; } - public Set getSelectedPoiFilters() { - Set result = new TreeSet<>(); - for (Set template : selectedPoiFilters.values()) { - if (template != null) { - result.addAll(template); + public Set getSelectedPoiFilters(PoiUIFilter ... filtersToExclude) { + if (filtersToExclude != null && filtersToExclude.length > 0) { + Set filters = new TreeSet<>(); + for (PoiUIFilter filter : selectedPoiFilters) { + boolean skip = false; + for (PoiUIFilter filterToExclude : filtersToExclude) { + String filterToExcludeId = filterToExclude.getFilterId(); + if (filterToExcludeId != null && filterToExcludeId.equals(filter.getFilterId())) { + skip = true; + break; + } + } + if (!skip) { + filters.add(filter); + } } + return filters; } - return result; + return selectedPoiFilters; } - @NonNull - public Set getSelectedPoiFilters(PoiTemplateList type) { - Set result = selectedPoiFilters.get(type); - if (result == null) { - return new TreeSet<>(); - } - return result; - } - - public void addSelectedPoiFilter(PoiTemplateList type, PoiUIFilter filter) { - if (!selectedPoiFilters.containsKey(type)) { - selectedPoiFilters.put(type, new TreeSet()); - } - Set templateFilters = selectedPoiFilters.get(type); - if (templateFilters != null) { - templateFilters.add(filter); + public void addSelectedPoiFilter(PoiUIFilter filter) { + if (filter.isTopWikiFilter()) { + prepareTopWikiFilter(filter); } + selectedPoiFilters.add(filter); saveSelectedPoiFilters(); } - public void removeSelectedPoiFilter(PoiTemplateList type, PoiUIFilter filter) { - if (selectedPoiFilters.containsKey(type)) { - Set templateFilters = selectedPoiFilters.get(type); - if (templateFilters != null) { - templateFilters.remove(filter); + public void removeSelectedPoiFilter(PoiUIFilter filter) { + selectedPoiFilters.remove(filter); + saveSelectedPoiFilters(); + } + + public boolean isShowingAnyPoi(PoiUIFilter ... filtersToExclude) { + return !getSelectedPoiFilters(filtersToExclude).isEmpty(); + } + + public void clearSelectedPoiFilters(PoiUIFilter ... filtersToExclude) { + if (filtersToExclude != null && filtersToExclude.length > 0) { + Iterator it = selectedPoiFilters.iterator(); + while (it.hasNext()) { + PoiUIFilter filter = it.next(); + boolean skip = false; + for (PoiUIFilter filterToExclude : filtersToExclude) { + String filterToExcludeId = filterToExclude.getFilterId(); + if (filterToExcludeId != null + && filterToExcludeId.equals(filter.getFilterId())) { + skip = true; + break; + } + } + if (!skip) { + it.remove(); + } } + } else { + selectedPoiFilters.clear(); } saveSelectedPoiFilters(); } - public boolean isShowingAnyPoi() { - for (PoiTemplateList type : selectedPoiFilters.keySet()) { - if (isShowingAnyPoi(type)) { - return true; - } - } - return false; - } - - public boolean isShowingAnyPoi(PoiTemplateList type) { - return !getSelectedPoiFilters(type).isEmpty(); - } - - public void clearSelectedPoiFilters() { - for (PoiTemplateList t : selectedPoiFilters.keySet()) { - clearSelectedPoiFilters(t); - } - saveSelectedPoiFilters(); - } - - public void clearSelectedPoiFilters(PoiTemplateList type) { - Set templateFilters = selectedPoiFilters.get(type); - if (templateFilters != null) { - templateFilters.clear(); - } - saveSelectedPoiFilters(); - } - - public void hidePoiFilters() { - selectedPoiFilters.clear(); - saveSelectedPoiFilters(); - } - public String getFiltersName(Set filters) { if (filters.isEmpty()) { return application.getResources().getString(R.string.shared_string_none); @@ -590,23 +559,28 @@ public class PoiFiltersHelper { } } - public String getSelectedPoiFiltersName(PoiTemplateList type) { - return getFiltersName(getSelectedPoiFilters(type)); + public String getSelectedPoiFiltersName(PoiUIFilter ... filtersToExclude) { + return getFiltersName(getSelectedPoiFilters(filtersToExclude)); } public boolean isPoiFilterSelected(PoiUIFilter filter) { - for (Set template : selectedPoiFilters.values()) { - return template.contains(filter); + return selectedPoiFilters.contains(filter); + } + + public boolean isTopWikiFilterSelected() { + String wikiFilterId = getTopWikiPoiFilter().getFilterId(); + for (PoiUIFilter filter : selectedPoiFilters) { + if (wikiFilterId.equals(filter.getFilterId())) { + return true; + } } return false; } public boolean isPoiFilterSelected(String filterId) { - for (Set template : selectedPoiFilters.values()) { - for (PoiUIFilter filter : template) { - if (filter.filterId.equals(filterId)) { - return true; - } + for (PoiUIFilter filter : selectedPoiFilters) { + if (filter.filterId.equals(filterId)) { + return true; } } return false; @@ -617,20 +591,14 @@ public class PoiFiltersHelper { if(!application.getPoiTypes().isInit()) { return; } - selectedPoiFilters.clear(); - OsmandSettings settings = application.getSettings(); - Set filters = settings.getSelectedPoiFilters(); - boolean shouldShowWikiPoi = WikipediaPoiMenu.isWikiPoiEnabled(application); - for (String f : filters) { + selectedPoiFilters = new TreeSet<>(); + for (String f : application.getSettings().getSelectedPoiFilters()) { PoiUIFilter filter = getFilterById(f); if (filter != null) { - if (filter.isWikiFilter()) { - if (shouldShowWikiPoi) { - addSelectedPoiFilter(PoiTemplateList.WIKI, filter); - } - } else { - addSelectedPoiFilter(PoiTemplateList.POI, filter); + if (filter.isTopWikiFilter()) { + prepareTopWikiFilter(filter); } + selectedPoiFilters.add(filter); } } } @@ -664,10 +632,8 @@ public class PoiFiltersHelper { private void saveSelectedPoiFilters() { Set filters = new HashSet<>(); - for (Set template : selectedPoiFilters.values()) { - for (PoiUIFilter filter : template) { - filters.add(filter.filterId); - } + for (PoiUIFilter filter : selectedPoiFilters) { + filters.add(filter.filterId); } application.getSettings().setSelectedPoiFilters(filters); } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index 59d22aef93..99c42dea21 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -4,6 +4,7 @@ package net.osmand.plus.poi; import android.content.Context; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; @@ -150,8 +151,11 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } public boolean isWikiFilter() { - return filterId.startsWith(STD_PREFIX + WIKI_PLACE) - || filterId.equals(STD_PREFIX + OSM_WIKI_CATEGORY); + return filterId.startsWith(STD_PREFIX + WIKI_PLACE) || isTopWikiFilter(); + } + + public boolean isTopWikiFilter() { + return filterId.equals(STD_PREFIX + OSM_WIKI_CATEGORY); } public String getFilterByName() { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java index f244fe0f4c..4c2d452e64 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java @@ -33,8 +33,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; - public class ShowHidePoiAction extends QuickAction { @@ -114,18 +112,18 @@ public class ShowHidePoiAction extends QuickAction { PoiFiltersHelper pf = activity.getMyApplication().getPoiFilters(); List poiFilters = loadPoiFilters(activity.getMyApplication().getPoiFilters()); - if (!isCurrentFilters(pf.getSelectedPoiFilters(PoiTemplateList.POI), poiFilters)) { + if (!isCurrentFilters(pf.getSelectedPoiFilters(), poiFilters)) { - pf.clearSelectedPoiFilters(PoiTemplateList.POI); + pf.clearSelectedPoiFilters(); for (PoiUIFilter filter : poiFilters) { if (filter.isStandardFilter()) { filter.removeUnsavedFilterByName(); } - pf.addSelectedPoiFilter(PoiTemplateList.POI, filter); + pf.addSelectedPoiFilter(filter); } - } else pf.clearSelectedPoiFilters(PoiTemplateList.POI); + } else pf.clearSelectedPoiFilters(); activity.getMapLayers().updateLayers(activity.getMapView()); } @@ -135,7 +133,7 @@ public class ShowHidePoiAction extends QuickAction { PoiFiltersHelper pf = application.getPoiFilters(); List poiFilters = loadPoiFilters(application.getPoiFilters()); - return isCurrentFilters(pf.getSelectedPoiFilters(PoiTemplateList.POI), poiFilters); + return isCurrentFilters(pf.getSelectedPoiFilters(), poiFilters); } private boolean isCurrentFilters(Set currentPoiFilters, List poiFilters) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 73d1573858..7cf08a10cc 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -120,8 +120,6 @@ import java.util.Map; import java.util.Set; import java.util.Stack; -import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; - public class MapRouteInfoMenu implements IRouteInformationListener, CardListener, FavoritesListener { private static final Log LOG = PlatformUtil.getLog(MapRouteInfoMenu.class); @@ -1158,7 +1156,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener private void createShowAlongTheRouteItems(MapActivity mapActivity, LinearLayout optionsContainer) { OsmandApplication app = mapActivity.getMyApplication(); final ApplicationMode applicationMode = app.getRoutingHelper().getAppMode(); - final Set poiFilters = app.getPoiFilters().getSelectedPoiFilters(PoiTemplateList.POI); + final Set poiFilters = app.getPoiFilters().getSelectedPoiFilters(); final boolean traffic = app.getSettings().SHOW_TRAFFIC_WARNINGS.getModeValue(applicationMode); final boolean fav = app.getSettings().SHOW_NEARBY_FAVORITES.getModeValue(applicationMode); if (!poiFilters.isEmpty()) { @@ -1184,7 +1182,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener public void onClick(View v) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - mapActivity.getMyApplication().getPoiFilters().removeSelectedPoiFilter(PoiTemplateList.POI, poiUIFilter); + mapActivity.getMyApplication().getPoiFilters() + .removeSelectedPoiFilter(poiUIFilter); mapActivity.getMapView().refreshMap(); updateOptionsButtons(); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java index c6df9e64a1..20c93dadc6 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java @@ -45,8 +45,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; - public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment implements IRouteInformationListener, IRoutingDataUpdateListener { public static final String TAG = "ShowAlongTheRouteBottomSheet"; @@ -436,8 +434,8 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment View v; if (type == WaypointHelper.POI) { v = themedInflater.inflate(R.layout.along_the_route_radius_poi, null); - String descEx = !app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.POI) ? - getString(R.string.poi) : app.getPoiFilters().getSelectedPoiFiltersName(PoiTemplateList.POI); + String descEx = !app.getPoiFilters().isShowingAnyPoi() ? + getString(R.string.poi) : app.getPoiFilters().getSelectedPoiFiltersName(); ((TextView) v.findViewById(R.id.title)).setText(getString(R.string.search_radius_proximity) + ":"); ((TextView) v.findViewById(R.id.titleEx)).setText(getString(R.string.shared_string_type) + ":"); final TextView radiusEx = (TextView) v.findViewById(R.id.descriptionEx); @@ -487,7 +485,7 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment new MapActivityLayers.DismissListener() { @Override public void dismiss() { - if (app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.POI)) { + if (app.getPoiFilters().isShowingAnyPoi()) { enableType(type, enable); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 078908ad1e..e882ff5da0 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -111,7 +111,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; import static net.osmand.plus.search.SendSearchQueryBottomSheet.MISSING_SEARCH_LOCATION_KEY; import static net.osmand.plus.search.SendSearchQueryBottomSheet.MISSING_SEARCH_QUERY_KEY; import static net.osmand.search.core.ObjectType.POI_TYPE; @@ -388,8 +387,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } else { filter = (PoiUIFilter) searchPhrase.getLastSelectedWord().getResult().object; } - app.getPoiFilters().clearSelectedPoiFilters(PoiTemplateList.POI); - app.getPoiFilters().addSelectedPoiFilter(PoiTemplateList.POI, filter); + app.getPoiFilters().clearSelectedPoiFilters(); + app.getPoiFilters().addSelectedPoiFilter(filter); mapActivity.getContextMenu().closeActiveToolbar(); showToolbar(); @@ -866,7 +865,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } public void closeSearch() { - app.getPoiFilters().clearSelectedPoiFilters(PoiTemplateList.POI); + app.getPoiFilters().clearSelectedPoiFilters(); dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index e51454e548..fd13f09dc1 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -46,8 +46,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; - public class QuickSearchHelper implements ResourceListener { public static final int SEARCH_FAVORITE_API_PRIORITY = 50; @@ -504,8 +502,8 @@ public class QuickSearchHelper implements ResourceListener { }); controller.setTitle(filter.getName()); PoiFiltersHelper helper = mapActivity.getMyApplication().getPoiFilters(); - helper.clearSelectedPoiFilters(PoiTemplateList.POI); - helper.addSelectedPoiFilter(PoiTemplateList.POI, filter); + helper.clearSelectedPoiFilters(); + helper.addSelectedPoiFilter(filter); mapActivity.showTopToolbar(controller); mapActivity.refreshMap(); } @@ -514,7 +512,7 @@ public class QuickSearchHelper implements ResourceListener { @NonNull TopToolbarController controller, @Nullable Runnable action) { mapActivity.hideTopToolbar(controller); - mapActivity.getMyApplication().getPoiFilters().clearSelectedPoiFilters(PoiTemplateList.POI); + mapActivity.getMyApplication().getPoiFilters().clearSelectedPoiFilters(); mapActivity.refreshMap(); if (action != null) { action.run(); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 1a336e50eb..152c2f1b90 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -1525,7 +1525,6 @@ public class OsmandSettings { public final CommonPreference WIKI_ARTICLE_SHOW_IMAGES_ASKED = new BooleanPreference("wikivoyage_show_images_asked", false).makeGlobal(); public final CommonPreference WIKI_ARTICLE_SHOW_IMAGES = new EnumStringPreference<>("wikivoyage_show_imgs", WikiArticleShowImages.OFF, WikiArticleShowImages.values()).makeGlobal(); - public final CommonPreference SHOW_WIKIPEDIA_POI = new BooleanPreference("show_wikipedia_poi", false).makeProfile(); public final CommonPreference GLOBAL_WIKIPEDIA_POI_ENABLED = new BooleanPreference("global_wikipedia_poi_enabled", false).makeProfile(); public final ListStringPreference WIKIPEDIA_POI_ENABLED_LANGUAGES = (ListStringPreference) new ListStringPreference("wikipedia_poi_enabled_languages", null, ",").makeProfile().cache(); diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 56424ee634..dadd9f5f58 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -39,6 +39,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.WaypointHelper; +import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.routing.IRouteInformationListener; @@ -205,8 +206,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon @Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { Set selectedPoiFilters = app.getPoiFilters().getSelectedPoiFilters(); - if (!this.filters.equals(selectedPoiFilters)) { - this.filters = new TreeSet<>(selectedPoiFilters); + if (this.filters != selectedPoiFilters) { + this.filters = selectedPoiFilters; data.clearCache(); } diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java index 44a3042657..113cba1ebe 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java @@ -151,6 +151,7 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen languages.add(new WikiLanguageItem(locale, WikipediaPoiMenu.getTranslation(app, locale), checked, topDefined)); } } else { + isGlobalWikiPoiEnabled = true; for (String locale : app.getPoiTypes().getAllAvailableWikiLocales()) { boolean topDefined = preferredLocales.contains(locale); languages.add(new WikiLanguageItem(locale, WikipediaPoiMenu.getTranslation(app, locale), false, topDefined)); diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java index cde895b1c3..054edb18c5 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java @@ -29,7 +29,6 @@ import java.util.List; import java.util.Set; import static net.osmand.osm.MapPoiTypes.WIKI_LANG; -import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; public class WikipediaPoiMenu { @@ -54,7 +53,7 @@ public class WikipediaPoiMenu { final int toggleActionStringId = R.string.shared_string_wikipedia; final int languageActionStringId = R.string.shared_string_language; final int spaceHeight = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_big_item_height); - final boolean enabled = app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.WIKI); + final boolean enabled = app.getPoiFilters().isTopWikiFilterSelected(); ContextMenuAdapter adapter = new ContextMenuAdapter(app); adapter.setDefaultLayoutId(R.layout.dash_item_with_description_72dp); adapter.setProfileDependent(true); @@ -76,11 +75,11 @@ public class WikipediaPoiMenu { app.runInUIThread(new Runnable() { @Override public void run() { - toggleWikipediaPoi(mapActivity, !enabled, true, callback); + toggleWikipediaPoi(mapActivity, !enabled, callback); } }); } else if (itemId == languageActionStringId) { - showLanguagesDialog(mapActivity, appMode, true, true, callback); + showLanguagesDialog(mapActivity, appMode, true, callback); } return false; } @@ -234,7 +233,6 @@ public class WikipediaPoiMenu { private static void showLanguagesDialog(@NonNull final MapActivity mapActivity, @NonNull final ApplicationMode appMode, final boolean usedOnMap, - final boolean refresh, final CallbackWithObject callback) { final OsmandApplication app = mapActivity.getMyApplication(); SelectWikiLanguagesBottomSheet.showInstance(mapActivity, appMode, usedOnMap, @@ -244,15 +242,9 @@ public class WikipediaPoiMenu { if (result) { Bundle wikiPoiSetting = getWikiPoiSettingsForProfile(app, appMode); if (wikiPoiSetting != null) { - boolean globalWikiEnabled = - wikiPoiSetting.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); - if (refresh) { - refreshWikiPoi(mapActivity, globalWikiEnabled); - } else { - toggleWikipediaPoi(mapActivity, true, usedOnMap, callback); - } + refreshWikipediaOnMap(mapActivity); } else { - toggleWikipediaPoi(mapActivity, false, usedOnMap, callback); + toggleWikipediaPoi(mapActivity, false, callback); } } return true; @@ -304,65 +296,46 @@ public class WikipediaPoiMenu { } public static void toggleWikipediaPoi(final MapActivity mapActivity, boolean enable, - boolean usedOnMap, CallbackWithObject callback) { + CallbackWithObject callback) { OsmandApplication app = mapActivity.getMyApplication(); - OsmandSettings settings = app.getSettings(); if (enable) { - Bundle wikiPoiSettings = getWikiPoiSettings(app); - if (wikiPoiSettings != null) { - settings.SHOW_WIKIPEDIA_POI.set(true); - boolean globalWikiEnabled = wikiPoiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); - showWikiOnMap(app, globalWikiEnabled); - } else { - ApplicationMode appMode = settings.getApplicationMode(); - showLanguagesDialog(mapActivity, appMode, usedOnMap, false, callback); - } + showWikipediaOnMap(app); } else { - settings.SHOW_WIKIPEDIA_POI.set(false); - hideWikiFromMap(app); + hideWikipediaFromMap(app); } if (callback != null) { - callback.processResult(settings.SHOW_WIKIPEDIA_POI.get()); + callback.processResult(enable); } mapActivity.refreshMap(); } - public static void refreshWikiPoi(MapActivity mapActivity, boolean globalWikiEnabled) { + public static void refreshWikipediaOnMap(MapActivity mapActivity) { OsmandApplication app = mapActivity.getMyApplication(); - hideWikiFromMap(app); - showWikiOnMap(app, globalWikiEnabled); + app.getPoiFilters().loadSelectedPoiFilters(); mapActivity.getDashboard().refreshContent(true); mapActivity.refreshMap(); } - private static void showWikiOnMap(OsmandApplication app, boolean globalWikiEnabled) { + private static void showWikipediaOnMap(OsmandApplication app) { PoiFiltersHelper ph = app.getPoiFilters(); - if (globalWikiEnabled) { - ph.addSelectedPoiFilter(PoiTemplateList.WIKI, ph.getGlobalWikiPoiFilter()); - } else { - List filters = ph.getLocalWikipediaPoiFilters(true); - for (PoiUIFilter filter : filters) { - ph.addSelectedPoiFilter(PoiTemplateList.WIKI, filter); - } - } + PoiUIFilter wiki = ph.getTopWikiPoiFilter(); + ph.loadSelectedPoiFilters(); + ph.addSelectedPoiFilter(wiki); } - private static void hideWikiFromMap(OsmandApplication app) { + private static void hideWikipediaFromMap(OsmandApplication app) { PoiFiltersHelper ph = app.getPoiFilters(); - for (PoiUIFilter filter : ph.getSelectedPoiFilters(PoiTemplateList.WIKI)) { - ph.removePoiFilter(filter); - } - ph.clearSelectedPoiFilters(PoiTemplateList.WIKI); + PoiUIFilter wiki = ph.getTopWikiPoiFilter(); + ph.removePoiFilter(wiki); + ph.removeSelectedPoiFilter(wiki); } public static String getLanguagesSummary(OsmandApplication app) { - Bundle wikiLanguagesSetting = getWikiPoiSettings(app); - if (wikiLanguagesSetting != null) { - boolean globalWikiEnabled = wikiLanguagesSetting.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); - List enabledLocales = wikiLanguagesSetting.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY); - if (globalWikiEnabled) { - return app.getString(R.string.shared_string_all_languages); - } else if (enabledLocales != null) { + Bundle wikiSetting = getWikiPoiSettings(app); + if (wikiSetting != null) { + boolean globalWikiEnabled = wikiSetting.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); + List enabledLocales = wikiSetting.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY); + if (!globalWikiEnabled && enabledLocales != null) { List translations = new ArrayList<>(); for (String locale : enabledLocales) { translations.add(getTranslation(app, locale)); @@ -370,11 +343,7 @@ public class WikipediaPoiMenu { return android.text.TextUtils.join(", ", translations); } } - return null; - } - - public static boolean isWikiPoiEnabled(OsmandApplication app) { - return app.getSettings().SHOW_WIKIPEDIA_POI.get() && getWikiPoiSettings(app) != null; + return app.getString(R.string.shared_string_all_languages); } public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) { @@ -385,7 +354,7 @@ public class WikipediaPoiMenu { @NonNull Set availableArticleLangs, String preferredLanguage) { Bundle wikiPoiSettings = getWikiPoiSettings(app); - if (!app.getSettings().SHOW_WIKIPEDIA_POI.get() || wikiPoiSettings == null) { + if (!app.getPoiFilters().isTopWikiFilterSelected() || wikiPoiSettings == null) { // Wikipedia POI setting disabled return preferredLanguage; }