diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index 9f0c35bc89..03c25c0f5f 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -41,6 +41,7 @@ public class OsmandRegions { private BinaryMapIndexReader reader; Map> countriesByDownloadName = new HashMap>(); Map fullNamesToLocaleNames = new HashMap(); + Map fullNamesNoParentToLocaleNames = new HashMap(); Map fullMapNamesToDownloadNames = new HashMap(); Map downloadNamesToFullNames = new HashMap(); Map fullNamesToLowercaseIndex = new HashMap(); @@ -81,22 +82,36 @@ public class OsmandRegions { return nameEnType; } - public String getLocaleName(String downloadName) { + public String getLocaleName(String downloadName, boolean includingParent) { final String lc = downloadName.toLowerCase(); if (downloadNamesToFullNames.containsKey(lc)) { String fullName = downloadNamesToFullNames.get(lc); - if (fullNamesToLocaleNames.containsKey(fullName)) { - return fullNamesToLocaleNames.get(fullName); + if (includingParent) { + if (fullNamesToLocaleNames.containsKey(fullName)) { + return fullNamesToLocaleNames.get(fullName); + } + } else { + if (fullNamesNoParentToLocaleNames.containsKey(fullName)) { + return fullNamesNoParentToLocaleNames.get(fullName); + } } } return downloadName.replace('_', ' '); } - public String getLocaleNameByFullName(String fullName) { - if (fullNamesToLocaleNames.containsKey(fullName)) { - return fullNamesToLocaleNames.get(fullName); + public String getLocaleNameByFullName(String fullName, boolean includingParent) { + if (includingParent) { + if (fullNamesToLocaleNames.containsKey(fullName)) { + return fullNamesToLocaleNames.get(fullName); + } else { + return fullName.replace('_', ' '); + } } else { - return fullName.replace('_', ' '); + if (fullNamesNoParentToLocaleNames.containsKey(fullName)) { + return fullNamesNoParentToLocaleNames.get(fullName); + } else { + return fullName.replace('_', ' '); + } } } @@ -350,6 +365,7 @@ public class OsmandRegions { String locName = getLocaleName(object); if(!Algorithms.isEmpty(locName)){ fullNamesToLocaleNames.put(fullName, locName); + fullNamesNoParentToLocaleNames.put(fullName, locName); } MapIndex mi = object.getMapIndex(); TIntObjectIterator it = object.getObjectNames().iterator(); @@ -358,8 +374,9 @@ public class OsmandRegions { it.advance(); TagValuePair tp = mi.decodeType(it.key()); if (tp.tag.equals("key_name") && Algorithms.isEmpty(locName)) { - fullNamesToLocaleNames.put(fullName, - Algorithms.capitalizeFirstLetterAndLowercase(it.value().replace('_', '-'))); + String str = Algorithms.capitalizeFirstLetterAndLowercase(it.value().replace('_', '-')); + fullNamesToLocaleNames.put(fullName, str); + fullNamesNoParentToLocaleNames.put(fullName, str); } if(tp.tag.startsWith("name") || tp.tag.equals("key_name")) { final String vl = it.value().toLowerCase(); @@ -403,7 +420,8 @@ public class OsmandRegions { if(locPrefix == null || locName == null) { throw new IllegalStateException("There is no prefix registered for " + fullName + " (" + parentFullName + ") "); } - fullNamesToLocaleNames.put(fullName, /*locPrefix + " " +*/ locName); + fullNamesToLocaleNames.put(fullName, locPrefix + " " + locName); + fullNamesNoParentToLocaleNames.put(fullName, locName); String index = fullNamesToLowercaseIndex.get(fullName); String prindex = fullNamesToLowercaseIndex.get(parentFullName); fullNamesToLowercaseIndex.put(fullName, index + " " + prindex); diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java index be9ed9139e..1185169b21 100644 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ b/OsmAnd/src/net/osmand/plus/WorldRegion.java @@ -141,7 +141,7 @@ public class WorldRegion { if (name != null) { this.name = name; } else { - this.name = osmandRegions.getLocaleNameByFullName(regionId); + this.name = osmandRegions.getLocaleNameByFullName(regionId, false); if (this.name == null) { this.name = capitalize(regionId.replace('_', ' ')); } @@ -157,7 +157,7 @@ public class WorldRegion { } else { this.downloadsIdPrefix = regionId.toLowerCase() + "."; } - this.name = osmandRegions.getLocaleNameByFullName(regionId); + this.name = osmandRegions.getLocaleNameByFullName(regionId, false); if (this.name == null) { this.name = capitalize(regionId.replace('_', ' ')); } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index bdd64a221d..4bb7b6130e 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -259,7 +259,7 @@ public class DownloadActivityType implements Parcelable { return ""; } - public String getVisibleName(IndexItem indexItem, Context ctx, OsmandRegions osmandRegions) { + public String getVisibleName(IndexItem indexItem, Context ctx, OsmandRegions osmandRegions, boolean includingParent) { if (this == VOICE_FILE) { String fileName = indexItem.fileName; if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) { @@ -284,11 +284,11 @@ public class DownloadActivityType implements Parcelable { if (bn.contains("addresses-nationwide")) { final int ind = bn.indexOf("addresses-nationwide"); String downloadName = bn.substring(0, ind - 1) + bn.substring(ind + "addresses-nationwide".length()); - return osmandRegions.getLocaleName(downloadName) + + return osmandRegions.getLocaleName(downloadName, includingParent) + " "+ ctx.getString(R.string.index_item_nation_addresses); } - return osmandRegions.getLocaleName(bn); + return osmandRegions.getLocaleName(bn, includingParent); } public String getTargetFileName(IndexItem item) { diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java index 574fb69228..b9dab4e113 100644 --- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java @@ -137,7 +137,11 @@ public class IndexItem implements Comparable, HasName, Parcelable { } public String getVisibleName(Context ctx, OsmandRegions osmandRegions) { - return type.getVisibleName(this, ctx, osmandRegions); + return type.getVisibleName(this, ctx, osmandRegions, true); + } + + public String getVisibleName(Context ctx, OsmandRegions osmandRegions, boolean includingParent) { + return type.getVisibleName(this, ctx, osmandRegions, includingParent); } public String getVisibleDescription(OsmandApplication clctx) { diff --git a/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java index 47591e2135..ef54488d9a 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java @@ -96,7 +96,7 @@ public class ItemViewHolder { if (indexItem.getType() == DownloadActivityType.VOICE_FILE) { nameTextView.setText(indexItem.getVisibleName(context, - context.getMyApplication().getRegions())); + context.getMyApplication().getRegions(), false)); } else { if (indexItem.getSimplifiedFileName().equals(ItemsListBuilder.WORLD_SEAMARKS_KEY) && nauticalPluginDisabled) { rightButtonAction = RightButtonAction.ASK_FOR_SEAMARKS_PLUGIN; @@ -119,7 +119,7 @@ public class ItemViewHolder { if (showTypeInTitle) { nameTextView.setText(indexItem.getType().getString(context)); } else { - nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions())); + nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), false)); } } diff --git a/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java b/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java index 882591f151..a12a32db85 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java +++ b/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java @@ -231,7 +231,7 @@ public class ItemsListBuilder { for (IndexItem indexItem : regionResources.values()) { - String name = indexItem.getVisibleName(context, osmandRegions); + String name = indexItem.getVisibleName(context, osmandRegions, false); if (Algorithms.isEmpty(name)) { continue; } diff --git a/OsmAnd/src/net/osmand/plus/download/items/SearchItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/items/SearchItemsFragment.java index aa0f3fc01a..ef9d75b81d 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/SearchItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/SearchItemsFragment.java @@ -322,13 +322,13 @@ public class SearchItemsFragment extends Fragment { if (obj1 instanceof WorldRegion) { str1 = ((WorldRegion) obj1).getName(); } else { - str1 = ((IndexItem) obj1).getVisibleName(getMyApplication(), osmandRegions); + str1 = ((IndexItem) obj1).getVisibleName(getMyApplication(), osmandRegions, false); } if (obj2 instanceof WorldRegion) { str2 = ((WorldRegion) obj2).getName(); } else { - str2 = ((IndexItem) obj2).getVisibleName(getMyApplication(), osmandRegions); + str2 = ((IndexItem) obj2).getVisibleName(getMyApplication(), osmandRegions, false); } return collator.compare(str1, str2); diff --git a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java index b672691dd6..26713418a4 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java @@ -48,7 +48,7 @@ public class FileNameTranslationHelper { } if (regions != null) { - return regions.getLocaleName(basename); + return regions.getLocaleName(basename, true); } return null; @@ -56,7 +56,7 @@ public class FileNameTranslationHelper { public static String getHillShadeName(Context ctx, OsmandRegions regions, String basename) { String hillsh = ctx.getString(R.string.download_hillshade_item) + " "; - String locName = regions.getLocaleName(basename.trim()); + String locName = regions.getLocaleName(basename.trim(), true); return hillsh + locName; } diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index 54ed144e12..9c7397a3de 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -250,7 +250,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { String fullName = osmandRegions.getFullName(o); String downloadName = osmandRegions.getMapDownloadType(fullName); if (!Algorithms.isEmpty(downloadName)) { - String name = osmandRegions.getLocaleName(downloadName); // Algorithms.capitalizeFirstLetterAndLowercase(o.getName()); + String name = osmandRegions.getLocaleName(downloadName, true); // Algorithms.capitalizeFirstLetterAndLowercase(o.getName()); if (checkIfObjectDownloaded(downloadName)) { return null; }