From 86b47876939d1868431c3f9aa5ef915723fb999c Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Sat, 14 Oct 2017 14:30:42 +0300 Subject: [PATCH] Fix wikipedia multilingual issue --- .../plus/mapcontextmenu/MenuBuilder.java | 43 +++++++++++++------ .../plus/mapcontextmenu/MenuController.java | 12 ++++++ .../builders/AmenityMenuBuilder.java | 5 +-- .../controllers/AmenityMenuController.java | 8 ++-- .../RenderedObjectMenuController.java | 2 +- .../net/osmand/plus/views/POIMapLayer.java | 16 +++++-- 6 files changed, 60 insertions(+), 26 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index d49357cbc9..bfdf8c0c57 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -78,6 +78,10 @@ public class MenuBuilder { private CardsRowBuilder onlinePhotoCardsRow; private List onlinePhotoCards; + private String preferredMapLang; + private String preferredMapAppLang; + private boolean transliterateNames; + public class PlainMenuItem { private int iconId; private String text; @@ -185,6 +189,25 @@ public class MenuBuilder { this.mapActivity = mapActivity; this.app = mapActivity.getMyApplication(); this.plainMenuItems = new LinkedList<>(); + + preferredMapLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); + preferredMapAppLang = preferredMapLang; + if (Algorithms.isEmpty(preferredMapAppLang)) { + preferredMapAppLang = app.getLanguage(); + } + transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get(); + } + + public String getPreferredMapLang() { + return preferredMapLang; + } + + public String getPreferredMapAppLang() { + return preferredMapAppLang; + } + + public boolean isTransliterateNames() { + return transliterateNames; } public MapActivity getMapActivity() { @@ -661,7 +684,7 @@ public class MenuBuilder { wikiButton.setPadding(dpToPx(14f), 0, dpToPx(14f), 0); wikiButton.setTextColor(app.getResources() .getColor(light ? R.color.color_dialog_buttons_light : R.color.color_dialog_buttons_dark)); - wikiButton.setText(wiki.getName()); + wikiButton.setText(wiki.getName(preferredMapAppLang, transliterateNames)); wikiButton.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); wikiButton.setSingleLine(true); @@ -683,10 +706,6 @@ public class MenuBuilder { protected boolean processNearstWiki() { if (showNearestWiki && latLon != null) { - String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); - if (Algorithms.isEmpty(preferredLang)) { - preferredLang = app.getLanguage(); - } QuadRect rect = MapUtils.calculateLatLonBbox( latLon.getLatitude(), latLon.getLongitude(), 250); nearestWiki = app.getResourceManager().searchAmenities( @@ -711,16 +730,14 @@ public class MenuBuilder { } }); Long id = objectId; - if (id != 0) { - List wikiList = new ArrayList<>(); - for (Amenity wiki : nearestWiki) { - String lng = wiki.getContentLanguage("content", preferredLang, "en"); - if (wiki.getId().equals(id) || (!lng.equals("en") && !lng.equals(preferredLang))) { - wikiList.add(wiki); - } + List wikiList = new ArrayList<>(); + for (Amenity wiki : nearestWiki) { + String lng = wiki.getContentLanguage("content", preferredMapAppLang, "en"); + if (wiki.getId().equals(id) || (!lng.equals("en") && !lng.equals(preferredMapAppLang))) { + wikiList.add(wiki); } - nearestWiki.removeAll(wikiList); } + nearestWiki.removeAll(wikiList); return true; } return false; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 0638eb3f83..d7e9d64af4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -119,6 +119,18 @@ public abstract class MenuController extends BaseMenuController { this.builder.setLight(isLight()); } + public String getPreferredMapLang() { + return builder.getPreferredMapLang(); + } + + public String getPreferredMapAppLang() { + return builder.getPreferredMapAppLang(); + } + + public boolean isTransliterateNames() { + return builder.isTransliterateNames(); + } + public void setMapContextMenu(MapContextMenu mapContextMenu) { this.mapContextMenu = mapContextMenu; builder.setMapContextMenu(mapContextMenu); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 632fc71213..9a65b98354 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -278,10 +278,7 @@ public class AmenityMenuBuilder extends MenuBuilder { public void buildInternal(View view) { boolean hasWiki = false; MapPoiTypes poiTypes = app.getPoiTypes(); - String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); - if (Algorithms.isEmpty(preferredLang)) { - preferredLang = app.getLanguage(); - } + String preferredLang = getPreferredMapAppLang(); List infoRows = new LinkedList<>(); List descriptions = new LinkedList<>(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 55f712ba66..dcbacd66df 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -11,7 +11,6 @@ import net.osmand.data.TransportStop; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MapContextMenu; @@ -84,7 +83,7 @@ public class AmenityMenuController extends MenuController { return getLeftIconId(amenity); } - public static int getLeftIconId(Amenity amenity) { + private static int getLeftIconId(Amenity amenity) { String id = null; PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); if (st != null) { @@ -107,8 +106,9 @@ public class AmenityMenuController extends MenuController { @Override public String getNameStr() { - OsmandSettings settings = getMapActivity().getMyApplication().getSettings(); - return amenity.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()); + return amenity.getName( + amenity.getType().isWiki() ? getPreferredMapAppLang() : getPreferredMapLang(), + isTransliterateNames()); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java index dac6fc5989..3e834bfa46 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java @@ -62,7 +62,7 @@ public class RenderedObjectMenuController extends MenuController { if (!Algorithms.isEmpty(renderedObject.getName()) && !isStartingWithRTLChar(renderedObject.getName())) { return renderedObject.getName(); } else if (renderedObject.getTags().size() > 0) { - String lang = getMapActivity().getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get().toLowerCase(); + String lang = getPreferredMapLang().toLowerCase(); String name = ""; if (!Algorithms.isEmpty(lang)) { name = renderedObject.getTags().get("name:" + lang); diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 81fdabad74..04b7287646 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -321,7 +321,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon app.getSettings().isLightContent() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); - final String title = Algorithms.isEmpty(lang) ? a.getName() : a.getName(lang); + final String title = Algorithms.isEmpty(preferredLang) ? a.getName() : a.getName(preferredLang); LinearLayout ll = new LinearLayout(ctx); ll.setOrientation(LinearLayout.VERTICAL); @@ -519,9 +519,17 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon @Override public PointDescription getObjectName(Object o) { if (o instanceof Amenity) { - return new PointDescription(PointDescription.POINT_TYPE_POI, ((Amenity) o).getName( - view.getSettings().MAP_PREFERRED_LOCALE.get(), - view.getSettings().MAP_TRANSLITERATE_NAMES.get())); + Amenity a = (Amenity) o; + String preferredMapLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); + String preferredMapAppLang = preferredMapLang; + if (Algorithms.isEmpty(preferredMapAppLang)) { + preferredMapAppLang = app.getLanguage(); + } + boolean transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get(); + + return new PointDescription(PointDescription.POINT_TYPE_POI, a.getName( + a.getType().isWiki() ? preferredMapAppLang : preferredMapLang, + transliterateNames)); } return null; }