Search in sources :

Example 1 with SettingsItem

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);
            }
        }
    }
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) DataSettingsItem(net.osmand.plus.settings.backend.backup.items.DataSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) ResourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.ResourcesSettingsItem) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem)

Example 2 with SettingsItem

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;
}
Also used : SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) DataSettingsItem(net.osmand.plus.settings.backend.backup.items.DataSettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) ResourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.ResourcesSettingsItem) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) DownloadsItem(net.osmand.plus.settings.backend.backup.items.DownloadsItem) SuggestedDownloadsItem(net.osmand.plus.settings.backend.backup.items.SuggestedDownloadsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) DataSettingsItem(net.osmand.plus.settings.backend.backup.items.DataSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) ResourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.ResourcesSettingsItem) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) SuggestedDownloadsItem(net.osmand.plus.settings.backend.backup.items.SuggestedDownloadsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) Nullable(androidx.annotation.Nullable)

Example 3 with SettingsItem

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;
}
Also used : ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) ApplicationModeBean(net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean) FavoritesSettingsItem(net.osmand.plus.settings.backend.backup.items.FavoritesSettingsItem) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) SearchHistorySettingsItem(net.osmand.plus.settings.backend.backup.items.SearchHistorySettingsItem) GpxSettingsItem(net.osmand.plus.settings.backend.backup.items.GpxSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) HistoryMarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.HistoryMarkersSettingsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) ItinerarySettingsItem(net.osmand.plus.settings.backend.backup.items.ItinerarySettingsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) OsmEditsSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmEditsSettingsItem) OsmNotesSettingsItem(net.osmand.plus.settings.backend.backup.items.OsmNotesSettingsItem) MarkersSettingsItem(net.osmand.plus.settings.backend.backup.items.MarkersSettingsItem) GlobalSettingsItem(net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) OnlineRoutingSettingsItem(net.osmand.plus.settings.backend.backup.items.OnlineRoutingSettingsItem) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) Nullable(androidx.annotation.Nullable)

Example 4 with SettingsItem

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;
}
Also used : JSONObject(org.json.JSONObject) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) JSONArray(org.json.JSONArray) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with SettingsItem

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;
            }
        }
    }
}
Also used : ZipFile(java.util.zip.ZipFile) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) ZipEntry(java.util.zip.ZipEntry)

Aggregations

SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)37 ArrayList (java.util.ArrayList)19 FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)18 File (java.io.File)11 List (java.util.List)11 IOException (java.io.IOException)10 GpxSettingsItem (net.osmand.plus.settings.backend.backup.items.GpxSettingsItem)10 ProfileSettingsItem (net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem)10 NonNull (androidx.annotation.NonNull)8 AvoidRoadsSettingsItem (net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem)7 MapSourcesSettingsItem (net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem)7 PoiUiFiltersSettingsItem (net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem)7 QuickActionsSettingsItem (net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem)7 Nullable (androidx.annotation.Nullable)6 HashMap (java.util.HashMap)6 PluginSettingsItem (net.osmand.plus.settings.backend.backup.items.PluginSettingsItem)6 HashSet (java.util.HashSet)5 FileInputStream (java.io.FileInputStream)4 FragmentActivity (androidx.fragment.app.FragmentActivity)3 Map (java.util.Map)3