Add other subtype for file items
This commit is contained in:
parent
e5e6964c8a
commit
198cc5337a
1 changed files with 20 additions and 14 deletions
|
@ -970,6 +970,7 @@ public class SettingsHelper {
|
||||||
|
|
||||||
public enum FileSubtype {
|
public enum FileSubtype {
|
||||||
UNKNOWN("", null),
|
UNKNOWN("", null),
|
||||||
|
OTHER("other", ""),
|
||||||
ROUTING_CONFIG("routing_config", IndexConstants.ROUTING_PROFILES_DIR),
|
ROUTING_CONFIG("routing_config", IndexConstants.ROUTING_PROFILES_DIR),
|
||||||
RENDERING_STYLE("rendering_style", IndexConstants.RENDERERS_DIR),
|
RENDERING_STYLE("rendering_style", IndexConstants.RENDERERS_DIR),
|
||||||
OBF_MAP("obf_map", IndexConstants.MAPS_PATH),
|
OBF_MAP("obf_map", IndexConstants.MAPS_PATH),
|
||||||
|
@ -1037,20 +1038,16 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileSettingsItem(@NonNull OsmandApplication app, @NonNull FileSubtype subtype, @NonNull File file) throws IllegalArgumentException {
|
|
||||||
super(app, file.getPath().replace(app.getAppPath(null).getPath(), ""));
|
|
||||||
this.file = file;
|
|
||||||
this.appPath = app.getAppPath(null);
|
|
||||||
this.subtype = subtype;
|
|
||||||
if (subtype == FileSubtype.UNKNOWN) {
|
|
||||||
throw new IllegalArgumentException("Unknown file subtype: " + getFileName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
|
FileSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
|
||||||
super(app, json);
|
super(app, json);
|
||||||
this.appPath = app.getAppPath(null);
|
this.appPath = app.getAppPath(null);
|
||||||
this.file = new File(appPath, name);
|
if (subtype == FileSubtype.OTHER) {
|
||||||
|
this.file = new File(appPath, name);
|
||||||
|
} else if (subtype == FileSubtype.UNKNOWN || subtype == null) {
|
||||||
|
throw new IllegalArgumentException("Unknown file subtype: " + getFileName());
|
||||||
|
} else {
|
||||||
|
this.file = new File(app.getAppPath(subtype.subtypeFolder), name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -1071,9 +1068,6 @@ public class SettingsHelper {
|
||||||
void readFromJson(@NonNull JSONObject json) throws JSONException {
|
void readFromJson(@NonNull JSONObject json) throws JSONException {
|
||||||
super.readFromJson(json);
|
super.readFromJson(json);
|
||||||
String fileName = getFileName();
|
String fileName = getFileName();
|
||||||
if (!Algorithms.isEmpty(fileName)) {
|
|
||||||
name = fileName;
|
|
||||||
}
|
|
||||||
String subtypeStr = json.has("subtype") ? json.getString("subtype") : null;
|
String subtypeStr = json.has("subtype") ? json.getString("subtype") : null;
|
||||||
if (!Algorithms.isEmpty(subtypeStr)) {
|
if (!Algorithms.isEmpty(subtypeStr)) {
|
||||||
subtype = FileSubtype.getSubtypeByName(subtypeStr);
|
subtype = FileSubtype.getSubtypeByName(subtypeStr);
|
||||||
|
@ -1082,6 +1076,18 @@ public class SettingsHelper {
|
||||||
} else {
|
} else {
|
||||||
subtype = FileSubtype.UNKNOWN;
|
subtype = FileSubtype.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
if (!Algorithms.isEmpty(fileName)) {
|
||||||
|
if (subtype == FileSubtype.OTHER) {
|
||||||
|
name = fileName;
|
||||||
|
} else if (subtype != null && subtype != FileSubtype.UNKNOWN) {
|
||||||
|
int index = fileName.lastIndexOf(File.separator);
|
||||||
|
if (index != -1) {
|
||||||
|
name = fileName.substring(index);
|
||||||
|
} else {
|
||||||
|
name = fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue