use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class SettingsItemsFactory method collectItems.
private void collectItems(JSONObject json) throws IllegalArgumentException, JSONException {
JSONArray itemsJson = json.getJSONArray("items");
int version = json.has("version") ? json.getInt("version") : 1;
if (version > SettingsHelper.VERSION) {
throw new IllegalArgumentException("Unsupported osf version: " + version);
}
Map<String, List<SettingsItem>> pluginItems = new HashMap<>();
for (int i = 0; i < itemsJson.length(); i++) {
JSONObject itemJson = itemsJson.getJSONObject(i);
SettingsItem item;
try {
item = createItem(itemJson);
// unknown type
if (item == null) {
continue;
}
items.add(item);
String pluginId = item.getPluginId();
if (pluginId != null && item.getType() != SettingsItemType.PLUGIN) {
List<SettingsItem> items = pluginItems.get(pluginId);
if (items != null) {
items.add(item);
} else {
items = new ArrayList<>();
items.add(item);
pluginItems.put(pluginId, items);
}
}
} catch (IllegalArgumentException e) {
SettingsHelper.LOG.error("Error creating item from json: " + itemJson, e);
}
}
for (SettingsItem item : items) {
if (item instanceof PluginSettingsItem) {
PluginSettingsItem pluginSettingsItem = ((PluginSettingsItem) item);
List<SettingsItem> pluginDependentItems = pluginItems.get(pluginSettingsItem.getName());
if (!Algorithms.isEmpty(pluginDependentItems)) {
pluginSettingsItem.getPluginDependentItems().addAll(pluginDependentItems);
}
}
}
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class SettingsItemsFactory method createItem.
@Nullable
private SettingsItem createItem(@NonNull JSONObject json) throws IllegalArgumentException, JSONException {
SettingsItem item = null;
SettingsItemType type = SettingsItem.parseItemType(json);
if (type == null) {
return null;
}
OsmandSettings settings = app.getSettings();
switch(type) {
case GLOBAL:
item = new GlobalSettingsItem(settings, json);
break;
case PROFILE:
item = new ProfileSettingsItem(app, json);
break;
case PLUGIN:
item = new PluginSettingsItem(app, json);
break;
case DATA:
item = new DataSettingsItem(app, json);
break;
case FILE:
item = new FileSettingsItem(app, json);
break;
case RESOURCES:
item = new ResourcesSettingsItem(app, json);
break;
case QUICK_ACTIONS:
item = new QuickActionsSettingsItem(app, json);
break;
case POI_UI_FILTERS:
item = new PoiUiFiltersSettingsItem(app, json);
break;
case MAP_SOURCES:
item = new MapSourcesSettingsItem(app, json);
break;
case AVOID_ROADS:
item = new AvoidRoadsSettingsItem(app, json);
break;
case SUGGESTED_DOWNLOADS:
item = new SuggestedDownloadsItem(app, json);
break;
case DOWNLOADS:
item = new DownloadsItem(app, json);
break;
case OSM_NOTES:
item = new OsmNotesSettingsItem(app, json);
break;
case OSM_EDITS:
item = new OsmEditsSettingsItem(app, json);
break;
case FAVOURITES:
item = new FavoritesSettingsItem(app, json);
break;
case ACTIVE_MARKERS:
item = new MarkersSettingsItem(app, json);
break;
case HISTORY_MARKERS:
item = new HistoryMarkersSettingsItem(app, json);
break;
case SEARCH_HISTORY:
item = new SearchHistorySettingsItem(app, json);
break;
case GPX:
item = new GpxSettingsItem(app, json);
break;
case ONLINE_ROUTING_ENGINES:
item = new OnlineRoutingSettingsItem(app, json);
break;
case ITINERARY_GROUPS:
item = new ItinerarySettingsItem(app, json);
break;
}
return item;
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class SettingsHelper method getBaseProfileSettingsItem.
@Nullable
private ProfileSettingsItem getBaseProfileSettingsItem(ApplicationModeBean modeBean, List<SettingsItem> settingsItems) {
for (SettingsItem settingsItem : settingsItems) {
if (settingsItem.getType() == SettingsItemType.PROFILE) {
ProfileSettingsItem profileItem = (ProfileSettingsItem) settingsItem;
ApplicationModeBean bean = profileItem.getModeBean();
if (Algorithms.objectEquals(bean.stringKey, modeBean.stringKey) && Algorithms.objectEquals(bean.userProfileName, modeBean.userProfileName)) {
return profileItem;
}
}
}
return null;
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class Exporter method createItemsJson.
protected JSONObject createItemsJson() throws JSONException {
JSONObject json = new JSONObject();
json.put("version", VERSION);
for (Map.Entry<String, String> param : additionalParams.entrySet()) {
json.put(param.getKey(), param.getValue());
}
JSONArray itemsJson = new JSONArray();
for (SettingsItem item : items) {
itemsJson.put(new JSONObject(item.toJson()));
}
json.put("items", itemsJson);
return json;
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class SettingsImporter method updateFilesInfo.
private void updateFilesInfo(@NonNull File file, List<SettingsItem> settingsItemList) throws IOException {
ZipFile zipfile = new ZipFile(file.getPath());
Enumeration<? extends ZipEntry> zipEnum = zipfile.entries();
while (zipEnum.hasMoreElements()) {
ZipEntry zipEntry = zipEnum.nextElement();
long size = zipEntry.getSize();
for (SettingsItem settingsItem : settingsItemList) {
if (settingsItem instanceof FileSettingsItem && zipEntry.getName().equals(settingsItem.getFileName())) {
FileSettingsItem fileSettingsItem = (FileSettingsItem) settingsItem;
fileSettingsItem.setSize(size);
fileSettingsItem.setLastModifiedTime(zipEntry.getTime());
break;
}
}
}
}
Aggregations