diff --git a/OsmAnd/src/net/osmand/plus/CustomRegion.java b/OsmAnd/src/net/osmand/plus/CustomRegion.java index fc433a7a5e..74ea704bd8 100644 --- a/OsmAnd/src/net/osmand/plus/CustomRegion.java +++ b/OsmAnd/src/net/osmand/plus/CustomRegion.java @@ -39,6 +39,8 @@ public class CustomRegion extends WorldRegion { private JSONArray downloadItemsJson; + private DynamicDownloadItems dynamicDownloadItems; + private DownloadDescriptionInfo descriptionInfo; private Map names = new HashMap<>(); @@ -103,6 +105,11 @@ public class CustomRegion extends WorldRegion { region.downloadItemsJson = object.optJSONArray("items"); + JSONObject urlItemsJson = object.optJSONObject("items-url"); + if (urlItemsJson != null) { + region.dynamicDownloadItems = DynamicDownloadItems.fromJson(urlItemsJson); + } + String headerColor = object.optString("header-color", null); try { region.headerColor = Algorithms.isEmpty(headerColor) ? 0 : Algorithms.parseColor(headerColor); @@ -130,7 +137,9 @@ public class CustomRegion extends WorldRegion { jsonObject.putOpt("description", descriptionInfo.toJson()); } jsonObject.putOpt("items", downloadItemsJson); - + if (dynamicDownloadItems != null) { + jsonObject.putOpt("items-url", dynamicDownloadItems.toJson()); + } return jsonObject; } @@ -182,4 +191,50 @@ public class CustomRegion extends WorldRegion { } return items; } + + public static class DynamicDownloadItems { + + private String url; + private String format; + private String itemsPath; + private JSONObject mapping; + + public String getUrl() { + return url; + } + + public String getFormat() { + return format; + } + + public String getItemsPath() { + return itemsPath; + } + + public JSONObject getMapping() { + return mapping; + } + + public static DynamicDownloadItems fromJson(JSONObject object) { + DynamicDownloadItems dynamicDownloadItems = new DynamicDownloadItems(); + + dynamicDownloadItems.url = object.optString("url", null); + dynamicDownloadItems.format = object.optString("format", null); + dynamicDownloadItems.itemsPath = object.optString("items-path", null); + dynamicDownloadItems.mapping = object.optJSONObject("mapping"); + + return dynamicDownloadItems; + } + + public JSONObject toJson() throws JSONException { + JSONObject jsonObject = new JSONObject(); + + jsonObject.putOpt("url", url); + jsonObject.putOpt("format", format); + jsonObject.putOpt("items-path", itemsPath); + jsonObject.putOpt("mapping", mapping); + + return jsonObject; + } + } } \ No newline at end of file