Fix hillshade, slope localization, map sorting

This commit is contained in:
Dima-1 2020-11-02 21:59:42 +02:00
parent f3c4b59362
commit f3900ffd4a
3 changed files with 38 additions and 10 deletions

View file

@ -342,7 +342,7 @@ public class DownloadActivityType {
return FileNameTranslationHelper.getFontName(ctx, getBasename(indexItem)); return FileNameTranslationHelper.getFontName(ctx, getBasename(indexItem));
} }
final String basename = getBasename(indexItem); final String basename = getBasename(indexItem);
if (basename.endsWith(FileNameTranslationHelper.WIKI_NAME)){ if (basename.endsWith(FileNameTranslationHelper.WIKI_NAME)) {
return FileNameTranslationHelper.getWikiName(ctx, basename); return FileNameTranslationHelper.getWikiName(ctx, basename);
} }
// if (this == HILLSHADE_FILE){ // if (this == HILLSHADE_FILE){
@ -357,7 +357,7 @@ public class DownloadActivityType {
final int ind = basename.indexOf("addresses-nationwide"); final int ind = basename.indexOf("addresses-nationwide");
String downloadName = basename.substring(0, ind - 1) + basename.substring(ind + "addresses-nationwide".length()); String downloadName = basename.substring(0, ind - 1) + basename.substring(ind + "addresses-nationwide".length());
return osmandRegions.getLocaleName(downloadName, includingParent) + 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_")) { } else if (basename.startsWith("Depth_")) {
final int extInd = basename.indexOf("osmand_ext"); final int extInd = basename.indexOf("osmand_ext");
String downloadName = extInd == -1 ? basename.substring(6, basename.length()).replace('_', ' ') String downloadName = extInd == -1 ? basename.substring(6, basename.length()).replace('_', ' ')
@ -438,11 +438,11 @@ public class DownloadActivityType {
} }
if (this == HILLSHADE_FILE) { if (this == HILLSHADE_FILE) {
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()) return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length())
.replace(FileNameTranslationHelper.HILL_SHADE, ""); .replace(FileNameTranslationHelper.HILL_SHADE + "_", "");
} }
if (this == SLOPE_FILE) { if (this == SLOPE_FILE) {
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()) return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length())
.replace(FileNameTranslationHelper.SLOPE, ""); .replace(FileNameTranslationHelper.SLOPE + "_", "");
} }
if (fileName.endsWith(IndexConstants.SQLITE_EXT)) { if (fileName.endsWith(IndexConstants.SQLITE_EXT)) {
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()); return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length());

View file

@ -4,6 +4,7 @@ import android.content.Context;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadResources;
@ -18,10 +19,14 @@ import java.lang.reflect.Field;
public class FileNameTranslationHelper { public class FileNameTranslationHelper {
private static final Log LOG = PlatformUtil.getLog(FileNameTranslationHelper.class); private static final Log LOG = PlatformUtil.getLog(FileNameTranslationHelper.class);
public static final String WIKI_NAME = "_wiki"; public static final String WIKI_NAME = "_wiki";
public static final String HILL_SHADE = "Hillshade_"; public static final String HILL_SHADE = "Hillshade";
public static final String SLOPE = "Slope_"; public static final String SLOPE = "Slope";
public static final String SEA_DEPTH = "Depth_"; 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) { public static String getFileName(Context ctx, OsmandRegions regions, String fileName) {
String basename = getBasename(fileName); String basename = getBasename(fileName);
if (basename.endsWith(WIKI_NAME)) { //wiki files if (basename.endsWith(WIKI_NAME)) { //wiki files
@ -30,13 +35,15 @@ public class FileNameTranslationHelper {
return getVoiceName(ctx, fileName); return getVoiceName(ctx, fileName);
} else if (fileName.endsWith(IndexConstants.FONT_INDEX_EXT)) { //otf files } else if (fileName.endsWith(IndexConstants.FONT_INDEX_EXT)) { //otf files
return getFontName(ctx, basename); 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); return getTerrainName(ctx, regions, basename, R.string.download_hillshade_maps);
} else if (fileName.startsWith(SLOPE)) { } else if (fileName.startsWith(SLOPE)) {
basename = basename.replace(SLOPE + " ", "");
return getTerrainName(ctx, regions, basename, R.string.download_slope_maps); return getTerrainName(ctx, regions, basename, R.string.download_slope_maps);
} else if (fileName.length() == 2) { //voice recorded files } else if (fileName.length() == 2) { //voice recorded files
try { try {
Field f = R.string.class.getField("lang_"+fileName); Field f = R.string.class.getField("lang_" + fileName);
if (f != null) { if (f != null) {
Integer in = (Integer) f.get(null); Integer in = (Integer) f.get(null);
return ctx.getString(in); return ctx.getString(in);
@ -62,9 +69,10 @@ public class FileNameTranslationHelper {
public static String getTerrainName(Context ctx, OsmandRegions regions, String basename, public static String getTerrainName(Context ctx, OsmandRegions regions, String basename,
int terrainNameRes) { int terrainNameRes) {
String terrain = ctx.getString(terrainNameRes) + " "; basename = basename.replace(" ", "_");
String terrain = ctx.getString(terrainNameRes);
String locName = regions.getLocaleName(basename.trim(), true); 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){ public static String getWikiName(Context ctx, String basename){

View file

@ -7,7 +7,9 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Collator;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.OsmAndCollator;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.map.ITileSource; 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.audionotes.AudioVideoNotesPlugin.Recording;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; 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;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OpenstreetmapPoint;
@ -42,6 +45,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -542,6 +547,7 @@ public class SettingsHelper {
files = getFilesByType(localIndexInfoList, LocalIndexType.MAP_DATA, LocalIndexType.TILES_DATA, files = getFilesByType(localIndexInfoList, LocalIndexType.MAP_DATA, LocalIndexType.TILES_DATA,
LocalIndexType.SRTM_DATA, LocalIndexType.WIKI_DATA); LocalIndexType.SRTM_DATA, LocalIndexType.WIKI_DATA);
if (!files.isEmpty()) { if (!files.isEmpty()) {
sortData(files);
dataList.put(ExportSettingsType.OFFLINE_MAPS, files); dataList.put(ExportSettingsType.OFFLINE_MAPS, files);
} }
files = getFilesByType(localIndexInfoList, LocalIndexType.TTS_VOICE_DATA); files = getFilesByType(localIndexInfoList, LocalIndexType.TTS_VOICE_DATA);
@ -801,4 +807,18 @@ public class SettingsHelper {
} }
return settingsToOperate; return settingsToOperate;
} }
public void sortData(List<File> files) {
final Collator collator = OsmAndCollator.primaryCollator();
Collections.sort(files, new Comparator<File>() {
@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());
}
});
}
} }