Change Wikipedia poi behaviour

This commit is contained in:
Nazar-Kutz 2020-06-01 13:00:01 +03:00
parent 873fb38c0a
commit 05eb4d701c
14 changed files with 210 additions and 261 deletions

View file

@ -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<PoiUIFilter> 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<PoiUIFilter> 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<ContextMenuItem> 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();
}
}

View file

@ -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);
}

View file

@ -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<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> 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<Boolean>() {
@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<Boolean>() {
@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<Boolean>() {
@ -343,19 +345,20 @@ public class ConfigureMapMenu {
protected void showPoiFilterDialog(final ArrayAdapter<ContextMenuItem> 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();

View file

@ -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,10 @@ public class PoiFiltersHelper {
private PoiUIFilter customPOIFilter;
private PoiUIFilter showAllPOIFilter;
private PoiUIFilter localWikiPoiFilter;
private PoiUIFilter globalWikiPoiFilter;
private PoiUIFilter topWikiPoiFilter;
private List<PoiUIFilter> cacheTopStandardFilters;
private List<PoiUIFilter> cacheWikipediaFilters;
private Map<PoiTemplateList, Set<PoiUIFilter>> selectedPoiFilters = new TreeMap<>();
private Set<PoiUIFilter> selectedPoiFilters = new TreeSet<>();
private boolean updatePoiFiltersOnMap;
private static final String UDF_CAR_AID = "car_aid";
private static final String UDF_FOR_TOURISTS = "for_tourists";
@ -75,10 +75,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 +135,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<String> 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<PoiUIFilter> getLocalWikipediaPoiFilters(boolean onlyActiveLocales) {
String wikiLang = "wiki:lang:";
if (cacheWikipediaFilters == null) {
List<PoiUIFilter> 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<PoiUIFilter> onlyActiveLocalFilters = new ArrayList<>();
Bundle wikiPoiSettings = WikipediaPoiMenu.getWikiPoiSettings(application);
if (wikiPoiSettings != null) {
List<String> 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 +217,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 +284,9 @@ public class PoiFiltersHelper {
List<PoiUIFilter> 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 +486,68 @@ public class PoiFiltersHelper {
return false;
}
public Set<PoiUIFilter> getSelectedPoiFilters() {
Set<PoiUIFilter> result = new TreeSet<>();
for (Set<PoiUIFilter> template : selectedPoiFilters.values()) {
if (template != null) {
result.addAll(template);
public Set<PoiUIFilter> getSelectedPoiFilters(PoiUIFilter ... filtersToExclude) {
if (filtersToExclude != null) {
Set<PoiUIFilter> 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<PoiUIFilter> getSelectedPoiFilters(PoiTemplateList type) {
Set<PoiUIFilter> 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<PoiUIFilter>());
}
Set<PoiUIFilter> 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<PoiUIFilter> 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<PoiUIFilter> 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<PoiUIFilter> templateFilters = selectedPoiFilters.get(type);
if (templateFilters != null) {
templateFilters.clear();
}
saveSelectedPoiFilters();
}
public void hidePoiFilters() {
selectedPoiFilters.clear();
saveSelectedPoiFilters();
}
public String getFiltersName(Set<PoiUIFilter> filters) {
if (filters.isEmpty()) {
return application.getResources().getString(R.string.shared_string_none);
@ -590,23 +560,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<PoiUIFilter> 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<PoiUIFilter> 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;
@ -618,21 +593,16 @@ public class PoiFiltersHelper {
return;
}
selectedPoiFilters.clear();
OsmandSettings settings = application.getSettings();
Set<String> filters = settings.getSelectedPoiFilters();
boolean shouldShowWikiPoi = WikipediaPoiMenu.isWikiPoiEnabled(application);
for (String f : filters) {
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);
}
}
updatePoiFiltersOnMap = true;
}
@Nullable
@ -664,14 +634,22 @@ public class PoiFiltersHelper {
private void saveSelectedPoiFilters() {
Set<String> filters = new HashSet<>();
for (Set<PoiUIFilter> template : selectedPoiFilters.values()) {
for (PoiUIFilter filter : template) {
filters.add(filter.filterId);
}
for (PoiUIFilter filter : selectedPoiFilters) {
filters.add(filter.filterId);
}
application.getSettings().setSelectedPoiFilters(filters);
}
public boolean shouldUpdatePoiFiltersOnMap() {
boolean shouldUpdate = updatePoiFiltersOnMap;
updatePoiFiltersOnMap = false;
return shouldUpdate;
}
public void setUpdatePoiFiltersOnMap(boolean updatePoiFiltersOnMap) {
this.updatePoiFiltersOnMap = updatePoiFiltersOnMap;
}
public class PoiFilterDbHelper {
private static final int TRUE_INT = 1;

View file

@ -150,8 +150,11 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
}
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() {

View file

@ -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<PoiUIFilter> 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<PoiUIFilter> poiFilters = loadPoiFilters(application.getPoiFilters());
return isCurrentFilters(pf.getSelectedPoiFilters(PoiTemplateList.POI), poiFilters);
return isCurrentFilters(pf.getSelectedPoiFilters(), poiFilters);
}
private boolean isCurrentFilters(Set<PoiUIFilter> currentPoiFilters, List<PoiUIFilter> poiFilters) {

View file

@ -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<PoiUIFilter> poiFilters = app.getPoiFilters().getSelectedPoiFilters(PoiTemplateList.POI);
final Set<PoiUIFilter> 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();
}

View file

@ -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);
}
}

View file

@ -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();
}

View file

@ -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();

View file

@ -1525,7 +1525,6 @@ public class OsmandSettings {
public final CommonPreference<Boolean> WIKI_ARTICLE_SHOW_IMAGES_ASKED = new BooleanPreference("wikivoyage_show_images_asked", false).makeGlobal();
public final CommonPreference<WikiArticleShowImages> WIKI_ARTICLE_SHOW_IMAGES = new EnumStringPreference<>("wikivoyage_show_imgs", WikiArticleShowImages.OFF, WikiArticleShowImages.values()).makeGlobal();
public final CommonPreference<Boolean> SHOW_WIKIPEDIA_POI = new BooleanPreference("show_wikipedia_poi", false).makeProfile();
public final CommonPreference<Boolean> 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();

View file

@ -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;
@ -204,8 +205,9 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
Set<PoiUIFilter> selectedPoiFilters = app.getPoiFilters().getSelectedPoiFilters();
if (!this.filters.equals(selectedPoiFilters)) {
PoiFiltersHelper ph = app.getPoiFilters();
Set<PoiUIFilter> selectedPoiFilters = ph.getSelectedPoiFilters();
if (!this.filters.equals(selectedPoiFilters) || ph.shouldUpdatePoiFiltersOnMap()) {
this.filters = new TreeSet<>(selectedPoiFilters);
data.clearCache();
}

View file

@ -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));

View file

@ -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<Boolean> 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,47 @@ public class WikipediaPoiMenu {
}
public static void toggleWikipediaPoi(final MapActivity mapActivity, boolean enable,
boolean usedOnMap, CallbackWithObject<Boolean> callback) {
CallbackWithObject<Boolean> 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);
hideWikipediaFromMap(app);
showWikipediaOnMap(app);
app.getPoiFilters().setUpdatePoiFiltersOnMap(true);
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<PoiUIFilter> filters = ph.getLocalWikipediaPoiFilters(true);
for (PoiUIFilter filter : filters) {
ph.addSelectedPoiFilter(PoiTemplateList.WIKI, filter);
}
}
PoiUIFilter wiki = ph.getTopWikiPoiFilter();
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<String> 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<String> enabledLocales = wikiSetting.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY);
if (!globalWikiEnabled && enabledLocales != null) {
List<String> translations = new ArrayList<>();
for (String locale : enabledLocales) {
translations.add(getTranslation(app, locale));
@ -370,11 +344,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 +355,7 @@ public class WikipediaPoiMenu {
@NonNull Set<String> 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;
}