Wikipedia Poi (Fixes 1)
This commit is contained in:
parent
7b268cd9d9
commit
3d3da9ee8e
21 changed files with 155 additions and 126 deletions
|
@ -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<String, PoiType> poiTypesByTag = new LinkedHashMap<String, PoiType>();
|
||||
|
@ -137,6 +139,19 @@ public class MapPoiTypes {
|
|||
return null;
|
||||
}
|
||||
|
||||
public List<String> getAllAvailableWikiLocales() {
|
||||
List<String> 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<? extends AbstractPoiType> lf) {
|
||||
final Collator instance = Collator.getInstance();
|
||||
Collections.sort(lf, new Comparator<AbstractPoiType>() {
|
||||
|
@ -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 {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title"
|
||||
|
|
|
@ -160,6 +160,7 @@
|
|||
<dimen name="bottom_sheet_divider_margin_start">84dp</dimen>
|
||||
<dimen name="bottom_sheet_image_text_margin_start">15dp</dimen>
|
||||
<dimen name="bottom_sheet_selected_item_title_height">84dp</dimen>
|
||||
<dimen name="bottom_sheet_big_item_height">192dp</dimen>
|
||||
|
||||
<dimen name="action_bar_image_width_land">354dp</dimen>
|
||||
<dimen name="action_bar_image_top_margin_land">102dp</dimen>
|
||||
|
|
|
@ -258,6 +258,7 @@
|
|||
<dimen name="bottom_sheet_image_text_margin_start">10dp</dimen>
|
||||
<dimen name="bottom_sheet_selected_item_title_height">56dp</dimen>
|
||||
<dimen name="bottom_sheet_text_spacing_multiplier" format="float">1.25</dimen>
|
||||
<dimen name="bottom_sheet_big_item_height">128dp</dimen>
|
||||
|
||||
<dimen name="action_bar_image_width_land">236dp</dimen>
|
||||
<dimen name="action_bar_image_top_margin_land">68dp</dimen>
|
||||
|
|
|
@ -252,18 +252,6 @@ public class AndroidUtils {
|
|||
return "";
|
||||
}
|
||||
|
||||
public static String makeStringFromList(@NonNull List<String> 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();
|
||||
|
||||
|
|
|
@ -1287,7 +1287,7 @@ public class OsmandSettings {
|
|||
public final CommonPreference<WikiArticleShowImages> WIKI_ARTICLE_SHOW_IMAGES = new EnumIntPreference<>("wikivoyage_show_imgs", WikiArticleShowImages.OFF, WikiArticleShowImages.values()).makeGlobal();
|
||||
public final CommonPreference<Boolean> SHOW_WIKIPEDIA_POI = new BooleanPreference("show_wikipedia_poi", false).makeProfile();
|
||||
public final CommonPreference<Boolean> GLOBAL_WIKIPEDIA_POI_ENABLED = new BooleanPreference("global_wikipedia_poi_enabled", false).makeProfile();
|
||||
public final ListStringPreference WIKIPEDIA_POI_ENABLED_LANGUAGES = (ListStringPreference) new ListStringPreference("wikipedia_poi_enabled_languages", null, ",,").makeProfile().cache();
|
||||
public final ListStringPreference WIKIPEDIA_POI_ENABLED_LANGUAGES = (ListStringPreference) new ListStringPreference("wikipedia_poi_enabled_languages", null, ",").makeProfile().cache();
|
||||
|
||||
public final CommonPreference<Boolean> SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile();
|
||||
public final CommonPreference<Boolean> KEEP_PASSED_MARKERS_ON_MAP = new BooleanPreference("keep_passed_markers_on_map", true).makeProfile();
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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<RenderingRuleProperty> customRules, ContextMenuAdapter adapter,
|
||||
private void createLayersItems(List<RenderingRuleProperty> 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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<PoiUIFilter> cacheTopStandardFilters;
|
||||
private List<PoiUIFilter> cacheWikipediaFilters;
|
||||
private Map<PoiTemplateList, Set<PoiUIFilter>> 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<PoiUIFilter> getWikiPOIFilters() {
|
||||
List<PoiUIFilter> cacheWikipediaFilters = new ArrayList<>();
|
||||
List<String> 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<PoiUIFilter> 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<PoiUIFilter> onlyActiveLocalFilters = new ArrayList<>();
|
||||
Bundle wikiPoiSettings = WikipediaPoiMenu.getWikiPoiSettings(application);
|
||||
if (wikiPoiSettings != null) {
|
||||
List<String> enabledWikipediaPoiLocales =
|
||||
wikiPoiSettings.getStringArrayList(WikipediaPoiMenu.ENABLED_WIKI_POI_LANGUAGES_KEY);
|
||||
if (enabledWikipediaPoiLocales != null) {
|
||||
for (PoiUIFilter filter : cacheWikipediaFilters) {
|
||||
for (String locale : enabledWikipediaPoiLocales) {
|
||||
String filterId = filter.getSavedFilterByName();
|
||||
String filterLocale = filterId.substring(wikiLang.length());
|
||||
if (locale.equalsIgnoreCase(filterLocale)) {
|
||||
onlyActiveLocalFilters.add(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return onlyActiveLocalFilters;
|
||||
}
|
||||
return cacheWikipediaFilters;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package net.osmand.plus.poi;
|
||||
|
||||
public enum PoiTemplateList {
|
||||
POI, WIKI
|
||||
}
|
|
@ -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<PoiUIFilter>, CustomSearchPoiFilter {
|
||||
|
||||
public final static String STD_PREFIX = "std_"; //$NON-NLS-1$
|
||||
|
@ -147,7 +150,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Boolean>() {
|
||||
@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<String> activatedLocales = null;
|
||||
List<String> 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<Boolean> 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<Boolean> onCheckLanguageCallback) {
|
||||
this.onCheckLanguageCallback = onCheckLanguageCallback;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(WikiLanguageItem other) {
|
||||
return this.title.compareToIgnoreCase(other.title);
|
||||
|
|
|
@ -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<ContextMenuItem> adapter,
|
||||
View view, int itemId, int pos) {
|
||||
return super.onRowItemClick(adapter, view, itemId, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> 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<ContextMenuItem> 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<PoiUIFilter> filters = ph.getWikiPOIFilters();
|
||||
List<PoiUIFilter> 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<String> enabledLanguages = wikiLanguagesSetting.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY);
|
||||
List<String> 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<String> 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) {
|
||||
|
|
Loading…
Reference in a new issue