Fixes first part

This commit is contained in:
Vitaliy 2020-07-02 15:25:40 +03:00
parent 9d9f0c3cf9
commit 414ce3f276
6 changed files with 50 additions and 37 deletions

View file

@ -21,6 +21,8 @@ import net.osmand.IProgress;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin; import net.osmand.access.AccessibilityPlugin;
import net.osmand.data.Amenity;
import net.osmand.data.MapObject;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TabActivity.TabItem; import net.osmand.plus.activities.TabActivity.TabItem;
@ -262,15 +264,10 @@ public abstract class OsmandPlugin {
Set<String> enabledPlugins = app.getSettings().getEnabledPlugins(); Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
allPlugins.clear(); allPlugins.clear();
allPlugins.add(new MapillaryPlugin(app));
if (!enabledPlugins.contains(MapillaryPlugin.ID) enableHiddenPlugin(app, enabledPlugins, new MapillaryPlugin(app));
&& !app.getSettings().getPlugins().contains("-" + MapillaryPlugin.ID)) { enableHiddenPlugin(app, enabledPlugins, new WikipediaPlugin(app));
enabledPlugins.add(MapillaryPlugin.ID);
app.getSettings().enablePlugin(MapillaryPlugin.ID, true);
}
checkPaidPlugin(app, enabledPlugins, new WikipediaPlugin(app));
allPlugins.add(new OsmandRasterMapsPlugin(app)); allPlugins.add(new OsmandRasterMapsPlugin(app));
allPlugins.add(new OsmandMonitoringPlugin(app)); allPlugins.add(new OsmandMonitoringPlugin(app));
checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app)); checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app));
@ -374,14 +371,11 @@ public abstract class OsmandPlugin {
} }
} }
private static void checkPaidPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) { private static void enableHiddenPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) {
allPlugins.add(plugin); allPlugins.add(plugin);
boolean active = Version.isPaidVersion(app); if (!enabledPlugins.contains(plugin.getId()) && !app.getSettings().getPlugins().contains("-" + plugin.getId())) {
plugin.setActive(active);
if (active) {
enabledPlugins.add(plugin.getId()); enabledPlugins.add(plugin.getId());
} else { app.getSettings().enablePlugin(plugin.getId(), true);
enabledPlugins.remove(plugin.getId());
} }
} }
@ -559,8 +553,11 @@ public abstract class OsmandPlugin {
protected void prepareExtraTopPoiFilters(PoiUIFilter ... filters) { protected void prepareExtraTopPoiFilters(PoiUIFilter ... filters) {
} }
protected String getMapObjectsLocale(Set<String> supportedLocales, protected String getMapObjectsLocale(Amenity amenity, String preferredLocale) {
String preferredLocale) { return null;
}
protected String getMapObjectPreferredLang(MapObject object, String defaultLanguage) {
return null; return null;
} }
@ -841,10 +838,19 @@ public abstract class OsmandPlugin {
} }
} }
public static String onGetMapObjectsLocale(Set<String> supportedLocales, public static String onGetMapObjectPreferredLang(MapObject object, String preferredMapLang, String preferredMapAppLang) {
String preferredLocale) {
for (OsmandPlugin plugin : getAvailablePlugins()) { 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) { if (locale != null) {
return locale; return locale;
} }

View file

@ -407,8 +407,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
if (amenity.getType().isWiki()) { if (amenity.getType().isWiki()) {
if (!hasWiki) { if (!hasWiki) {
String articleLang = OsmandPlugin.onGetMapObjectsLocale( String articleLang = OsmandPlugin.onGetMapObjectsLocale(amenity, preferredLang);
amenity.getSupportedContentLocales(), preferredLang);
String lng = amenity.getContentLanguage("content", articleLang, "en"); String lng = amenity.getContentLanguage("content", articleLang, "en");
if (Algorithms.isEmpty(lng)) { if (Algorithms.isEmpty(lng)) {
lng = "en"; lng = "en";

View file

@ -157,11 +157,8 @@ public class AmenityMenuController extends MenuController {
@NonNull @NonNull
@Override @Override
public String getNameStr() { public String getNameStr() {
String preferredLang = getPreferredMapLang(); String preferredLang = OsmandPlugin.onGetMapObjectPreferredLang(amenity,
if (amenity.getType().isWiki()) { getPreferredMapAppLang(), getPreferredMapLang());
preferredLang = OsmandPlugin.onGetMapObjectsLocale(
amenity.getSupportedContentLocales(), getPreferredMapAppLang());
}
String name = amenity.getName(preferredLang, isTransliterateNames()); String name = amenity.getName(preferredLang, isTransliterateNames());
Map<String, String> additionalInfo = amenity.getAdditionalInfo(); Map<String, String> additionalInfo = amenity.getAdditionalInfo();
if (additionalInfo != null) { if (additionalInfo != null) {

View file

@ -331,20 +331,19 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override @Override
public PointDescription getObjectName(Object o) { public PointDescription getObjectName(Object o) {
if (o instanceof Amenity) { if (o instanceof Amenity) {
Amenity a = (Amenity) o; Amenity amenity = (Amenity) o;
String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get();
boolean transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get(); boolean transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
if (a.getType().isWiki()) { if (amenity.getType().isWiki()) {
if (Algorithms.isEmpty(preferredLang)) { if (Algorithms.isEmpty(preferredLang)) {
preferredLang = app.getLanguage(); preferredLang = app.getLanguage();
} }
preferredLang = OsmandPlugin.onGetMapObjectsLocale( preferredLang = OsmandPlugin.onGetMapObjectsLocale(amenity, preferredLang);
a.getSupportedContentLocales(), preferredLang);
} }
return new PointDescription(PointDescription.POINT_TYPE_POI, return new PointDescription(PointDescription.POINT_TYPE_POI,
a.getName(preferredLang, transliterateNames)); amenity.getName(preferredLang, transliterateNames));
} }
return null; return null;
} }

View file

@ -282,8 +282,8 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
WikipediaDialogFragment wikipediaDialogFragment = new WikipediaDialogFragment(); WikipediaDialogFragment wikipediaDialogFragment = new WikipediaDialogFragment();
wikipediaDialogFragment.setAmenity(amenity); wikipediaDialogFragment.setAmenity(amenity);
lang = lang != null ? lang : OsmandPlugin.onGetMapObjectsLocale( WikipediaPlugin wikipediaPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
amenity.getSupportedContentLocales(), lang = lang != null ? lang : wikipediaPlugin.getMapObjectsLocale(amenity,
app.getSettings().MAP_PREFERRED_LOCALE.get()); app.getSettings().MAP_PREFERRED_LOCALE.get());
wikipediaDialogFragment.setLanguage(lang); wikipediaDialogFragment.setLanguage(lang);
wikipediaDialogFragment.setRetainInstance(true); wikipediaDialogFragment.setRetainInstance(true);

View file

@ -9,6 +9,8 @@ import androidx.fragment.app.Fragment;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.data.Amenity;
import net.osmand.data.MapObject;
import net.osmand.osm.AbstractPoiType; import net.osmand.osm.AbstractPoiType;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
@ -244,12 +246,22 @@ public class WikipediaPlugin extends OsmandPlugin {
} }
@Override @Override
protected String getMapObjectsLocale(Set<String> supportedLocales, String preferredLocale) { protected String getMapObjectsLocale(Amenity amenity, String preferredLocale) {
return getWikiArticleLanguage(supportedLocales, preferredLocale); return getWikiArticleLanguage(amenity.getSupportedContentLocales(), preferredLocale);
} }
public String getWikiArticleLanguage(@NonNull Set<String> availableArticleLangs, @Override
String preferredLanguage) { 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<String> availableArticleLangs, String preferredLanguage) {
if (!hasCustomSettings()) { if (!hasCustomSettings()) {
// Wikipedia with default settings // Wikipedia with default settings
return preferredLanguage; return preferredLanguage;
@ -347,7 +359,7 @@ public class WikipediaPlugin extends OsmandPlugin {
} }
@Override @Override
protected void prepareExtraTopPoiFilters(PoiUIFilter ... filters) { protected void prepareExtraTopPoiFilters(PoiUIFilter... filters) {
for (PoiUIFilter filter : filters) { for (PoiUIFilter filter : filters) {
if (filter.isTopWikiFilter()) { if (filter.isTopWikiFilter()) {
boolean prepareByDefault = true; boolean prepareByDefault = true;