From b2cd27f6a23732a7c1b7b30959c83d81a4247318 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 26 Mar 2020 10:03:57 +0200 Subject: [PATCH] Fix check for file subtype --- .../src/net/osmand/plus/SettingsHelper.java | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 5679f0e417..afa8e94f04 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -1010,12 +1010,20 @@ public class SettingsHelper { name = fileName.substring(1); } for (FileSubtype subtype : FileSubtype.values()) { - if (subtype == ROUTING_CONFIG || subtype == RENDERING_STYLE) { - if (name.startsWith(subtype.subtypeFolder) || name.startsWith(subtype.subtypeName)) { - return subtype; - } - } else if (subtype != UNKNOWN && name.startsWith(subtype.subtypeFolder)) { - return subtype; + switch (subtype) { + case UNKNOWN: + case OTHER: + break; + case OBF_MAP: + if (name.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { + return subtype; + } + break; + default: + if (name.startsWith(subtype.subtypeFolder)) { + return subtype; + } + break; } } return UNKNOWN; @@ -1029,7 +1037,7 @@ public class SettingsHelper { protected File file; private File appPath; - private FileSubtype subtype; + protected FileSubtype subtype; public FileSettingsItem(@NonNull OsmandApplication app, @NonNull File file) throws IllegalArgumentException { super(app, file.getPath().replace(app.getAppPath(null).getPath(), "")); @@ -1071,13 +1079,15 @@ public class SettingsHelper { void readFromJson(@NonNull JSONObject json) throws JSONException { super.readFromJson(json); String fileName = getFileName(); - String subtypeStr = json.has("subtype") ? json.getString("subtype") : null; - if (!Algorithms.isEmpty(subtypeStr)) { - subtype = FileSubtype.getSubtypeByName(subtypeStr); - } else if (!Algorithms.isEmpty(fileName)) { - subtype = FileSubtype.getSubtypeByFileName(fileName); - } else { - subtype = FileSubtype.UNKNOWN; + if (subtype == null) { + String subtypeStr = json.has("subtype") ? json.getString("subtype") : null; + if (!Algorithms.isEmpty(subtypeStr)) { + subtype = FileSubtype.getSubtypeByName(subtypeStr); + } else if (!Algorithms.isEmpty(fileName)) { + subtype = FileSubtype.getSubtypeByFileName(fileName); + } else { + subtype = FileSubtype.UNKNOWN; + } } if (!Algorithms.isEmpty(fileName)) { if (subtype == FileSubtype.OTHER) { @@ -1188,6 +1198,12 @@ public class SettingsHelper { return SettingsItemType.RESOURCES; } + @Override + void readFromJson(@NonNull JSONObject json) throws JSONException { + subtype = FileSubtype.OTHER; + super.readFromJson(json); + } + @Override public boolean applyFileName(@NonNull String fileName) { if (fileName.endsWith(File.separator)) {