From f3900ffd4ac8fffe1b06efd5d393101b261bccec Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 2 Nov 2020 21:59:42 +0200 Subject: [PATCH] Fix hillshade, slope localization, map sorting --- .../plus/download/DownloadActivityType.java | 8 ++++---- .../helpers/FileNameTranslationHelper.java | 20 +++++++++++++------ .../backend/backup/SettingsHelper.java | 20 +++++++++++++++++++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index 95631c9c8c..b516d73d2c 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -342,7 +342,7 @@ public class DownloadActivityType { return FileNameTranslationHelper.getFontName(ctx, getBasename(indexItem)); } final String basename = getBasename(indexItem); - if (basename.endsWith(FileNameTranslationHelper.WIKI_NAME)){ + if (basename.endsWith(FileNameTranslationHelper.WIKI_NAME)) { return FileNameTranslationHelper.getWikiName(ctx, basename); } // if (this == HILLSHADE_FILE){ @@ -357,7 +357,7 @@ public class DownloadActivityType { final int ind = basename.indexOf("addresses-nationwide"); String downloadName = basename.substring(0, ind - 1) + basename.substring(ind + "addresses-nationwide".length()); return osmandRegions.getLocaleName(downloadName, includingParent) + - " "+ ctx.getString(R.string.index_item_nation_addresses); + " " + ctx.getString(R.string.index_item_nation_addresses); } else if (basename.startsWith("Depth_")) { final int extInd = basename.indexOf("osmand_ext"); String downloadName = extInd == -1 ? basename.substring(6, basename.length()).replace('_', ' ') @@ -438,11 +438,11 @@ public class DownloadActivityType { } if (this == HILLSHADE_FILE) { return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()) - .replace(FileNameTranslationHelper.HILL_SHADE, ""); + .replace(FileNameTranslationHelper.HILL_SHADE + "_", ""); } if (this == SLOPE_FILE) { return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()) - .replace(FileNameTranslationHelper.SLOPE, ""); + .replace(FileNameTranslationHelper.SLOPE + "_", ""); } if (fileName.endsWith(IndexConstants.SQLITE_EXT)) { return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()); diff --git a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java index 229003050e..e366d1e8bb 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java @@ -4,6 +4,7 @@ import android.content.Context; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.map.OsmandRegions; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.download.DownloadResources; @@ -18,10 +19,14 @@ import java.lang.reflect.Field; public class FileNameTranslationHelper { private static final Log LOG = PlatformUtil.getLog(FileNameTranslationHelper.class); public static final String WIKI_NAME = "_wiki"; - public static final String HILL_SHADE = "Hillshade_"; - public static final String SLOPE = "Slope_"; + public static final String HILL_SHADE = "Hillshade"; + public static final String SLOPE = "Slope"; public static final String SEA_DEPTH = "Depth_"; + public static String getFileNameWithRegion(OsmandApplication app, String fileName) { + return getFileName(app, app.getResourceManager().getOsmandRegions(), fileName); + } + public static String getFileName(Context ctx, OsmandRegions regions, String fileName) { String basename = getBasename(fileName); if (basename.endsWith(WIKI_NAME)) { //wiki files @@ -30,13 +35,15 @@ public class FileNameTranslationHelper { return getVoiceName(ctx, fileName); } else if (fileName.endsWith(IndexConstants.FONT_INDEX_EXT)) { //otf files return getFontName(ctx, basename); - } else if (fileName.startsWith(HILL_SHADE)){ + } else if (fileName.startsWith(HILL_SHADE)) { + basename = basename.replace(HILL_SHADE + " ", ""); return getTerrainName(ctx, regions, basename, R.string.download_hillshade_maps); } else if (fileName.startsWith(SLOPE)) { + basename = basename.replace(SLOPE + " ", ""); return getTerrainName(ctx, regions, basename, R.string.download_slope_maps); } else if (fileName.length() == 2) { //voice recorded files try { - Field f = R.string.class.getField("lang_"+fileName); + Field f = R.string.class.getField("lang_" + fileName); if (f != null) { Integer in = (Integer) f.get(null); return ctx.getString(in); @@ -62,9 +69,10 @@ public class FileNameTranslationHelper { public static String getTerrainName(Context ctx, OsmandRegions regions, String basename, int terrainNameRes) { - String terrain = ctx.getString(terrainNameRes) + " "; + basename = basename.replace(" ", "_"); + String terrain = ctx.getString(terrainNameRes); String locName = regions.getLocaleName(basename.trim(), true); - return terrain + locName; + return ctx.getString(R.string.ltr_or_rtl_combine_via_space, locName, "(" + terrain + ")"); } public static String getWikiName(Context ctx, String basename){ diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index f3821505a2..f6cbdb4b43 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -7,7 +7,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import net.osmand.AndroidUtils; +import net.osmand.Collator; import net.osmand.IndexConstants; +import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.map.ITileSource; @@ -23,6 +25,7 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; +import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; import net.osmand.plus.osmedit.OpenstreetmapPoint; @@ -42,6 +45,8 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -542,6 +547,7 @@ public class SettingsHelper { files = getFilesByType(localIndexInfoList, LocalIndexType.MAP_DATA, LocalIndexType.TILES_DATA, LocalIndexType.SRTM_DATA, LocalIndexType.WIKI_DATA); if (!files.isEmpty()) { + sortData(files); dataList.put(ExportSettingsType.OFFLINE_MAPS, files); } files = getFilesByType(localIndexInfoList, LocalIndexType.TTS_VOICE_DATA); @@ -801,4 +807,18 @@ public class SettingsHelper { } return settingsToOperate; } + + public void sortData(List files) { + final Collator collator = OsmAndCollator.primaryCollator(); + Collections.sort(files, new Comparator() { + @Override + public int compare(File lhs, File rhs) { + return collator.compare(getNameToDisplay(lhs), getNameToDisplay(rhs)); + } + + private String getNameToDisplay(File item) { + return FileNameTranslationHelper.getFileNameWithRegion(app, item.getName()); + } + }); + } } \ No newline at end of file