diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 0bcbcc7ba4..4cbfe665e2 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -21,6 +21,8 @@ import net.osmand.IProgress; import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.access.AccessibilityPlugin; +import net.osmand.data.Amenity; +import net.osmand.data.MapObject; import net.osmand.map.WorldRegion; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TabActivity.TabItem; @@ -262,15 +264,10 @@ public abstract class OsmandPlugin { Set enabledPlugins = app.getSettings().getEnabledPlugins(); allPlugins.clear(); - allPlugins.add(new MapillaryPlugin(app)); - if (!enabledPlugins.contains(MapillaryPlugin.ID) - && !app.getSettings().getPlugins().contains("-" + MapillaryPlugin.ID)) { - enabledPlugins.add(MapillaryPlugin.ID); - app.getSettings().enablePlugin(MapillaryPlugin.ID, true); - } + enableHiddenPlugin(app, enabledPlugins, new MapillaryPlugin(app)); + enableHiddenPlugin(app, enabledPlugins, new WikipediaPlugin(app)); - checkPaidPlugin(app, enabledPlugins, new WikipediaPlugin(app)); allPlugins.add(new OsmandRasterMapsPlugin(app)); allPlugins.add(new OsmandMonitoringPlugin(app)); checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app)); @@ -374,14 +371,11 @@ public abstract class OsmandPlugin { } } - private static void checkPaidPlugin(@NonNull OsmandApplication app, @NonNull Set enabledPlugins, @NonNull OsmandPlugin plugin) { + private static void enableHiddenPlugin(@NonNull OsmandApplication app, @NonNull Set enabledPlugins, @NonNull OsmandPlugin plugin) { allPlugins.add(plugin); - boolean active = Version.isPaidVersion(app); - plugin.setActive(active); - if (active) { + if (!enabledPlugins.contains(plugin.getId()) && !app.getSettings().getPlugins().contains("-" + plugin.getId())) { enabledPlugins.add(plugin.getId()); - } else { - enabledPlugins.remove(plugin.getId()); + app.getSettings().enablePlugin(plugin.getId(), true); } } @@ -559,8 +553,11 @@ public abstract class OsmandPlugin { protected void prepareExtraTopPoiFilters(PoiUIFilter ... filters) { } - protected String getMapObjectsLocale(Set supportedLocales, - String preferredLocale) { + protected String getMapObjectsLocale(Amenity amenity, String preferredLocale) { + return null; + } + + protected String getMapObjectPreferredLang(MapObject object, String defaultLanguage) { return null; } @@ -841,10 +838,19 @@ public abstract class OsmandPlugin { } } - public static String onGetMapObjectsLocale(Set supportedLocales, - String preferredLocale) { + public static String onGetMapObjectPreferredLang(MapObject object, String preferredMapLang, String preferredMapAppLang) { for (OsmandPlugin plugin : getAvailablePlugins()) { - String locale = plugin.getMapObjectsLocale(supportedLocales, preferredLocale); + String locale = plugin.getMapObjectPreferredLang(object, preferredMapLang); + if (locale != null) { + return locale; + } + } + return preferredMapAppLang; + } + + public static String onGetMapObjectsLocale(Amenity amenity, String preferredLocale) { + for (OsmandPlugin plugin : getAvailablePlugins()) { + String locale = plugin.getMapObjectsLocale(amenity, preferredLocale); if (locale != null) { return locale; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 89316855a3..66567bc76c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -407,8 +407,7 @@ public class AmenityMenuBuilder extends MenuBuilder { if (amenity.getType().isWiki()) { if (!hasWiki) { - String articleLang = OsmandPlugin.onGetMapObjectsLocale( - amenity.getSupportedContentLocales(), preferredLang); + String articleLang = OsmandPlugin.onGetMapObjectsLocale(amenity, preferredLang); String lng = amenity.getContentLanguage("content", articleLang, "en"); if (Algorithms.isEmpty(lng)) { lng = "en"; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 02ec9db520..06ade3cc26 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -157,11 +157,8 @@ public class AmenityMenuController extends MenuController { @NonNull @Override public String getNameStr() { - String preferredLang = getPreferredMapLang(); - if (amenity.getType().isWiki()) { - preferredLang = OsmandPlugin.onGetMapObjectsLocale( - amenity.getSupportedContentLocales(), getPreferredMapAppLang()); - } + String preferredLang = OsmandPlugin.onGetMapObjectPreferredLang(amenity, + getPreferredMapAppLang(), getPreferredMapLang()); String name = amenity.getName(preferredLang, isTransliterateNames()); Map additionalInfo = amenity.getAdditionalInfo(); if (additionalInfo != null) { diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index eeb83b08d8..18b23fd8e8 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -331,20 +331,19 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon @Override public PointDescription getObjectName(Object o) { if (o instanceof Amenity) { - Amenity a = (Amenity) o; + Amenity amenity = (Amenity) o; String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); boolean transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get(); - if (a.getType().isWiki()) { + if (amenity.getType().isWiki()) { if (Algorithms.isEmpty(preferredLang)) { preferredLang = app.getLanguage(); } - preferredLang = OsmandPlugin.onGetMapObjectsLocale( - a.getSupportedContentLocales(), preferredLang); + preferredLang = OsmandPlugin.onGetMapObjectsLocale(amenity, preferredLang); } return new PointDescription(PointDescription.POINT_TYPE_POI, - a.getName(preferredLang, transliterateNames)); + amenity.getName(preferredLang, transliterateNames)); } return null; } diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java index a01d79903c..2e917881e4 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java @@ -282,8 +282,8 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment { WikipediaDialogFragment wikipediaDialogFragment = new WikipediaDialogFragment(); wikipediaDialogFragment.setAmenity(amenity); - lang = lang != null ? lang : OsmandPlugin.onGetMapObjectsLocale( - amenity.getSupportedContentLocales(), + WikipediaPlugin wikipediaPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class); + lang = lang != null ? lang : wikipediaPlugin.getMapObjectsLocale(amenity, app.getSettings().MAP_PREFERRED_LOCALE.get()); wikipediaDialogFragment.setLanguage(lang); wikipediaDialogFragment.setRetainInstance(true); diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java index 75bbfd7d15..5b67d37e2e 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java @@ -9,6 +9,8 @@ import androidx.fragment.app.Fragment; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; +import net.osmand.data.Amenity; +import net.osmand.data.MapObject; import net.osmand.osm.AbstractPoiType; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; @@ -244,12 +246,22 @@ public class WikipediaPlugin extends OsmandPlugin { } @Override - protected String getMapObjectsLocale(Set supportedLocales, String preferredLocale) { - return getWikiArticleLanguage(supportedLocales, preferredLocale); + protected String getMapObjectsLocale(Amenity amenity, String preferredLocale) { + return getWikiArticleLanguage(amenity.getSupportedContentLocales(), preferredLocale); } - public String getWikiArticleLanguage(@NonNull Set availableArticleLangs, - String preferredLanguage) { + @Override + protected String getMapObjectPreferredLang(MapObject object, String defaultLanguage) { + if (object instanceof Amenity) { + Amenity amenity = (Amenity) object; + if (amenity.getType().isWiki()) { + return getWikiArticleLanguage(amenity.getSupportedContentLocales(), defaultLanguage); + } + } + return null; + } + + public String getWikiArticleLanguage(@NonNull Set availableArticleLangs, String preferredLanguage) { if (!hasCustomSettings()) { // Wikipedia with default settings return preferredLanguage; @@ -347,7 +359,7 @@ public class WikipediaPlugin extends OsmandPlugin { } @Override - protected void prepareExtraTopPoiFilters(PoiUIFilter ... filters) { + protected void prepareExtraTopPoiFilters(PoiUIFilter... filters) { for (PoiUIFilter filter : filters) { if (filter.isTopWikiFilter()) { boolean prepareByDefault = true;