Fix wikipedia multilingual issue
This commit is contained in:
parent
0caf577a65
commit
86b4787693
6 changed files with 60 additions and 26 deletions
|
@ -78,6 +78,10 @@ public class MenuBuilder {
|
|||
private CardsRowBuilder onlinePhotoCardsRow;
|
||||
private List<AbstractCard> 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<Amenity> 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<Amenity> 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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<AmenityInfoRow> infoRows = new LinkedList<>();
|
||||
List<AmenityInfoRow> descriptions = new LinkedList<>();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue