Fixes first part
This commit is contained in:
parent
9d9f0c3cf9
commit
414ce3f276
6 changed files with 50 additions and 37 deletions
|
@ -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<String> 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<String> enabledPlugins, @NonNull OsmandPlugin plugin) {
|
||||
private static void enableHiddenPlugin(@NonNull OsmandApplication app, @NonNull Set<String> 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<String> 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<String> 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;
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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<String, String> additionalInfo = amenity.getAdditionalInfo();
|
||||
if (additionalInfo != null) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<String> supportedLocales, String preferredLocale) {
|
||||
return getWikiArticleLanguage(supportedLocales, preferredLocale);
|
||||
protected String getMapObjectsLocale(Amenity amenity, String preferredLocale) {
|
||||
return getWikiArticleLanguage(amenity.getSupportedContentLocales(), preferredLocale);
|
||||
}
|
||||
|
||||
public String getWikiArticleLanguage(@NonNull Set<String> 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<String> 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;
|
||||
|
|
Loading…
Reference in a new issue