From 7b268cd9d9d5c9b6262abcd01bb619b85e00e1ac Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Tue, 31 Mar 2020 12:41:49 +0300 Subject: [PATCH 1/3] Add Wikipedia POI separate screen and logic --- .../aidlapi/OsmAndCustomizationConstants.java | 1 + .../main/java/net/osmand/osm/MapPoiTypes.java | 10 + .../bottom_sheet_item_title_with_checkbox.xml | 39 ++ ...ottom_sheet_item_title_with_swith_56dp.xml | 47 +++ .../dash_item_with_description_72dp.xml | 78 ++++ .../layout/list_group_title_with_descr.xml | 21 +- OsmAnd/res/layout/list_item_icon_and_menu.xml | 14 +- OsmAnd/res/values/strings.xml | 5 + OsmAnd/src/net/osmand/AndroidUtils.java | 12 + .../net/osmand/plus/ContextMenuAdapter.java | 2 +- .../src/net/osmand/plus/ContextMenuItem.java | 15 +- .../src/net/osmand/plus/OsmandSettings.java | 55 ++- .../plus/activities/MapActivityLayers.java | 9 +- .../activities/search/SearchPOIActivity.java | 3 +- .../BottomSheetItemWithCompoundButton.java | 4 + .../osmand/plus/dashboard/DashboardOnMap.java | 18 +- .../osmand/plus/dialogs/ConfigureMapMenu.java | 35 +- .../osmand/plus/helpers/WaypointHelper.java | 1 + .../net/osmand/plus/poi/PoiFiltersHelper.java | 156 ++++++-- .../net/osmand/plus/poi/PoiTemplateList.java | 5 + .../src/net/osmand/plus/poi/PoiUIFilter.java | 4 + .../actions/ShowHidePoiAction.java | 11 +- .../MapRouteInfoMenu.java | 5 +- .../ShowAlongTheRouteBottomSheet.java | 6 +- .../search/QuickSearchDialogFragment.java | 7 +- .../osmand/plus/search/QuickSearchHelper.java | 7 +- .../net/osmand/plus/views/POIMapLayer.java | 1 + .../SelectWikiLanguagesBottomSheet.java | 275 ++++++++++++++ .../plus/wikipedia/WikipediaPoiMenu.java | 348 ++++++++++++++++++ 29 files changed, 1103 insertions(+), 91 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_title_with_checkbox.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_item_title_with_swith_56dp.xml create mode 100644 OsmAnd/res/layout/dash_item_with_description_72dp.xml create mode 100644 OsmAnd/src/net/osmand/plus/poi/PoiTemplateList.java create mode 100644 OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java create mode 100644 OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java b/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java index 6657e29bca..6127cabc9c 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java @@ -35,6 +35,7 @@ public interface OsmAndCustomizationConstants { String POI_OVERLAY_LABELS_ID = SHOW_ITEMS_ID_SCHEME + "poi_overlay_labels"; String TRANSPORT_ID = SHOW_ITEMS_ID_SCHEME + "transport"; String GPX_FILES_ID = SHOW_ITEMS_ID_SCHEME + "gpx_files"; + String WIKIPEDIA_ID = SHOW_ITEMS_ID_SCHEME + "wikipedia"; String MAP_MARKERS_ID = SHOW_ITEMS_ID_SCHEME + "map_markers"; String MAP_SOURCE_ID = SHOW_ITEMS_ID_SCHEME + "map_source"; String RECORDING_LAYER = SHOW_ITEMS_ID_SCHEME + "recording_layer"; diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 874759598d..38e914a63d 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -36,6 +36,7 @@ public class MapPoiTypes { private PoiCategory otherCategory; private PoiCategory otherMapCategory; + public static final String WIKI_LANG_KEY_PREFFIX = "wiki_lang:"; static final String OSM_WIKI_CATEGORY = "osmwiki"; private PoiTranslator poiTranslator = null; private boolean init; @@ -127,6 +128,15 @@ public class MapPoiTypes { return lf; } + public PoiCategory getOsmwiki() { + for (PoiCategory category : categories) { + if (category.isWiki()) { + return category; + } + } + return null; + } + private void sortList(List lf) { final Collator instance = Collator.getInstance(); Collections.sort(lf, new Comparator() { diff --git a/OsmAnd/res/layout/bottom_sheet_item_title_with_checkbox.xml b/OsmAnd/res/layout/bottom_sheet_item_title_with_checkbox.xml new file mode 100644 index 0000000000..cede7a0e86 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_title_with_checkbox.xml @@ -0,0 +1,39 @@ + + + + + + + + diff --git a/OsmAnd/res/layout/bottom_sheet_item_title_with_swith_56dp.xml b/OsmAnd/res/layout/bottom_sheet_item_title_with_swith_56dp.xml new file mode 100644 index 0000000000..c347f4b20f --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_title_with_swith_56dp.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/dash_item_with_description_72dp.xml b/OsmAnd/res/layout/dash_item_with_description_72dp.xml new file mode 100644 index 0000000000..768ae56024 --- /dev/null +++ b/OsmAnd/res/layout/dash_item_with_description_72dp.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/list_group_title_with_descr.xml b/OsmAnd/res/layout/list_group_title_with_descr.xml index 5d2e429a58..4c48d7ba5e 100644 --- a/OsmAnd/res/layout/list_group_title_with_descr.xml +++ b/OsmAnd/res/layout/list_group_title_with_descr.xml @@ -21,7 +21,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - android:minHeight="48dp" + android:minHeight="@dimen/setting_list_item_large_height" android:background="?attr/bg_color" android:gravity="center" android:orientation="vertical" @@ -34,9 +34,9 @@ android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingTop="10dp" - android:textColor="?android:textColorPrimary" - android:textSize="@dimen/default_sub_text_size" + android:paddingTop="@dimen/content_padding_small" + android:textColor="@color/preference_category_title" + android:textSize="@dimen/default_desc_text_size" osmand:typeface="@string/font_roboto_medium" tools:text="Download map"/> @@ -44,18 +44,13 @@ android:id="@+id/description" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingTop="4dp" + android:paddingTop="@dimen/content_padding_half" + android:paddingBottom="@dimen/content_padding" android:textColor="?android:textColorSecondary" - android:textSize="@dimen/default_sub_text_size" - android:paddingBottom="10dp" + android:textSize="@dimen/default_desc_text_size" + osmand:typeface="@string/font_roboto_regular" tools:text="For view contour lines on the map, you need to download contour line map of this region."/> - - \ No newline at end of file diff --git a/OsmAnd/res/layout/list_item_icon_and_menu.xml b/OsmAnd/res/layout/list_item_icon_and_menu.xml index 7e08397865..b3ad8c8cbe 100644 --- a/OsmAnd/res/layout/list_item_icon_and_menu.xml +++ b/OsmAnd/res/layout/list_item_icon_and_menu.xml @@ -15,8 +15,8 @@ android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_gravity="center_vertical" - android:layout_marginLeft="16dp" - android:layout_marginStart="16dp" + android:layout_marginLeft="@dimen/content_padding" + android:layout_marginStart="@dimen/content_padding" tools:src="@drawable/ic_action_gabout_dark"/> @@ -81,8 +81,8 @@ android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_gravity="center_vertical" - android:layout_marginEnd="16dp" - android:layout_marginRight="16dp" + android:layout_marginEnd="@dimen/content_padding" + android:layout_marginRight="@dimen/content_padding" android:focusable="false"/> + Additional maps are needed to view Wikipedia POIs on the map. + Some Wikipedia articles may not be available in your name, select the languages in which Wikipedia articles will appear on the map.\nYou will be able to switch between all available languages while reading the article. + All languages + Language + Languages Snowmobile Ski touring Min diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index de35fad5a0..5a9025c088 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -252,6 +252,18 @@ public class AndroidUtils { return ""; } + public static String makeStringFromList(@NonNull List strings, @NonNull String divider) { + if (strings.size() == 0) { + return ""; + } + StringBuilder result = new StringBuilder(strings.get(0)); + for (int i = 1; i < strings.size(); i++) { + result.append(divider); + result.append(strings.get(i)); + } + return result.toString(); + } + public static View findParentViewById(View view, int id) { ViewParent viewParent = view.getParent(); diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index b164989528..e9c934346f 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -404,7 +404,7 @@ public class ContextMenuAdapter { } }; ch.setOnCheckedChangeListener(listener); - ch.setVisibility(View.VISIBLE); + ch.setVisibility(item.shouldHideCompoundButton() ? View.GONE : View.VISIBLE); } else if (ch != null) { ch.setVisibility(View.GONE); } diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java index 0e5b89ab5c..c04acf706a 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java @@ -37,6 +37,7 @@ public class ContextMenuItem { private final ContextMenuAdapter.OnIntegerValueChangedListener integerListener; private final ContextMenuAdapter.ProgressListener progressListener; private final boolean hideDivider; + private final boolean hideCompoundButton; private final int minHeight; private final int tag; private final String id; @@ -60,6 +61,7 @@ public class ContextMenuItem { ContextMenuAdapter.OnIntegerValueChangedListener integerListener, ContextMenuAdapter.ProgressListener progressListener, boolean hideDivider, + boolean hideCompoundButton, int minHeight, int tag, String id) { @@ -82,6 +84,7 @@ public class ContextMenuItem { this.integerListener = integerListener; this.progressListener = progressListener; this.hideDivider = hideDivider; + this.hideCompoundButton = hideCompoundButton; this.minHeight = minHeight; this.tag = tag; this.id = id; @@ -182,6 +185,10 @@ public class ContextMenuItem { return hideDivider; } + public boolean shouldHideCompoundButton() { + return hideCompoundButton; + } + public void setTitle(String title) { this.title = title; } @@ -255,6 +262,7 @@ public class ContextMenuItem { private ContextMenuAdapter.ProgressListener mProgressListener = null; private boolean mSkipPaintingWithoutColor; private boolean mHideDivider; + private boolean mHideCompoundButton; private int mMinHeight; private int mTag; private String mId; @@ -358,6 +366,11 @@ public class ContextMenuItem { return this; } + public ItemBuilder hideCompoundButton(boolean hideCompoundButton) { + mHideCompoundButton = hideCompoundButton; + return this; + } + public ItemBuilder setMinHeight(int minHeight) { this.mMinHeight = minHeight; return this; @@ -381,7 +394,7 @@ public class ContextMenuItem { return new ContextMenuItem(mTitleId, mTitle, mIcon, mColorRes, mSecondaryIcon, mSelected, mProgress, mLayout, mLoading, mIsCategory, mIsClickable, mSkipPaintingWithoutColor, mPosition, mOrder, mDescription, mItemClickListener, mIntegerListener, mProgressListener, - mHideDivider, mMinHeight, mTag, mId); + mHideDivider, mHideCompoundButton, mMinHeight, mTag, mId); } } } diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 85c93e31f4..b5d2cf32a8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1012,42 +1012,58 @@ public class OsmandSettings { super(id, defaultValue); this.delimiter = delimiter; } - + public boolean addValue(String res) { - String vl = get(); + return addModeValue(getApplicationMode(), res); + } + + public boolean addModeValue(ApplicationMode appMode, String res) { + String vl = getModeValue(appMode); if (vl == null || vl.isEmpty()) { vl = res + delimiter; } else { vl = vl + res + delimiter; } - set(vl); + setModeValue(appMode, vl); return true; } - + public void clearAll() { - set(""); + clearAllForProfile(getApplicationMode()); + } + + public void clearAllForProfile(ApplicationMode appMode) { + setModeValue(appMode, ""); } public boolean containsValue(String res) { - String vl = get(); + return containsValue(getApplicationMode(), res); + } + + public boolean containsValue(ApplicationMode appMode, String res) { + String vl = getModeValue(appMode); String r = res + delimiter; - return vl.startsWith(r) || vl.indexOf(delimiter + r) >= 0; + return vl.startsWith(r) || vl.contains(delimiter + r); } public boolean removeValue(String res) { - String vl = get(); + return removeValueForProfile(getApplicationMode(), res); + } + + public boolean removeValueForProfile(ApplicationMode appMode, String res) { + String vl = getModeValue(appMode); String r = res + delimiter; if(vl != null) { if(vl.startsWith(r)) { vl = vl.substring(r.length()); - set(vl); + setModeValue(appMode, vl); return true; } else { int it = vl.indexOf(delimiter + r); if(it >= 0) { vl = vl.substring(0, it + delimiter.length()) + vl.substring(it + delimiter.length() + r.length()); } - set(vl); + setModeValue(appMode, vl); return true; } } @@ -1055,7 +1071,11 @@ public class OsmandSettings { } public List getStringsList() { - final String listAsString = get(); + return getStringsListForProfile(getApplicationMode()); + } + + public List getStringsListForProfile(ApplicationMode appMode) { + final String listAsString = getModeValue(appMode); if (listAsString != null) { if (listAsString.contains(delimiter)) { return Arrays.asList(listAsString.split(delimiter)); @@ -1069,13 +1089,17 @@ public class OsmandSettings { } public void setStringsList(List values) { + setStringsListForProfile(getApplicationMode(), values); + } + + public void setStringsListForProfile(ApplicationMode appMode, List values) { if (values == null || values.size() == 0) { - set(null); + setModeValue(appMode, null); return; } - clearAll(); + clearAllForProfile(appMode); for (String value : values) { - addValue(value); + addModeValue(appMode, value); } } } @@ -1261,6 +1285,9 @@ 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 EnumIntPreference<>("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(); public final CommonPreference SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile(); public final CommonPreference KEEP_PASSED_MARKERS_ON_MAP = new BooleanPreference("keep_passed_markers_on_map", true).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index 84e1afd445..a112d0ed96 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -35,6 +35,7 @@ import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.measurementtool.MeasurementToolLayer; import net.osmand.plus.poi.PoiFiltersHelper; +import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.render.MapVectorLayer; @@ -304,9 +305,9 @@ public class MapActivityLayers { if (filter.isStandardFilter()) { filter.removeUnsavedFilterByName(); } - getApplication().getPoiFilters().addSelectedPoiFilter(filter); + poiFilters.addSelectedPoiFilter(PoiTemplateList.POI, filter); } else { - getApplication().getPoiFilters().removeSelectedPoiFilter(filter); + poiFilters.removeSelectedPoiFilter(PoiTemplateList.POI, filter); } } mapView.refreshMap(); @@ -368,8 +369,8 @@ public class MapActivityLayers { if (pf.isStandardFilter()) { pf.removeUnsavedFilterByName(); } - getApplication().getPoiFilters().clearSelectedPoiFilters(); - getApplication().getPoiFilters().addSelectedPoiFilter(pf); + poiFilters.clearSelectedPoiFilters(PoiTemplateList.POI); + poiFilters.addSelectedPoiFilter(PoiTemplateList.POI, 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 b08b6348eb..cbc165ad99 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -58,6 +58,7 @@ import net.osmand.plus.activities.EditPOIFilterActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmandListActivity; import net.osmand.plus.poi.NominatimPoiFilter; +import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter.AmenityNameFilter; import net.osmand.plus.render.RenderingIcons; @@ -164,7 +165,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(filter); + app.getPoiFilters().addSelectedPoiFilter(PoiTemplateList.POI, filter); if (location != null) { settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15); } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java index 267ff16519..b106b8a2db 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java @@ -78,6 +78,10 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri this.compoundButtonColorId = compoundButtonColorId; } + public CompoundButton getCompoundButton() { + return compoundButton; + } + @Override public void inflate(Context context, ViewGroup container, boolean nightMode) { super.inflate(context, container, nightMode); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 8815bd0e22..243750ecd8 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -84,6 +84,7 @@ import net.osmand.plus.views.DownloadedRegionsLayer; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; +import net.osmand.plus.wikipedia.WikipediaPoiMenu; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -174,6 +175,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo MAPILLARY, CONTOUR_LINES, OSM_NOTES, + WIKIPEDIA, TERRAIN } @@ -321,6 +323,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo tv.setText(R.string.osm_notes); } else if (visibleType == DashboardType.TERRAIN) { tv.setText(R.string.shared_string_terrain); + } else if (visibleType == DashboardType.WIKIPEDIA) { + tv.setText(R.string.shared_string_wikipedia); } ImageView edit = (ImageView) dashboardView.findViewById(R.id.toolbar_edit); edit.setVisibility(View.GONE); @@ -676,7 +680,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo && visibleType != DashboardType.CONFIGURE_MAP && visibleType != DashboardType.CONTOUR_LINES && visibleType != DashboardType.TERRAIN - && visibleType != DashboardType.OSM_NOTES) { + && visibleType != DashboardType.OSM_NOTES + && visibleType != DashboardType.WIKIPEDIA) { listView.setDivider(dividerDrawable); listView.setDividerHeight(AndroidUtils.dpToPx(mapActivity, 1f)); } else { @@ -712,6 +717,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo cm = ContourLinesMenu.createListAdapter(mapActivity); } else if (visibleType == DashboardType.OSM_NOTES) { cm = OsmNotesMenu.createListAdapter(mapActivity); + } else if (visibleType == DashboardType.WIKIPEDIA) { + cm = WikipediaPoiMenu.createListAdapter(mapActivity); } if (cm != null) { updateListAdapter(cm); @@ -730,14 +737,17 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo } public void onNewDownloadIndexes() { - if (visibleType == DashboardType.CONTOUR_LINES || visibleType == DashboardType.TERRAIN) { + if (visibleType == DashboardType.CONTOUR_LINES + || visibleType == DashboardType.TERRAIN + || visibleType == DashboardType.WIKIPEDIA) { refreshContent(true); } } @SuppressWarnings("unchecked") public void onDownloadInProgress() { - if (visibleType == DashboardType.CONTOUR_LINES || visibleType == DashboardType.TERRAIN) { + if (visibleType == DashboardType.CONTOUR_LINES || visibleType == DashboardType.TERRAIN + || visibleType == DashboardType.WIKIPEDIA) { DownloadIndexesThread downloadThread = getMyApplication().getDownloadThread(); IndexItem downloadIndexItem = downloadThread.getCurrentDownloadingItem(); if (downloadIndexItem != null) { @@ -764,6 +774,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo } } SRTMPlugin.refreshMapComplete(mapActivity); + } else if (visibleType == DashboardType.WIKIPEDIA) { + refreshContent(true); } } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 4b991c2b8e..424d936d98 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -47,13 +47,16 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.activities.PluginActivity; 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.PoiTemplateList; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.corenative.NativeCoreContext; +import net.osmand.plus.wikipedia.WikipediaPoiMenu; import net.osmand.render.RenderingRule; import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRuleStorageProperties; @@ -98,6 +101,7 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_CATEGORY_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.TEXT_SIZE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_RENDERING_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID; 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; @@ -195,6 +199,10 @@ public class ConfigureMapMenu { } else if (itemId == R.string.layer_gpx_layer && cm.getItem(pos).getSelected()) { showGpxSelectionDialog(adapter, adapter.getItem(pos)); return false; + } else if (itemId == R.string.shared_string_wikipedia) { + ma.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.WIKIPEDIA, + AndroidUtils.getCenterViewCoordinates(view)); + return false; } else { CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item); if (btn != null && btn.getVisibility() == View.VISIBLE) { @@ -217,11 +225,12 @@ public class ConfigureMapMenu { item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); } if (itemId == R.string.layer_poi) { - poiFiltersHelper.clearSelectedPoiFilters(); + poiFiltersHelper.clearSelectedPoiFilters(PoiTemplateList.POI); if (isChecked) { showPoiFilterDialog(adapter, adapter.getItem(pos)); } else { - adapter.getItem(pos).setDescription(poiFiltersHelper.getSelectedPoiFiltersName()); + adapter.getItem(pos).setDescription( + poiFiltersHelper.getSelectedPoiFiltersName(PoiTemplateList.POI)); } } else if (itemId == R.string.layer_amenity_label) { settings.SHOW_POI_LABEL.set(isChecked); @@ -235,6 +244,8 @@ public class ConfigureMapMenu { } else { showGpxSelectionDialog(adapter, adapter.getItem(pos)); } + } else if (itemId == R.string.shared_string_wikipedia) { + WikipediaPoiMenu.toggleWikipediaPoi(ma, isChecked, true); } else if (itemId == R.string.map_markers) { settings.SHOW_MAP_MARKERS.set(isChecked); } else if (itemId == R.string.layer_map) { @@ -278,14 +289,14 @@ public class ConfigureMapMenu { @Override public void dismiss() { PoiFiltersHelper pf = ma.getMyApplication().getPoiFilters(); - boolean selected = pf.isShowingAnyPoi(); + boolean selected = pf.isShowingAnyPoi(PoiTemplateList.POI); item.setSelected(selected); - item.setDescription(pf.getSelectedPoiFiltersName()); + item.setDescription(pf.getSelectedPoiFiltersName(PoiTemplateList.POI)); item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); adapter.notifyDataSetChanged(); } }; - if (poiFiltersHelper.getSelectedPoiFilters().size() > 1) { + if (poiFiltersHelper.isShowingAnyPoi(PoiTemplateList.POI)) { ma.getMapLayers().showMultichoicePoiFilterDialog(ma.getMapView(), dismissListener); } else { @@ -315,12 +326,12 @@ public class ConfigureMapMenu { .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_action_fav_dark) .setListener(l).createItem()); - selected = app.getPoiFilters().isShowingAnyPoi(); + selected = app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.POI); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(POI_OVERLAY_ID) .setTitleId(R.string.layer_poi, activity) .setSelected(selected) - .setDescription(app.getPoiFilters().getSelectedPoiFiltersName()) + .setDescription(app.getPoiFilters().getSelectedPoiFiltersName(PoiTemplateList.POI)) .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_action_info_dark) .setSecondaryIcon(R.drawable.ic_action_additional_option) @@ -526,6 +537,16 @@ public class ConfigureMapMenu { .setSecondaryIcon(R.drawable.ic_action_additional_option) .setListener(l).createItem()); + selected = settings.SHOW_WIKIPEDIA_POI.get(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setId(WIKIPEDIA_ID) + .setTitleId(R.string.shared_string_wikipedia, activity) + .setSelected(selected) + .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) + .setIcon(R.drawable.ic_plugin_wikipedia) + .setSecondaryIcon(R.drawable.ic_action_additional_option) + .setListener(l).createItem()); + selected = settings.SHOW_MAP_MARKERS.get(); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(MAP_MARKERS_ID) diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 7f51847964..6443915ab3 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -25,6 +25,7 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.IntermediatePointsDialog; import net.osmand.plus.base.FavoriteImageDrawable; +import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.routing.AlarmInfo; diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 9bfc82dfdd..90447f2bf4 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -1,5 +1,7 @@ package net.osmand.plus.poi; +import android.os.Bundle; + import androidx.annotation.NonNull; import net.osmand.osm.AbstractPoiType; @@ -7,10 +9,12 @@ import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteStatement; +import net.osmand.plus.wikipedia.WikipediaPoiMenu; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -22,8 +26,10 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.TreeMap; import java.util.TreeSet; public class PoiFiltersHelper { @@ -37,8 +43,9 @@ public class PoiFiltersHelper { private PoiUIFilter customPOIFilter; private PoiUIFilter showAllPOIFilter; private PoiUIFilter localWikiPoiFilter; + private PoiUIFilter globalWikiPoiFilter; private List cacheTopStandardFilters; - private Set selectedPoiFilters = new TreeSet<>(); + private Map> selectedPoiFilters = new TreeMap<>(); private static final String UDF_CAR_AID = "car_aid"; private static final String UDF_FOR_TOURISTS = "for_tourists"; @@ -115,6 +122,42 @@ public class PoiFiltersHelper { return localWikiPoiFilter; } + public PoiUIFilter getGlobalWikiPoiFilter() { + if (globalWikiPoiFilter == null) { + String wikiFilterId = PoiUIFilter.STD_PREFIX + "osmwiki"; + for (PoiUIFilter filter : getTopDefinedPoiFilters()) { + if (wikiFilterId.equals(filter.getFilterId())) { + globalWikiPoiFilter = filter; + break; + } + } + } + return globalWikiPoiFilter; + } + + public List getWikiPOIFilters() { + List cacheWikipediaFilters = new ArrayList<>(); + List enabledLanguages = null; + Bundle wikiPoiSettings = WikipediaPoiMenu.getWikiPoiSettings(application); + if (wikiPoiSettings != null) { + enabledLanguages = wikiPoiSettings.getStringArrayList(WikipediaPoiMenu.ENABLED_WIKI_POI_LANGUAGES_KEY); + } + if (enabledLanguages != null) { + for (String language : enabledLanguages) { + PoiType place = application.getPoiTypes().getPoiTypeByKey("wiki_place"); + if (place != null) { + String locale = new Locale(language).getLanguage(); + PoiUIFilter filter = new PoiUIFilter(place, application, " " + + application.getLangTranslation(locale)); + filter.setSavedFilterByName("wiki:lang:" + locale); + filter.setStandardFilter(true); + cacheWikipediaFilters.add(filter); + } + } + } + return cacheWikipediaFilters; + } + public PoiUIFilter getShowAllPOIFilter() { if (showAllPOIFilter == null) { PoiUIFilter filter = new PoiUIFilter(null, application, ""); @@ -159,8 +202,13 @@ public class PoiFiltersHelper { return f; } } + for (PoiUIFilter f : getWikiPOIFilters()) { + if (f.getFilterId().equals(filterId)) { + return f; + } + } PoiUIFilter ff = getFilterById(filterId, getCustomPOIFilter(), getSearchByNamePOIFilter(), - getLocalWikiPOIFilter(), getShowAllPOIFilter(), getNominatimPOIFilter(), getNominatimAddressFilter()); + getGlobalWikiPoiFilter(), getShowAllPOIFilter(), getNominatimPOIFilter(), getNominatimAddressFilter()); if (ff != null) { return ff; } @@ -225,9 +273,6 @@ 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()) { @@ -258,7 +303,11 @@ public class PoiFiltersHelper { public List getSortedPoiFilters(boolean onlyActive) { initPoiUIFiltersState(); List allFilters = new ArrayList<>(); - allFilters.addAll(getTopDefinedPoiFilters()); + for (PoiUIFilter filter : getTopDefinedPoiFilters()) { + if (!filter.isWikiFilter()) { + allFilters.add(filter); + } + } allFilters.addAll(getSearchPoiFilters()); Collections.sort(allFilters); if (onlyActive) { @@ -421,28 +470,70 @@ public class PoiFiltersHelper { return false; } - @NonNull public Set getSelectedPoiFilters() { - return selectedPoiFilters; + Set result = new TreeSet<>(); + for (Set template : selectedPoiFilters.values()) { + if (template != null) { + result.addAll(template); + } + } + return result; } - public void addSelectedPoiFilter(PoiUIFilter filter) { - selectedPoiFilters.add(filter); + @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); + } saveSelectedPoiFilters(); } - public void removeSelectedPoiFilter(PoiUIFilter filter) { - selectedPoiFilters.remove(filter); + public void removeSelectedPoiFilter(PoiTemplateList type, PoiUIFilter filter) { + if (selectedPoiFilters.containsKey(type)) { + Set templateFilters = selectedPoiFilters.get(type); + if (templateFilters != null) { + templateFilters.remove(filter); + } + } saveSelectedPoiFilters(); } public boolean isShowingAnyPoi() { - return !selectedPoiFilters.isEmpty(); + for (PoiTemplateList type : selectedPoiFilters.keySet()) { + if (isShowingAnyPoi(type)) { + return true; + } + } + return false; + } + + public boolean isShowingAnyPoi(PoiTemplateList type) { + return !getSelectedPoiFilters(type).isEmpty(); } public void clearSelectedPoiFilters() { - selectedPoiFilters.clear(); - saveSelectedPoiFilters(); + for (PoiTemplateList t : selectedPoiFilters.keySet()) { + clearSelectedPoiFilters(t); + } + } + + public void clearSelectedPoiFilters(PoiTemplateList type) { + Set templateFilters = selectedPoiFilters.get(type); + if (templateFilters != null) { + templateFilters.clear(); + } } public void hidePoiFilters() { @@ -461,18 +552,23 @@ public class PoiFiltersHelper { } } - public String getSelectedPoiFiltersName() { - return getFiltersName(selectedPoiFilters); + public String getSelectedPoiFiltersName(PoiTemplateList type) { + return getFiltersName(getSelectedPoiFilters(type)); } public boolean isPoiFilterSelected(PoiUIFilter filter) { - return selectedPoiFilters.contains(filter); + for (Set template : selectedPoiFilters.values()) { + return template.contains(filter); + } + return false; } public boolean isPoiFilterSelected(String filterId) { - for (PoiUIFilter filter : selectedPoiFilters) { - if (filter.filterId.equals(filterId)) { - return true; + for (Set template : selectedPoiFilters.values()) { + for (PoiUIFilter filter : template) { + if (filter.filterId.equals(filterId)) { + return true; + } } } return false; @@ -480,19 +576,29 @@ public class PoiFiltersHelper { public void loadSelectedPoiFilters() { selectedPoiFilters.clear(); - Set filters = application.getSettings().getSelectedPoiFilters(); + OsmandSettings settings = application.getSettings(); + Set filters = settings.getSelectedPoiFilters(); + boolean shouldShowWikiPoi = WikipediaPoiMenu.isWikiPoiEnabled(application); for (String f : filters) { PoiUIFilter filter = getFilterById(f); if (filter != null) { - selectedPoiFilters.add(filter); + if (filter.isWikiFilter()) { + if (shouldShowWikiPoi) { + addSelectedPoiFilter(PoiTemplateList.WIKI, filter); + } + } else { + addSelectedPoiFilter(PoiTemplateList.POI, filter); + } } } } private void saveSelectedPoiFilters() { Set filters = new HashSet<>(); - for (PoiUIFilter f : selectedPoiFilters) { - filters.add(f.filterId); + for (Set template : selectedPoiFilters.values()) { + for (PoiUIFilter filter : template) { + filters.add(filter.filterId); + } } application.getSettings().setSelectedPoiFilters(filters); } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiTemplateList.java b/OsmAnd/src/net/osmand/plus/poi/PoiTemplateList.java new file mode 100644 index 0000000000..59a790b3ab --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/poi/PoiTemplateList.java @@ -0,0 +1,5 @@ +package net.osmand.plus.poi; + +public enum PoiTemplateList { + POI, WIKI +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index 7efaf867ef..5afdd742cc 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -146,6 +146,10 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable this.deleted = deleted; } + public boolean isWikiFilter() { + return filterId.startsWith(STD_PREFIX + "wiki_place") || filterId.equals(STD_PREFIX + "osmwiki"); + } + public String getFilterByName() { return filterByName; } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java index 2e985e9fd0..8186951771 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java @@ -23,6 +23,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.poi.PoiFiltersHelper; +import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickActionType; @@ -112,18 +113,18 @@ public class ShowHidePoiAction extends QuickAction { PoiFiltersHelper pf = activity.getMyApplication().getPoiFilters(); List poiFilters = loadPoiFilters(activity.getMyApplication().getPoiFilters()); - if (!isCurrentFilters(pf.getSelectedPoiFilters(), poiFilters)) { + if (!isCurrentFilters(pf.getSelectedPoiFilters(PoiTemplateList.POI), poiFilters)) { - pf.clearSelectedPoiFilters(); + pf.clearSelectedPoiFilters(PoiTemplateList.POI); for (PoiUIFilter filter : poiFilters) { if (filter.isStandardFilter()) { filter.removeUnsavedFilterByName(); } - pf.addSelectedPoiFilter(filter); + pf.addSelectedPoiFilter(PoiTemplateList.POI, filter); } - } else pf.clearSelectedPoiFilters(); + } else pf.clearSelectedPoiFilters(PoiTemplateList.POI); activity.getMapLayers().updateLayers(activity.getMapView()); } @@ -133,7 +134,7 @@ public class ShowHidePoiAction extends QuickAction { PoiFiltersHelper pf = application.getPoiFilters(); List poiFilters = loadPoiFilters(application.getPoiFilters()); - return isCurrentFilters(pf.getSelectedPoiFilters(), poiFilters); + return isCurrentFilters(pf.getSelectedPoiFilters(PoiTemplateList.POI), 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 754c1ee4b0..81f0f6a3d0 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -70,6 +70,7 @@ import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; +import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment; import net.osmand.plus.profiles.ConfigureAppModesBottomSheetDialogFragment; @@ -1149,7 +1150,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(); + final Set poiFilters = app.getPoiFilters().getSelectedPoiFilters(PoiTemplateList.POI); final boolean traffic = app.getSettings().SHOW_TRAFFIC_WARNINGS.getModeValue(applicationMode); final boolean fav = app.getSettings().SHOW_NEARBY_FAVORITES.getModeValue(applicationMode); if (!poiFilters.isEmpty()) { @@ -1175,7 +1176,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener public void onClick(View v) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - mapActivity.getMyApplication().getPoiFilters().removeSelectedPoiFilter(poiUIFilter); + mapActivity.getMyApplication().getPoiFilters().removeSelectedPoiFilter(PoiTemplateList.POI, 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 2e181db52a..466d18cd40 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java @@ -36,6 +36,7 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.SimpleDividerItem; import net.osmand.plus.helpers.WaypointDialogHelper; import net.osmand.plus.helpers.WaypointHelper; +import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.routing.IRouteInformationListener; import net.osmand.plus.routing.IRoutingDataUpdateListener; @@ -433,7 +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() ? getString(R.string.poi) : app.getPoiFilters().getSelectedPoiFiltersName(); + String descEx = !app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.POI) ? + getString(R.string.poi) : app.getPoiFilters().getSelectedPoiFiltersName(PoiTemplateList.POI); ((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); @@ -483,7 +485,7 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment new MapActivityLayers.DismissListener() { @Override public void dismiss() { - if (app.getPoiFilters().isShowingAnyPoi()) { + if (app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.POI)) { enableType(type, enable); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 9d25e244cd..91cd25a83d 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -79,6 +79,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; +import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.RearrangePoiFiltersFragment; import net.osmand.plus.resources.RegionAddressRepository; @@ -383,8 +384,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } else { filter = (PoiUIFilter) searchPhrase.getLastSelectedWord().getResult().object; } - app.getPoiFilters().clearSelectedPoiFilters(); - app.getPoiFilters().addSelectedPoiFilter(filter); + app.getPoiFilters().clearSelectedPoiFilters(PoiTemplateList.POI); + app.getPoiFilters().addSelectedPoiFilter(PoiTemplateList.POI, filter); mapActivity.getContextMenu().closeActiveToolbar(); showToolbar(); @@ -861,7 +862,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } public void closeSearch() { - app.getPoiFilters().clearSelectedPoiFilters(); + app.getPoiFilters().clearSelectedPoiFilters(PoiTemplateList.POI); dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index fd13f09dc1..93b4c3127a 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -27,6 +27,7 @@ import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.poi.NominatimPoiFilter; import net.osmand.plus.poi.PoiFiltersHelper; +import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.resources.ResourceManager.ResourceListener; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -502,8 +503,8 @@ public class QuickSearchHelper implements ResourceListener { }); controller.setTitle(filter.getName()); PoiFiltersHelper helper = mapActivity.getMyApplication().getPoiFilters(); - helper.clearSelectedPoiFilters(); - helper.addSelectedPoiFilter(filter); + helper.clearSelectedPoiFilters(PoiTemplateList.POI); + helper.addSelectedPoiFilter(PoiTemplateList.POI, filter); mapActivity.showTopToolbar(controller); mapActivity.refreshMap(); } @@ -512,7 +513,7 @@ public class QuickSearchHelper implements ResourceListener { @NonNull TopToolbarController controller, @Nullable Runnable action) { mapActivity.hideTopToolbar(controller); - mapActivity.getMyApplication().getPoiFilters().clearSelectedPoiFilters(); + mapActivity.getMyApplication().getPoiFilters().clearSelectedPoiFilters(PoiTemplateList.POI); mapActivity.refreshMap(); if (action != null) { action.run(); diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index ebb3efa034..ba7a9eee85 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.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.routing.IRouteInformationListener; diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java new file mode 100644 index 0000000000..474cac110c --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java @@ -0,0 +1,275 @@ +package net.osmand.plus.wikipedia; + +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.view.View; +import android.widget.CompoundButton; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; + +import net.osmand.AndroidUtils; +import net.osmand.CallbackWithObject; +import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; +import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +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 SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragment { + + public static final String TAG = SelectWikiLanguagesBottomSheet.class.getSimpleName(); + + private OsmandApplication app; + private ApplicationMode appMode; + private OsmandSettings settings; + + private List languageItems; + + private ArrayList languages; + private CallbackWithObject languageChangedCallback; + private boolean isGlobalWikiPoiEnabled = false; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + app = requiredMyApplication(); + settings = app.getSettings(); + initLanguagesData(); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + setLanguageListEnable(!isGlobalWikiPoiEnabled); + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + + boolean nightMode = isNightMode(app); + final int activeColorResId = AndroidUtils.resolveAttribute(app, R.attr.active_color_basic); + final int profileColorResId = appMode.getIconColorInfo().getColor(nightMode); + + final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); + final int paddingHalf = app.getResources().getDimensionPixelSize(R.dimen.content_padding_half); + + items.add(new TitleItem(getString(R.string.shared_string_languages))); + items.add(new LongDescriptionItem(getString(R.string.wikipedia_poi_languages_promo))); + items.add(new DividerSpaceItem(app, paddingSmall)); + + final BottomSheetItemWithCompoundButton[] btnSelectAll = new BottomSheetItemWithCompoundButton[1]; + btnSelectAll[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() + .setChecked(this.isGlobalWikiPoiEnabled) + .setCompoundButtonColorId(profileColorResId) + .setTitle(getString(R.string.shared_string_all_languages)) + .setTitleColorId(activeColorResId) + .setCustomView(getCustomButtonView()) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + isGlobalWikiPoiEnabled = !isGlobalWikiPoiEnabled; + btnSelectAll[0].setChecked(isGlobalWikiPoiEnabled); + setLanguageListEnable(!isGlobalWikiPoiEnabled); + } + }) + .create(); + items.add(btnSelectAll[0]); + items.add(new DividerSpaceItem(app, paddingHalf)); + + languageItems = new ArrayList<>(); + for (final WikiLanguageItem language : languages) { + final BottomSheetItemWithCompoundButton[] languageItem = new BottomSheetItemWithCompoundButton[1]; + languageItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() + .setChecked(language.isChecked()) + .setTitle(language.getTitle()) + .setLayoutId(R.layout.bottom_sheet_item_title_with_checkbox) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + boolean newValue = !languageItem[0].isChecked(); + language.setChecked(newValue); + } + }) + .create(); + languageItems.add(languageItem[0]); + language.setOnCheckLanguageCallback(new CallbackWithObject() { + @Override + public boolean processResult(Boolean result) { + languageItem[0].setChecked(result); + return true; + } + }); + } + items.addAll(languageItems); + } + + private void initLanguagesData() { + languages = new ArrayList<>(); + + Bundle wikiPoiSettings = WikipediaPoiMenu.getWikiPoiSettings(app); + List activatedLocales = null; + if (wikiPoiSettings != null) { + isGlobalWikiPoiEnabled = wikiPoiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); + activatedLocales = wikiPoiSettings.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY); + } + + PoiCategory osmwiki = app.getPoiTypes().getOsmwiki(); + if (activatedLocales != null) { + for (PoiType type : osmwiki.getPoiTypeByKeyName("wiki_place").getPoiAdditionals()) { + String name = type.getKeyName(); + if (name != null && name.startsWith(MapPoiTypes.WIKI_LANG_KEY_PREFFIX)) { + String locale = name.substring(MapPoiTypes.WIKI_LANG_KEY_PREFFIX.length()); + boolean checked = activatedLocales.contains(locale); + languages.add(new WikiLanguageItem(locale, app.getLangTranslation(locale), checked)); + } + } + } else { + for (PoiType type : osmwiki.getPoiTypeByKeyName("wiki_place").getPoiAdditionals()) { + String name = type.getKeyName(); + if (name != null && name.startsWith(MapPoiTypes.WIKI_LANG_KEY_PREFFIX)) { + String locale = name.substring(MapPoiTypes.WIKI_LANG_KEY_PREFFIX.length()); + languages.add(new WikiLanguageItem(locale, app.getLangTranslation(locale), false)); + } + } + } + + Collections.sort(languages); + } + + private void setLanguageListEnable(boolean enable) { + int textColorPrimaryId = nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light; + int disableColorId = nightMode ? R.color.active_buttons_and_links_text_disabled_dark : R.color.active_buttons_and_links_text_disabled_light; + int profileColorId = appMode.getIconColorInfo().getColor(nightMode); + for (BottomSheetItemWithCompoundButton item : languageItems) { + item.getView().setEnabled(enable); + item.setTitleColorId(enable ? textColorPrimaryId : disableColorId); + CompoundButton cb = item.getCompoundButton(); + if (cb != null) { + cb.setEnabled(enable); + UiUtilities.setupCompoundButton(nightMode, ContextCompat.getColor(app, enable ? profileColorId : disableColorId), cb); + } + } + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_apply; + } + + @Override + protected void onRightBottomButtonClick() { + super.onRightBottomButtonClick(); + List localesForSaving = new ArrayList<>(); + for (WikiLanguageItem language : languages) { + if (language.isChecked()) { + localesForSaving.add(language.getLocale()); + } + } + settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.setStringsListForProfile(appMode, localesForSaving); + settings.GLOBAL_WIKIPEDIA_POI_ENABLED.setModeValue(appMode, isGlobalWikiPoiEnabled); + if (languageChangedCallback != null) { + languageChangedCallback.processResult(true); + } + dismiss(); + } + + private View getCustomButtonView() { + OsmandApplication app = getMyApplication(); + if (app == null) { + return null; + } + View buttonView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_title_with_swith_56dp, null); + CompoundButton cb = buttonView.findViewById(R.id.compound_button); + + int color = AndroidUtils.getColorFromAttr(app, R.attr.divider_color_basic); + int bgColor = UiUtilities.getColorWithAlpha(color, 0.5f); + + int bgResId = R.drawable.rectangle_rounded_right; + Drawable bgDrawable = app.getUIUtilities().getPaintedIcon(bgResId, bgColor); + AndroidUtils.setBackground(buttonView, bgDrawable); + + int selectedModeColorId = appMode.getIconColorInfo().getColor(nightMode); + UiUtilities.setupCompoundButton(nightMode, selectedModeColorId, cb); + + return buttonView; + } + + public void setAppMode(ApplicationMode appMode) { + this.appMode = appMode; + } + + public void setLanguageChangedCallback(CallbackWithObject languageChangedCallback) { + this.languageChangedCallback = languageChangedCallback; + } + + private class WikiLanguageItem implements Comparable { + private String locale; + private String title; + private boolean checked; + private CallbackWithObject onCheckLanguageCallback; + + public WikiLanguageItem(String locale, String title, boolean checked) { + this.locale = locale; + this.title = title; + this.checked = checked; + } + + public String getLocale() { + return locale; + } + + public boolean isChecked() { + return checked; + } + + public void setChecked(boolean checked) { + this.checked = checked; + if (onCheckLanguageCallback != null) { + onCheckLanguageCallback.processResult(checked); + } + } + + public void setOnCheckLanguageCallback(CallbackWithObject onCheckLanguageCallback) { + this.onCheckLanguageCallback = onCheckLanguageCallback; + } + + public String getTitle() { + return title; + } + + + @Override + public int compareTo(WikiLanguageItem other) { + return this.title.compareToIgnoreCase(other.title); + } + } + + public static void showInstance(@NonNull MapActivity mapActivity, + @NonNull ApplicationMode appMode, + boolean usedOnMap, + CallbackWithObject callback) { + SelectWikiLanguagesBottomSheet fragment = new SelectWikiLanguagesBottomSheet(); + fragment.setAppMode(appMode); + fragment.setUsedOnMap(usedOnMap); + fragment.setLanguageChangedCallback(callback); + fragment.show(mapActivity.getSupportFragmentManager(), SelectWikiLanguagesBottomSheet.TAG); + } +} diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java new file mode 100644 index 0000000000..58df48ee63 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java @@ -0,0 +1,348 @@ +package net.osmand.plus.wikipedia; + +import android.os.Bundle; +import android.view.View; +import android.widget.ArrayAdapter; + +import androidx.annotation.NonNull; + +import net.osmand.AndroidUtils; +import net.osmand.CallbackWithObject; +import net.osmand.plus.ApplicationMode; +import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.ContextMenuItem; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.download.DownloadActivityType; +import net.osmand.plus.download.DownloadIndexesThread; +import net.osmand.plus.download.DownloadResources; +import net.osmand.plus.download.DownloadValidationManager; +import net.osmand.plus.download.IndexItem; +import net.osmand.plus.poi.PoiFiltersHelper; +import net.osmand.plus.poi.PoiTemplateList; +import net.osmand.plus.poi.PoiUIFilter; +import net.osmand.util.Algorithms; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class WikipediaPoiMenu { + + public static final String GLOBAL_WIKI_POI_ENABLED_KEY = "global_wikipedia_poi_enabled_key"; + public static final String ENABLED_WIKI_POI_LANGUAGES_KEY = "enabled_wikipedia_poi_languages_key"; + + private MapActivity mapActivity; + private OsmandApplication app; + private OsmandSettings settings; + private ApplicationMode appMode; + private boolean nightMode; + + public WikipediaPoiMenu(MapActivity mapActivity) { + this.mapActivity = mapActivity; + this.app = mapActivity.getMyApplication(); + this.settings = app.getSettings(); + this.appMode = settings.getApplicationMode(); + this.nightMode = app.getDaynightHelper().isNightModeForMapControls(); + } + + private ContextMenuAdapter createLayersItems() { + final int toggleActionStringId = R.string.shared_string_wikipedia; + final int languageActionStringId = R.string.shared_string_language; + ContextMenuAdapter adapter = new ContextMenuAdapter(); + adapter.setDefaultLayoutId(R.layout.dash_item_with_description_72dp); + adapter.setProfileDependent(true); + adapter.setNightMode(nightMode); + + ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() { + + @Override + public boolean onRowItemClick(ArrayAdapter adapter, + View view, int itemId, int pos) { + return super.onRowItemClick(adapter, view, itemId, pos); + } + + @Override + public boolean onContextMenuClick(final ArrayAdapter adapter, + final int itemId, final int position, final boolean isChecked, int[] viewCoordinates) { + if (itemId == toggleActionStringId) { + app.runInUIThread(new Runnable() { + @Override + public void run() { + toggleWikipediaPoi(mapActivity, !settings.SHOW_WIKIPEDIA_POI.getModeValue(appMode), true); + } + }); + } else if (itemId == languageActionStringId) { + showLanguagesDialog(mapActivity, appMode, true, true); + } + return false; + } + }; + + int toggleIconId = R.drawable.ic_plugin_wikipedia; + int toggleIconColorId; + boolean enabled = settings.SHOW_WIKIPEDIA_POI.getModeValue(appMode); + if (enabled) { + toggleIconColorId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; + } else { + toggleIconColorId = ContextMenuItem.INVALID_ID; + } + String summary = mapActivity.getString(enabled ? R.string.shared_string_enabled : R.string.shared_string_disabled); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(toggleActionStringId, mapActivity) + .setDescription(summary) + .setIcon(toggleIconId) + .setColor(toggleIconColorId) + .setListener(l) + .setSelected(enabled).createItem()); + + if (enabled) { + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setLayout(R.layout.list_item_divider) + .createItem()); + + summary = getLanguagesSummary(app); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(languageActionStringId, mapActivity) + .setIcon(R.drawable.ic_action_map_language) + .setDescription(summary) + .hideCompoundButton(true) + .setListener(l) + .createItem()); + } + + final DownloadIndexesThread downloadThread = app.getDownloadThread(); + if (!downloadThread.getIndexes().isDownloadedFromInternet) { + if (settings.isInternetConnectionAvailable()) { + downloadThread.runReloadIndexFiles(); + } + } + final boolean downloadIndexes = settings.isInternetConnectionAvailable() + && !downloadThread.getIndexes().isDownloadedFromInternet + && !downloadThread.getIndexes().downloadFromInternetFailed; + + if (downloadIndexes) { + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.shared_string_download_map, mapActivity) + .setDescription(app.getString(R.string.wiki_menu_download_descr)) + .setCategory(true) + .setLayout(R.layout.list_group_title_with_descr).createItem()); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setLayout(R.layout.list_item_icon_and_download) + .setTitleId(R.string.downloading_list_indexes, mapActivity) + .setLoading(true) + .setListener(l).createItem()); + } else { + try { + IndexItem currentDownloadingItem = downloadThread.getCurrentDownloadingItem(); + int currentDownloadingProgress = downloadThread.getCurrentDownloadingItemProgress(); + List wikiIndexes = DownloadResources.findIndexItemsAt( + app, mapActivity.getMapLocation(), DownloadActivityType.WIKIPEDIA_FILE); + if (wikiIndexes.size() > 0) { + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.shared_string_download_map, mapActivity) + .setDescription(app.getString(R.string.wiki_menu_download_descr)) + .setCategory(true) + .setLayout(R.layout.list_group_title_with_descr).createItem()); + for (final IndexItem indexItem : wikiIndexes) { + ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder() + .setLayout(R.layout.list_item_icon_and_download) + .setTitle(indexItem.getVisibleName(app, app.getRegions(), false)) + .setDescription(DownloadActivityType.WIKIPEDIA_FILE.getString(app) + " • " + indexItem.getSizeDescription(app)) + .setIcon(DownloadActivityType.WIKIPEDIA_FILE.getIconResource()) + .setListener(new ContextMenuAdapter.ItemClickListener() { + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) { + ContextMenuItem item = adapter.getItem(position); + if (downloadThread.isDownloading(indexItem)) { + downloadThread.cancelDownload(indexItem); + if (item != null) { + item.setProgress(ContextMenuItem.INVALID_ID); + item.setLoading(false); + item.setSecondaryIcon(R.drawable.ic_action_import); + adapter.notifyDataSetChanged(); + } + } else { + new DownloadValidationManager(app).startDownload(mapActivity, indexItem); + if (item != null) { + item.setProgress(ContextMenuItem.INVALID_ID); + item.setLoading(true); + item.setSecondaryIcon(R.drawable.ic_action_remove_dark); + adapter.notifyDataSetChanged(); + } + } + return false; + } + }) + .setProgressListener(new ContextMenuAdapter.ProgressListener() { + @Override + public boolean onProgressChanged(Object progressObject, int progress, + ArrayAdapter adapter, + int itemId, int position) { + if (progressObject != null && progressObject instanceof IndexItem) { + IndexItem progressItem = (IndexItem) progressObject; + if (indexItem.compareTo(progressItem) == 0) { + ContextMenuItem item = adapter.getItem(position); + if (item != null) { + item.setProgress(progress); + item.setLoading(true); + item.setSecondaryIcon(R.drawable.ic_action_remove_dark); + adapter.notifyDataSetChanged(); + } + return true; + } + } + return false; + } + }); + + if (indexItem == currentDownloadingItem) { + itemBuilder.setLoading(true) + .setProgress(currentDownloadingProgress) + .setSecondaryIcon(R.drawable.ic_action_remove_dark); + } else { + itemBuilder.setSecondaryIcon(R.drawable.ic_action_import); + } + adapter.addItem(itemBuilder.createItem()); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return adapter; + } + + private static void showLanguagesDialog(@NonNull final MapActivity mapActivity, + @NonNull final ApplicationMode appMode, + final boolean usedOnMap, + final boolean refresh) { + final OsmandApplication app = mapActivity.getMyApplication(); + SelectWikiLanguagesBottomSheet.showInstance(mapActivity, appMode, usedOnMap, + new CallbackWithObject() { + @Override + public boolean processResult(Boolean result) { + if (result) { + Bundle wikiPoiSetting = getWikiPoiSettingsForProfile(app, appMode); + if (wikiPoiSetting != null) { + if (refresh) { + refreshWikiPoi(mapActivity, wikiPoiSetting); + } else { + toggleWikipediaPoi(mapActivity, true, usedOnMap); + } + } else { + toggleWikipediaPoi(mapActivity, false, usedOnMap); + } + } + return true; + } + }); + } + + public static Bundle getWikiPoiSettings(OsmandApplication app) { + Bundle wikiSettings = getWikiPoiSettingsForProfile(app, app.getSettings().getApplicationMode()); + if (wikiSettings == null) { + wikiSettings = getWikiPoiSettingsForProfile(app, app.getSettings().DEFAULT_APPLICATION_MODE.get()); + } + return wikiSettings; + } + + private static Bundle getWikiPoiSettingsForProfile(OsmandApplication app, ApplicationMode appMode) { + OsmandSettings settings = app.getSettings(); + boolean globalWikiPoiEnabled = settings.GLOBAL_WIKIPEDIA_POI_ENABLED.getModeValue(appMode); + List enabledWikiPoiLanguages = settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getStringsListForProfile(appMode); + if (!globalWikiPoiEnabled && Algorithms.isEmpty(enabledWikiPoiLanguages)) { + return null; + } + Bundle bundle = new Bundle(); + bundle.putBoolean(GLOBAL_WIKI_POI_ENABLED_KEY, globalWikiPoiEnabled); + if (enabledWikiPoiLanguages != null) { + bundle.putStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY, + new ArrayList<>(enabledWikiPoiLanguages)); + } + return bundle; + } + + public static void toggleWikipediaPoi(final MapActivity mapActivity, boolean enable, boolean usedOnMap) { + OsmandApplication app = mapActivity.getMyApplication(); + OsmandSettings settings = app.getSettings(); + if (enable) { + Bundle wikiPoiSettings = getWikiPoiSettings(app); + if (wikiPoiSettings != null) { + settings.SHOW_WIKIPEDIA_POI.set(true); + showWikiOnMap(app, wikiPoiSettings); + } else { + ApplicationMode appMode = settings.getApplicationMode(); + showLanguagesDialog(mapActivity, appMode, usedOnMap, false); + } + } else { + settings.SHOW_WIKIPEDIA_POI.set(false); + hideWikiFromMap(app); + } + mapActivity.getDashboard().refreshContent(true); + mapActivity.refreshMap(); + } + + public static void refreshWikiPoi(MapActivity mapActivity, @NonNull Bundle wikiPoiSettings) { + OsmandApplication app = mapActivity.getMyApplication(); + hideWikiFromMap(app); + showWikiOnMap(app, wikiPoiSettings); + mapActivity.getDashboard().refreshContent(true); + mapActivity.refreshMap(); + } + + private static void showWikiOnMap(OsmandApplication app, Bundle wikiPoiSettings) { + PoiFiltersHelper ph = app.getPoiFilters(); + boolean globalWikiEnabled = wikiPoiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); + if (globalWikiEnabled) { + ph.addSelectedPoiFilter(PoiTemplateList.WIKI, ph.getGlobalWikiPoiFilter()); + } else { + List filters = ph.getWikiPOIFilters(); + for (PoiUIFilter filter : filters) { + ph.addSelectedPoiFilter(PoiTemplateList.WIKI, filter); + } + } + } + + private static void hideWikiFromMap(OsmandApplication app) { + PoiFiltersHelper ph = app.getPoiFilters(); + for (PoiUIFilter filter : ph.getSelectedPoiFilters(PoiTemplateList.WIKI)) { + ph.removePoiFilter(filter); + } + ph.clearSelectedPoiFilters(PoiTemplateList.WIKI); + } + + private static String getLanguagesSummary(OsmandApplication app) { + Bundle wikiLanguagesSetting = getWikiPoiSettings(app); + if (wikiLanguagesSetting != null) { + boolean globalWikiEnabled = wikiLanguagesSetting.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); + List enabledLanguages = wikiLanguagesSetting.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY); + if (globalWikiEnabled) { + return app.getString(R.string.shared_string_all_languages); + } else if (enabledLanguages != null) { + List translations = new ArrayList<>(); + for (String language : enabledLanguages) { + translations.add(app.getLangTranslation(language)); + } + return AndroidUtils.makeStringFromList(translations, ", "); + } + } + return null; + } + + public static boolean isWikiPoiEnabled(OsmandApplication app) { + OsmandSettings settings = app.getSettings(); + boolean shouldShowWiki = settings.SHOW_WIKIPEDIA_POI.get(); + if (shouldShowWiki && getWikiPoiSettings(app) == null) { + settings.SHOW_WIKIPEDIA_POI.set(false); + shouldShowWiki = false; + } + return shouldShowWiki; + } + + public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) { + return new WikipediaPoiMenu(mapActivity).createLayersItems(); + } +} From 3d3da9ee8efcd3318913fc9be0a303c88f227ae9 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Wed, 8 Apr 2020 12:15:20 +0300 Subject: [PATCH 2/3] Wikipedia Poi (Fixes 1) --- .../main/java/net/osmand/osm/MapPoiTypes.java | 29 +++++-- .../dash_item_with_description_72dp.xml | 4 +- OsmAnd/res/values-large/sizes.xml | 1 + OsmAnd/res/values/sizes.xml | 1 + OsmAnd/src/net/osmand/AndroidUtils.java | 12 --- .../src/net/osmand/plus/OsmandSettings.java | 2 +- .../plus/activities/MapActivityLayers.java | 3 +- .../activities/search/SearchPOIActivity.java | 3 +- .../osmand/plus/dialogs/ConfigureMapMenu.java | 10 +-- .../osmand/plus/helpers/WaypointHelper.java | 1 - .../net/osmand/plus/poi/PoiFiltersHelper.java | 54 ++++++++---- .../net/osmand/plus/poi/PoiTemplateList.java | 5 -- .../src/net/osmand/plus/poi/PoiUIFilter.java | 6 +- .../actions/ShowHidePoiAction.java | 3 +- .../MapRouteInfoMenu.java | 3 +- .../ShowAlongTheRouteBottomSheet.java | 3 +- .../search/QuickSearchDialogFragment.java | 2 +- .../osmand/plus/search/QuickSearchHelper.java | 3 +- .../net/osmand/plus/views/POIMapLayer.java | 1 - .../SelectWikiLanguagesBottomSheet.java | 49 +++-------- .../plus/wikipedia/WikipediaPoiMenu.java | 86 ++++++++++++------- 21 files changed, 155 insertions(+), 126 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/poi/PoiTemplateList.java diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 38e914a63d..0edd44aa6e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -36,8 +36,10 @@ public class MapPoiTypes { private PoiCategory otherCategory; private PoiCategory otherMapCategory; - public static final String WIKI_LANG_KEY_PREFFIX = "wiki_lang:"; - static final String OSM_WIKI_CATEGORY = "osmwiki"; + public static final String WIKI_LANG = "wiki_lang"; + public static final String WIKI_PLACE = "wiki_place"; + public static final String OSM_WIKI_CATEGORY = "osmwiki"; + private PoiTranslator poiTranslator = null; private boolean init; Map poiTypesByTag = new LinkedHashMap(); @@ -137,6 +139,19 @@ public class MapPoiTypes { return null; } + public List getAllAvailableWikiLocales() { + List availableWikiLocales = new ArrayList<>(); + for (PoiType type : getOsmwiki().getPoiTypeByKeyName(WIKI_PLACE).getPoiAdditionals()) { + String name = type.getKeyName(); + String wikiLang = WIKI_LANG + ":"; + if (name != null && name.startsWith(wikiLang)) { + String locale = name.substring(wikiLang.length()); + availableWikiLocales.add(locale); + } + } + return availableWikiLocales; + } + private void sortList(List lf) { final Collator instance = Collator.getInstance(); Collections.sort(lf, new Comparator() { @@ -411,7 +426,7 @@ public class MapPoiTypes { } else if (name.equals("poi_type")) { if (lastCategory == null) { lastCategory = getOtherMapCategory(); - } + } if(!Algorithms.isEmpty(parser.getAttributeValue("", "deprecated_of"))){ String vl = parser.getAttributeValue("", "name"); String target = parser.getAttributeValue("", "deprecated_of"); @@ -605,7 +620,7 @@ public class MapPoiTypes { tp.setOsmValue(parser.getAttributeValue("", "value")); tp.setOsmEditTagValue(parser.getAttributeValue("", "edit_tag"), parser.getAttributeValue("", "edit_value")); - + tp.setOsmTag2(parser.getAttributeValue("", "tag2")); tp.setOsmValue2(parser.getAttributeValue("", "value2")); tp.setText("text".equals(parser.getAttributeValue("", "type"))); @@ -816,7 +831,7 @@ public class MapPoiTypes { poiTypesByTag.put(key, p); } } - + public String replaceDeprecatedSubtype(PoiCategory type, String subtype) { if(deprecatedTags.containsKey(subtype)) { return deprecatedTags.get(subtype); @@ -902,9 +917,9 @@ public class MapPoiTypes { } - - + + } diff --git a/OsmAnd/res/layout/dash_item_with_description_72dp.xml b/OsmAnd/res/layout/dash_item_with_description_72dp.xml index 768ae56024..cf4bdf9f36 100644 --- a/OsmAnd/res/layout/dash_item_with_description_72dp.xml +++ b/OsmAnd/res/layout/dash_item_with_description_72dp.xml @@ -36,7 +36,9 @@ android:paddingLeft="@dimen/content_padding" android:paddingRight="@dimen/content_padding" android:paddingStart="@dimen/content_padding" - android:paddingEnd="@dimen/content_padding"> + android:paddingEnd="@dimen/content_padding" + android:paddingTop="@dimen/content_padding" + android:paddingBottom="@dimen/content_padding"> 84dp 15dp 84dp + 192dp 354dp 102dp diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 57f4331982..4b6eb58c81 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -258,6 +258,7 @@ 10dp 56dp 1.25 + 128dp 236dp 68dp diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 5a9025c088..de35fad5a0 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -252,18 +252,6 @@ public class AndroidUtils { return ""; } - public static String makeStringFromList(@NonNull List strings, @NonNull String divider) { - if (strings.size() == 0) { - return ""; - } - StringBuilder result = new StringBuilder(strings.get(0)); - for (int i = 1; i < strings.size(); i++) { - result.append(divider); - result.append(strings.get(i)); - } - return result.toString(); - } - public static View findParentViewById(View view, int id) { ViewParent viewParent = view.getParent(); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index b5d2cf32a8..287b235e31 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1287,7 +1287,7 @@ public class OsmandSettings { public final CommonPreference WIKI_ARTICLE_SHOW_IMAGES = new EnumIntPreference<>("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(); + public final ListStringPreference WIKIPEDIA_POI_ENABLED_LANGUAGES = (ListStringPreference) new ListStringPreference("wikipedia_poi_enabled_languages", null, ",").makeProfile().cache(); public final CommonPreference SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile(); public final CommonPreference KEEP_PASSED_MARKERS_ON_MAP = new BooleanPreference("keep_passed_markers_on_map", true).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index a112d0ed96..e516f997be 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -35,7 +35,6 @@ import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.measurementtool.MeasurementToolLayer; import net.osmand.plus.poi.PoiFiltersHelper; -import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.render.MapVectorLayer; @@ -66,6 +65,8 @@ 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 */ diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index cbc165ad99..819600f085 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -58,7 +58,6 @@ import net.osmand.plus.activities.EditPOIFilterActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmandListActivity; import net.osmand.plus.poi.NominatimPoiFilter; -import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter.AmenityNameFilter; import net.osmand.plus.render.RenderingIcons; @@ -79,6 +78,8 @@ import java.util.TreeMap; import gnu.trove.set.hash.TLongHashSet; +import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; + /** * Search poi activity */ diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 424d936d98..d036379d6d 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -50,7 +50,6 @@ 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.PoiTemplateList; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.srtmplugin.SRTMPlugin; @@ -102,6 +101,7 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.TEXT_SIZE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_RENDERING_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID; +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; @@ -306,7 +306,7 @@ public class ConfigureMapMenu { } } - private void createLayersItems(List customRules, ContextMenuAdapter adapter, + private void createLayersItems(List customRules, ContextMenuAdapter adapter, final MapActivity activity, final int themeRes, final boolean nightMode) { final OsmandApplication app = activity.getMyApplication(); final OsmandSettings settings = app.getSettings(); @@ -537,7 +537,7 @@ public class ConfigureMapMenu { .setSecondaryIcon(R.drawable.ic_action_additional_option) .setListener(l).createItem()); - selected = settings.SHOW_WIKIPEDIA_POI.get(); + selected = app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.WIKI); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(WIKIPEDIA_ID) .setTitleId(R.string.shared_string_wikipedia, activity) @@ -588,7 +588,7 @@ public class ConfigureMapMenu { final OsmandSettings settings = app.getSettings(); final int selectedProfileColorRes = settings.APPLICATION_MODE.get().getIconColorInfo().getColor(nightMode); final int selectedProfileColor = ContextCompat.getColor(app, selectedProfileColorRes); - + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_map_rendering, activity) .setId(MAP_RENDERING_CATEGORY_ID) .setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem()); @@ -1172,7 +1172,7 @@ public class ConfigureMapMenu { final AlertDialog dialog = bld.create(); dialogAdapter.setDialog(dialog); - + if (customRulesIncluded != null) { for (RenderingRuleProperty p : customRulesIncluded) { if (!p.isBoolean()) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 6443915ab3..7f51847964 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -25,7 +25,6 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.IntermediatePointsDialog; import net.osmand.plus.base.FavoriteImageDrawable; -import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.routing.AlarmInfo; diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 90447f2bf4..8e8864af75 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -32,6 +32,8 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import static net.osmand.osm.MapPoiTypes.WIKI_PLACE; + public class PoiFiltersHelper { private final OsmandApplication application; @@ -45,6 +47,7 @@ public class PoiFiltersHelper { private PoiUIFilter localWikiPoiFilter; private PoiUIFilter globalWikiPoiFilter; private List cacheTopStandardFilters; + private List cacheWikipediaFilters; private Map> selectedPoiFilters = new TreeMap<>(); private static final String UDF_CAR_AID = "car_aid"; @@ -62,6 +65,10 @@ 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; @@ -110,7 +117,7 @@ public class PoiFiltersHelper { public PoiUIFilter getLocalWikiPOIFilter() { if (localWikiPoiFilter == null) { - PoiType place = application.getPoiTypes().getPoiTypeByKey("wiki_place"); + PoiType place = application.getPoiTypes().getPoiTypeByKey(WIKI_PLACE); if (place != null && !Algorithms.isEmpty(application.getLanguage())) { PoiUIFilter filter = new PoiUIFilter(place, application, " " + application.getLangTranslation(application.getLanguage())); @@ -135,26 +142,41 @@ public class PoiFiltersHelper { return globalWikiPoiFilter; } - public List getWikiPOIFilters() { - List cacheWikipediaFilters = new ArrayList<>(); - List enabledLanguages = null; - Bundle wikiPoiSettings = WikipediaPoiMenu.getWikiPoiSettings(application); - if (wikiPoiSettings != null) { - enabledLanguages = wikiPoiSettings.getStringArrayList(WikipediaPoiMenu.ENABLED_WIKI_POI_LANGUAGES_KEY); - } - if (enabledLanguages != null) { - for (String language : enabledLanguages) { - PoiType place = application.getPoiTypes().getPoiTypeByKey("wiki_place"); - if (place != null) { - String locale = new Locale(language).getLanguage(); + public List getLocalWikipediaPoiFilters(boolean onlyActiveLocales) { + String wikiLang = "wiki:lang:"; + if (cacheWikipediaFilters == null) { + cacheWikipediaFilters = new ArrayList<>(); + PoiType place = application.getPoiTypes().getPoiTypeByKey(WIKI_PLACE); + if (place != null) { + for (String locale : application.getPoiTypes().getAllAvailableWikiLocales()) { PoiUIFilter filter = new PoiUIFilter(place, application, " " + - application.getLangTranslation(locale)); - filter.setSavedFilterByName("wiki:lang:" + locale); + WikipediaPoiMenu.getTranslation(application, locale)); + filter.setSavedFilterByName(wikiLang + locale); filter.setStandardFilter(true); cacheWikipediaFilters.add(filter); } } } + 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; } @@ -202,7 +224,7 @@ public class PoiFiltersHelper { return f; } } - for (PoiUIFilter f : getWikiPOIFilters()) { + for (PoiUIFilter f : getLocalWikipediaPoiFilters(true)) { if (f.getFilterId().equals(filterId)) { return f; } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiTemplateList.java b/OsmAnd/src/net/osmand/plus/poi/PoiTemplateList.java deleted file mode 100644 index 59a790b3ab..0000000000 --- a/OsmAnd/src/net/osmand/plus/poi/PoiTemplateList.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.osmand.plus.poi; - -public enum PoiTemplateList { - POI, WIKI -} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index 5afdd742cc..59d22aef93 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -39,6 +39,9 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; +import static net.osmand.osm.MapPoiTypes.OSM_WIKI_CATEGORY; +import static net.osmand.osm.MapPoiTypes.WIKI_PLACE; + public class PoiUIFilter implements SearchPoiTypeFilter, Comparable, CustomSearchPoiFilter { public final static String STD_PREFIX = "std_"; //$NON-NLS-1$ @@ -147,7 +150,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } public boolean isWikiFilter() { - return filterId.startsWith(STD_PREFIX + "wiki_place") || filterId.equals(STD_PREFIX + "osmwiki"); + return filterId.startsWith(STD_PREFIX + WIKI_PLACE) + || 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 8186951771..2052bbe020 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java @@ -23,7 +23,6 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.poi.PoiFiltersHelper; -import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickActionType; @@ -34,6 +33,8 @@ 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 { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 81f0f6a3d0..e16c872c91 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -70,7 +70,6 @@ import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; -import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment; import net.osmand.plus.profiles.ConfigureAppModesBottomSheetDialogFragment; @@ -120,6 +119,8 @@ 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); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java index 466d18cd40..8f40582bdc 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java @@ -36,7 +36,6 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.SimpleDividerItem; import net.osmand.plus.helpers.WaypointDialogHelper; import net.osmand.plus.helpers.WaypointHelper; -import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.routing.IRouteInformationListener; import net.osmand.plus.routing.IRoutingDataUpdateListener; @@ -45,6 +44,8 @@ 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"; diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 91cd25a83d..17bf11ee5b 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -79,7 +79,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; -import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.RearrangePoiFiltersFragment; import net.osmand.plus.resources.RegionAddressRepository; @@ -108,6 +107,7 @@ 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; diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 93b4c3127a..e51454e548 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -27,7 +27,6 @@ import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.poi.NominatimPoiFilter; import net.osmand.plus.poi.PoiFiltersHelper; -import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.resources.ResourceManager.ResourceListener; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -47,6 +46,8 @@ 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; diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index ba7a9eee85..ebb3efa034 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -39,7 +39,6 @@ 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.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.routing.IRouteInformationListener; diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java index 474cac110c..97bd1d746a 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/SelectWikiLanguagesBottomSheet.java @@ -11,9 +11,6 @@ import androidx.core.content.ContextCompat; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; -import net.osmand.osm.MapPoiTypes; -import net.osmand.osm.PoiCategory; -import net.osmand.osm.PoiType; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -53,6 +50,9 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen app = requiredMyApplication(); settings = app.getSettings(); initLanguagesData(); + if (savedInstanceState != null) { + dismiss(); + } } @Override @@ -105,18 +105,12 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen @Override public void onClick(View v) { boolean newValue = !languageItem[0].isChecked(); + languageItem[0].setChecked(newValue); language.setChecked(newValue); } }) .create(); languageItems.add(languageItem[0]); - language.setOnCheckLanguageCallback(new CallbackWithObject() { - @Override - public boolean processResult(Boolean result) { - languageItem[0].setChecked(result); - return true; - } - }); } items.addAll(languageItems); } @@ -125,29 +119,19 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen languages = new ArrayList<>(); Bundle wikiPoiSettings = WikipediaPoiMenu.getWikiPoiSettings(app); - List activatedLocales = null; + List enabledWikiPoiLocales = null; if (wikiPoiSettings != null) { isGlobalWikiPoiEnabled = wikiPoiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); - activatedLocales = wikiPoiSettings.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY); + enabledWikiPoiLocales = wikiPoiSettings.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY); } - - PoiCategory osmwiki = app.getPoiTypes().getOsmwiki(); - if (activatedLocales != null) { - for (PoiType type : osmwiki.getPoiTypeByKeyName("wiki_place").getPoiAdditionals()) { - String name = type.getKeyName(); - if (name != null && name.startsWith(MapPoiTypes.WIKI_LANG_KEY_PREFFIX)) { - String locale = name.substring(MapPoiTypes.WIKI_LANG_KEY_PREFFIX.length()); - boolean checked = activatedLocales.contains(locale); - languages.add(new WikiLanguageItem(locale, app.getLangTranslation(locale), checked)); - } + if (enabledWikiPoiLocales != null) { + for (String locale : app.getPoiTypes().getAllAvailableWikiLocales()) { + boolean checked = enabledWikiPoiLocales.contains(locale); + languages.add(new WikiLanguageItem(locale, WikipediaPoiMenu.getTranslation(app, locale), checked)); } } else { - for (PoiType type : osmwiki.getPoiTypeByKeyName("wiki_place").getPoiAdditionals()) { - String name = type.getKeyName(); - if (name != null && name.startsWith(MapPoiTypes.WIKI_LANG_KEY_PREFFIX)) { - String locale = name.substring(MapPoiTypes.WIKI_LANG_KEY_PREFFIX.length()); - languages.add(new WikiLanguageItem(locale, app.getLangTranslation(locale), false)); - } + for (String locale : app.getPoiTypes().getAllAvailableWikiLocales()) { + languages.add(new WikiLanguageItem(locale, WikipediaPoiMenu.getTranslation(app, locale), false)); } } @@ -224,7 +208,6 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen private String locale; private String title; private boolean checked; - private CallbackWithObject onCheckLanguageCallback; public WikiLanguageItem(String locale, String title, boolean checked) { this.locale = locale; @@ -242,20 +225,12 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen public void setChecked(boolean checked) { this.checked = checked; - if (onCheckLanguageCallback != null) { - onCheckLanguageCallback.processResult(checked); - } - } - - public void setOnCheckLanguageCallback(CallbackWithObject onCheckLanguageCallback) { - this.onCheckLanguageCallback = onCheckLanguageCallback; } public String getTitle() { return title; } - @Override public int compareTo(WikiLanguageItem other) { return this.title.compareToIgnoreCase(other.title); diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java index 58df48ee63..4baf24a982 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java @@ -1,12 +1,10 @@ package net.osmand.plus.wikipedia; import android.os.Bundle; -import android.view.View; import android.widget.ArrayAdapter; import androidx.annotation.NonNull; -import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; @@ -21,14 +19,17 @@ import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; import net.osmand.plus.poi.PoiFiltersHelper; -import net.osmand.plus.poi.PoiTemplateList; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.util.Algorithms; import java.io.IOException; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import static net.osmand.osm.MapPoiTypes.WIKI_LANG; +import static net.osmand.plus.poi.PoiFiltersHelper.PoiTemplateList; + public class WikipediaPoiMenu { public static final String GLOBAL_WIKI_POI_ENABLED_KEY = "global_wikipedia_poi_enabled_key"; @@ -51,19 +52,14 @@ public class WikipediaPoiMenu { private ContextMenuAdapter createLayersItems() { 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); ContextMenuAdapter adapter = new ContextMenuAdapter(); adapter.setDefaultLayoutId(R.layout.dash_item_with_description_72dp); adapter.setProfileDependent(true); adapter.setNightMode(nightMode); ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() { - - @Override - public boolean onRowItemClick(ArrayAdapter adapter, - View view, int itemId, int pos) { - return super.onRowItemClick(adapter, view, itemId, pos); - } - @Override public boolean onContextMenuClick(final ArrayAdapter adapter, final int itemId, final int position, final boolean isChecked, int[] viewCoordinates) { @@ -71,7 +67,7 @@ public class WikipediaPoiMenu { app.runInUIThread(new Runnable() { @Override public void run() { - toggleWikipediaPoi(mapActivity, !settings.SHOW_WIKIPEDIA_POI.getModeValue(appMode), true); + toggleWikipediaPoi(mapActivity, !enabled, true); } }); } else if (itemId == languageActionStringId) { @@ -83,7 +79,6 @@ public class WikipediaPoiMenu { int toggleIconId = R.drawable.ic_plugin_wikipedia; int toggleIconColorId; - boolean enabled = settings.SHOW_WIKIPEDIA_POI.getModeValue(appMode); if (enabled) { toggleIconColorId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; } else { @@ -132,8 +127,13 @@ public class WikipediaPoiMenu { adapter.addItem(new ContextMenuItem.ItemBuilder() .setLayout(R.layout.list_item_icon_and_download) .setTitleId(R.string.downloading_list_indexes, mapActivity) + .hideDivider(true) .setLoading(true) .setListener(l).createItem()); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setLayout(R.layout.card_bottom_divider) + .setMinHeight(spaceHeight) + .createItem()); } else { try { IndexItem currentDownloadingItem = downloadThread.getCurrentDownloadingItem(); @@ -146,12 +146,15 @@ public class WikipediaPoiMenu { .setDescription(app.getString(R.string.wiki_menu_download_descr)) .setCategory(true) .setLayout(R.layout.list_group_title_with_descr).createItem()); - for (final IndexItem indexItem : wikiIndexes) { + for (int i = 0; i < wikiIndexes.size(); i++) { + final IndexItem indexItem = wikiIndexes.get(i); + boolean isLastItem = i == wikiIndexes.size() - 1; ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder() .setLayout(R.layout.list_item_icon_and_download) .setTitle(indexItem.getVisibleName(app, app.getRegions(), false)) .setDescription(DownloadActivityType.WIKIPEDIA_FILE.getString(app) + " • " + indexItem.getSizeDescription(app)) .setIcon(DownloadActivityType.WIKIPEDIA_FILE.getIconResource()) + .hideDivider(isLastItem) .setListener(new ContextMenuAdapter.ItemClickListener() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) { @@ -207,6 +210,10 @@ public class WikipediaPoiMenu { } adapter.addItem(itemBuilder.createItem()); } + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setLayout(R.layout.card_bottom_divider) + .setMinHeight(spaceHeight) + .createItem()); } } catch (IOException e) { e.printStackTrace(); @@ -227,8 +234,10 @@ 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, wikiPoiSetting); + refreshWikiPoi(mapActivity, globalWikiEnabled); } else { toggleWikipediaPoi(mapActivity, true, usedOnMap); } @@ -241,6 +250,25 @@ public class WikipediaPoiMenu { }); } + public static String getTranslation(OsmandApplication app, String locale) { + String translation = app.getLangTranslation(locale); + if (translation.equalsIgnoreCase(locale)) { + translation = getTranslationFromPhrases(app, locale); + } + return translation; + } + + private static String getTranslationFromPhrases(OsmandApplication app, String locale) { + String keyName = WIKI_LANG + "_" + locale; + try { + Field f = R.string.class.getField("poi_" + keyName); + Integer in = (Integer) f.get(null); + return app.getString(in); + } catch (Throwable e) { + return locale; + } + } + public static Bundle getWikiPoiSettings(OsmandApplication app) { Bundle wikiSettings = getWikiPoiSettingsForProfile(app, app.getSettings().getApplicationMode()); if (wikiSettings == null) { @@ -272,7 +300,8 @@ public class WikipediaPoiMenu { Bundle wikiPoiSettings = getWikiPoiSettings(app); if (wikiPoiSettings != null) { settings.SHOW_WIKIPEDIA_POI.set(true); - showWikiOnMap(app, wikiPoiSettings); + boolean globalWikiEnabled = wikiPoiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); + showWikiOnMap(app, globalWikiEnabled); } else { ApplicationMode appMode = settings.getApplicationMode(); showLanguagesDialog(mapActivity, appMode, usedOnMap, false); @@ -285,21 +314,20 @@ public class WikipediaPoiMenu { mapActivity.refreshMap(); } - public static void refreshWikiPoi(MapActivity mapActivity, @NonNull Bundle wikiPoiSettings) { + public static void refreshWikiPoi(MapActivity mapActivity, boolean globalWikiEnabled) { OsmandApplication app = mapActivity.getMyApplication(); hideWikiFromMap(app); - showWikiOnMap(app, wikiPoiSettings); + showWikiOnMap(app, globalWikiEnabled); mapActivity.getDashboard().refreshContent(true); mapActivity.refreshMap(); } - private static void showWikiOnMap(OsmandApplication app, Bundle wikiPoiSettings) { + private static void showWikiOnMap(OsmandApplication app, boolean globalWikiEnabled) { PoiFiltersHelper ph = app.getPoiFilters(); - boolean globalWikiEnabled = wikiPoiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); if (globalWikiEnabled) { ph.addSelectedPoiFilter(PoiTemplateList.WIKI, ph.getGlobalWikiPoiFilter()); } else { - List filters = ph.getWikiPOIFilters(); + List filters = ph.getLocalWikipediaPoiFilters(true); for (PoiUIFilter filter : filters) { ph.addSelectedPoiFilter(PoiTemplateList.WIKI, filter); } @@ -318,28 +346,22 @@ public class WikipediaPoiMenu { Bundle wikiLanguagesSetting = getWikiPoiSettings(app); if (wikiLanguagesSetting != null) { boolean globalWikiEnabled = wikiLanguagesSetting.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY); - List enabledLanguages = wikiLanguagesSetting.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY); + List enabledLocales = wikiLanguagesSetting.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY); if (globalWikiEnabled) { return app.getString(R.string.shared_string_all_languages); - } else if (enabledLanguages != null) { + } else if (enabledLocales != null) { List translations = new ArrayList<>(); - for (String language : enabledLanguages) { - translations.add(app.getLangTranslation(language)); + for (String locale : enabledLocales) { + translations.add(getTranslation(app, locale)); } - return AndroidUtils.makeStringFromList(translations, ", "); + return android.text.TextUtils.join(", ", translations); } } return null; } public static boolean isWikiPoiEnabled(OsmandApplication app) { - OsmandSettings settings = app.getSettings(); - boolean shouldShowWiki = settings.SHOW_WIKIPEDIA_POI.get(); - if (shouldShowWiki && getWikiPoiSettings(app) == null) { - settings.SHOW_WIKIPEDIA_POI.set(false); - shouldShowWiki = false; - } - return shouldShowWiki; + return app.getSettings().SHOW_WIKIPEDIA_POI.get() && getWikiPoiSettings(app) != null; } public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) { From 0d3f0711fdec43bcb7370419610f19928f9da5e6 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Wed, 8 Apr 2020 13:50:21 +0300 Subject: [PATCH 3/3] 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(); }