From fa4aa8fde5355071f25d5471cde32ac9a90e819d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 8 Jan 2021 00:18:12 +0200 Subject: [PATCH 1/2] Add export and import of online routing --- OsmAnd/res/values/strings.xml | 2 + .../onlinerouting/OnlineRoutingEngine.java | 16 +- .../OnlineRoutingEngineFragment.java | 10 +- .../onlinerouting/OnlineRoutingHelper.java | 69 ++++----- .../settings/backend/ExportSettingsType.java | 5 +- .../plus/settings/backend/OsmandSettings.java | 3 +- .../backup/OnlineRoutingSettingsItem.java | 142 ++++++++++++++++++ .../backend/backup/SettingsHelper.java | 19 +++ .../backend/backup/SettingsItemType.java | 3 +- .../backend/backup/SettingsItemsFactory.java | 3 + .../fragments/DuplicatesSettingsAdapter.java | 4 + .../fragments/ExportItemsBottomSheet.java | 5 + .../fragments/ImportDuplicatesFragment.java | 8 + .../fragments/ImportSettingsFragment.java | 9 ++ .../ImportedSettingsItemsAdapter.java | 7 +- 15 files changed, 249 insertions(+), 56 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 4991659469..47645eb555 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,8 @@ --> + Online routing engines + Online routing engine Copy address Error, recheck parameters Car diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingEngine.java b/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingEngine.java index 10ba169cb1..aae11a39b9 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingEngine.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingEngine.java @@ -3,6 +3,7 @@ package net.osmand.plus.onlinerouting; import android.content.Context; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import net.osmand.plus.R; import net.osmand.util.Algorithms; @@ -26,11 +27,13 @@ public class OnlineRoutingEngine { private Map params = new HashMap<>(); public OnlineRoutingEngine(@NonNull String stringKey, - @NonNull ServerType serverType, - @NonNull String vehicleKey, - Map params) { + @NonNull ServerType serverType, + @NonNull String vehicleKey, + @Nullable Map params) { this(stringKey, serverType, vehicleKey); - this.params = params; + if (!Algorithms.isEmpty(params)) { + this.params.putAll(params); + } } public OnlineRoutingEngine(@NonNull String stringKey, @@ -96,8 +99,9 @@ public class OnlineRoutingEngine { } public static OnlineRoutingEngine createNewEngine(@NonNull ServerType serverType, - @NonNull String vehicleKey) { - return new OnlineRoutingEngine(generateKey(), serverType, vehicleKey); + @NonNull String vehicleKey, + @Nullable Map params) { + return new OnlineRoutingEngine(generateKey(), serverType, vehicleKey, params); } private static String generateKey() { diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingEngineFragment.java b/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingEngineFragment.java index 18b24a8762..46e47bc8f2 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingEngineFragment.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingEngineFragment.java @@ -132,8 +132,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, - @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { view = getInflater().inflate( R.layout.online_routing_engine_fragment, container, false); segmentsContainer = (ViewGroup) view.findViewById(R.id.segments_container); @@ -402,7 +402,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { if (isEditingMode()) { engineToSave = new OnlineRoutingEngine(editedEngineKey, engine.serverType, engine.getVehicleKey()); } else { - engineToSave = OnlineRoutingEngine.createNewEngine(engine.serverType, engine.getVehicleKey()); + engineToSave = OnlineRoutingEngine.createNewEngine(engine.serverType, engine.getVehicleKey(), null); } engineToSave.putParameter(EngineParameterType.CUSTOM_SERVER_URL, engine.customServerUrl); @@ -568,8 +568,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { } public static void showInstance(@NonNull FragmentActivity activity, - @NonNull ApplicationMode appMode, - String editedEngineKey) { + @NonNull ApplicationMode appMode, + String editedEngineKey) { FragmentManager fm = activity.getSupportFragmentManager(); if (!fm.isStateSaved() && fm.findFragmentByTag(OnlineRoutingEngineFragment.TAG) == null) { OnlineRoutingEngineFragment fragment = new OnlineRoutingEngineFragment(); diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingHelper.java b/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingHelper.java index 8a9e42bd54..54a5467bc1 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingHelper.java @@ -91,7 +91,7 @@ public class OnlineRoutingHelper { JSONObject json = new JSONObject(jsonString); readFromJson(json, engines); } catch (JSONException e) { - LOG.debug("Error when create a new JSONObject: " + e.toString()); + LOG.debug("Error when reading engines from JSON ", e); } } return engines; @@ -99,57 +99,50 @@ public class OnlineRoutingHelper { private void saveToSettings() { if (!Algorithms.isEmpty(cachedEngines)) { - JSONObject json = new JSONObject(); - if (writeToJson(json, cachedEngines)) { + try { + JSONObject json = new JSONObject(); + writeToJson(json, cachedEngines); settings.ONLINE_ROUTING_ENGINES.set(json.toString()); + } catch (JSONException e) { + LOG.debug("Error when writing engines to JSON ", e); } } else { settings.ONLINE_ROUTING_ENGINES.set(null); } } - private static void readFromJson(JSONObject json, List engines) { - try { - if (!json.has("items")) { - return; - } - Gson gson = new Gson(); - Type type = new TypeToken>() { - }.getType(); - JSONArray itemsJson = json.getJSONArray("items"); - for (int i = 0; i < itemsJson.length(); i++) { - JSONObject object = itemsJson.getJSONObject(i); - String key = object.getString("key"); - String vehicleKey = object.getString("vehicle"); - ServerType serverType = ServerType.valueOf(object.getString("serverType")); - String paramsString = object.getString("params"); - HashMap params = gson.fromJson(paramsString, type); - engines.add(new OnlineRoutingEngine(key, serverType, vehicleKey, params)); - } - } catch (JSONException e) { - LOG.debug("Error when reading engines from JSON: " + e.toString()); + public static void readFromJson(JSONObject json, List engines) throws JSONException { + if (!json.has("items")) { + return; + } + Gson gson = new Gson(); + Type type = new TypeToken>() { + }.getType(); + JSONArray itemsJson = json.getJSONArray("items"); + for (int i = 0; i < itemsJson.length(); i++) { + JSONObject object = itemsJson.getJSONObject(i); + String key = object.getString("key"); + String vehicleKey = object.getString("vehicle"); + ServerType serverType = ServerType.valueOf(object.getString("serverType")); + String paramsString = object.getString("params"); + HashMap params = gson.fromJson(paramsString, type); + engines.add(new OnlineRoutingEngine(key, serverType, vehicleKey, params)); } } - private static boolean writeToJson(JSONObject json, List engines) { + public static void writeToJson(JSONObject json, List engines) throws JSONException { JSONArray jsonArray = new JSONArray(); Gson gson = new Gson(); Type type = new TypeToken>() { }.getType(); - try { - for (OnlineRoutingEngine engine : engines) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("key", engine.getStringKey()); - jsonObject.put("serverType", engine.getServerType().name()); - jsonObject.put("vehicle", engine.getVehicleKey()); - jsonObject.put("params", gson.toJson(engine.getParams(), type)); - jsonArray.put(jsonObject); - } - json.put("items", jsonArray); - return true; - } catch (JSONException e) { - LOG.debug("Error when writing engines to JSON: " + e.toString()); - return false; + for (OnlineRoutingEngine engine : engines) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("key", engine.getStringKey()); + jsonObject.put("serverType", engine.getServerType().name()); + jsonObject.put("vehicle", engine.getVehicleKey()); + jsonObject.put("params", gson.toJson(engine.getParams(), type)); + jsonArray.put(jsonObject); } + json.put("items", jsonArray); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java index c3b1e63a75..7ee75c4092 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java @@ -24,7 +24,8 @@ public enum ExportSettingsType { MAP_SOURCES(R.string.quick_action_map_source_title, R.drawable.ic_map), OFFLINE_MAPS(R.string.shared_string_maps, R.drawable.ic_map), TTS_VOICE(R.string.local_indexes_cat_tts, R.drawable.ic_action_volume_up), - VOICE(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up); + VOICE(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up), + ONLINE_ROUTING_ENGINES(R.string.online_routing_engines, R.drawable.ic_world_globe_dark); @StringRes private final int titleId; @@ -59,6 +60,6 @@ public enum ExportSettingsType { public boolean isResourcesCategory() { return this == CUSTOM_RENDER_STYLE || this == CUSTOM_ROUTING || this == MAP_SOURCES - || this == OFFLINE_MAPS || this == VOICE || this == TTS_VOICE; + || this == OFFLINE_MAPS || this == VOICE || this == TTS_VOICE || this == ONLINE_ROUTING_ENGINES; } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index efaaff576b..dfaaea9468 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -48,7 +48,6 @@ import net.osmand.plus.helpers.enums.TracksSortByMode; import net.osmand.plus.mapillary.MapillaryPlugin; import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format; import net.osmand.plus.mapmarkers.MapMarkersMode; -import net.osmand.plus.onlinerouting.OnlineRoutingEngine; import net.osmand.plus.profiles.LocationIcon; import net.osmand.plus.profiles.NavigationIcon; import net.osmand.plus.profiles.ProfileIconColors; @@ -1016,7 +1015,7 @@ public class OsmandSettings { ROUTE_SERVICE.setModeDefaultValue(ApplicationMode.AIRCRAFT, RouteService.STRAIGHT); } - public final CommonPreference ONLINE_ROUTING_ENGINES = new StringPreference(this, "online_routing_engines", null); + public final CommonPreference ONLINE_ROUTING_ENGINES = new StringPreference(this, "online_routing_engines", null).makeGlobal(); public final CommonPreference NAVIGATION_ICON = new EnumStringPreference<>(this, "navigation_icon", NavigationIcon.DEFAULT, NavigationIcon.values()).makeProfile().cache(); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java new file mode 100644 index 0000000000..19f29daafe --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java @@ -0,0 +1,142 @@ +package net.osmand.plus.settings.backend.backup; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.onlinerouting.OnlineRoutingEngine; +import net.osmand.plus.onlinerouting.OnlineRoutingEngine.EngineParameterType; +import net.osmand.plus.onlinerouting.OnlineRoutingHelper; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class OnlineRoutingSettingsItem extends CollectionSettingsItem { + + private OnlineRoutingHelper onlineRoutingHelper; + + public OnlineRoutingSettingsItem(@NonNull OsmandApplication app, @NonNull List items) { + super(app, null, items); + } + + public OnlineRoutingSettingsItem(@NonNull OsmandApplication app, @Nullable OnlineRoutingSettingsItem baseItem, @NonNull List items) { + super(app, baseItem, items); + } + + public OnlineRoutingSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException { + super(app, json); + } + + @Override + protected void init() { + super.init(); + onlineRoutingHelper = app.getOnlineRoutingHelper(); + existingItems = new ArrayList<>(onlineRoutingHelper.getEngines()); + } + + @NonNull + @Override + public SettingsItemType getType() { + return SettingsItemType.ONLINE_ROUTING_ENGINES; + } + + @NonNull + @Override + public String getName() { + return "online_routing_engines"; + } + + @NonNull + @Override + public String getPublicName(@NonNull Context ctx) { + return ctx.getString(R.string.online_routing_engine); + } + + @Override + public void apply() { + List newItems = getNewItems(); + if (!newItems.isEmpty() || !duplicateItems.isEmpty()) { + appliedItems = new ArrayList<>(newItems); + + for (OnlineRoutingEngine duplicate : duplicateItems) { + if (shouldReplace) { + onlineRoutingHelper.deleteEngine(duplicate.getStringKey()); + } + appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate)); + } + for (OnlineRoutingEngine engine : appliedItems) { + onlineRoutingHelper.saveEngine(engine); + } + } + } + + @Override + public boolean isDuplicate(@NonNull OnlineRoutingEngine routingEngine) { + for (OnlineRoutingEngine engine : existingItems) { + if (engine.getStringKey().equals(routingEngine.getStringKey()) + || engine.getName(app).equals(routingEngine.getName(app))) { + return true; + } + } + return false; + } + + @Override + public boolean shouldReadOnCollecting() { + return true; + } + + @NonNull + @Override + public OnlineRoutingEngine renameItem(@NonNull OnlineRoutingEngine item) { + int number = 0; + while (true) { + number++; + OnlineRoutingEngine renamedItem = OnlineRoutingEngine.createNewEngine(item.getServerType(), item.getVehicleKey(), item.getParams()); + renamedItem.putParameter(EngineParameterType.CUSTOM_NAME, renamedItem.getName(app) + "_" + number); + if (!isDuplicate(renamedItem)) { + return renamedItem; + } + } + } + + @Override + void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException { + try { + OnlineRoutingHelper.readFromJson(json, items); + } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType()))); + throw new IllegalArgumentException("Json parse error", e); + } + } + + @Override + void writeItemsToJson(@NonNull JSONObject json) { + if (!items.isEmpty()) { + try { + OnlineRoutingHelper.writeToJson(json, items); + } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType()))); + SettingsHelper.LOG.error("Failed write to json", e); + } + } + } + + @Nullable + @Override + SettingsItemReader getReader() { + return getJsonReader(); + } + + @Nullable + @Override + SettingsItemWriter getWriter() { + return getJsonWriter(); + } +} diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 69ac3b1a13..afe3a9c9ec 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -33,6 +33,7 @@ import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.onlinerouting.OnlineRoutingEngine; import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmNotesPoint; @@ -624,6 +625,10 @@ public class SettingsHelper { resourcesItems.put(ExportSettingsType.CUSTOM_ROUTING, Arrays.asList(fl)); } } + List onlineRoutingEngines = app.getOnlineRoutingHelper().getEngines(); + if (!Algorithms.isEmpty(onlineRoutingEngines)) { + resourcesItems.put(ExportSettingsType.ONLINE_ROUTING_ENGINES, onlineRoutingEngines); + } List iTileSources = new ArrayList<>(); Set tileSourceNames = app.getSettings().getTileSourceEntries(true).keySet(); for (String name : tileSourceNames) { @@ -701,6 +706,7 @@ public class SettingsHelper { List markersGroups = new ArrayList<>(); List markersHistoryGroups = new ArrayList<>(); List historyEntries = new ArrayList<>(); + List onlineRoutingEngines = new ArrayList<>(); for (Object object : data) { if (object instanceof QuickAction) { @@ -741,6 +747,8 @@ public class SettingsHelper { historyEntries.add((HistoryEntry) object); } else if (object instanceof GlobalSettingsItem) { settingsItems.add((GlobalSettingsItem) object); + } else if (object instanceof OnlineRoutingEngine) { + onlineRoutingEngines.add((OnlineRoutingEngine) object); } } if (!quickActions.isEmpty()) { @@ -793,6 +801,9 @@ public class SettingsHelper { if (!historyEntries.isEmpty()) { settingsItems.add(new SearchHistorySettingsItem(app, historyEntries)); } + if (!onlineRoutingEngines.isEmpty()) { + settingsItems.add(new OnlineRoutingSettingsItem(app, onlineRoutingEngines)); + } return settingsItems; } @@ -848,6 +859,7 @@ public class SettingsHelper { List markersGroups = new ArrayList<>(); List markersHistoryGroups = new ArrayList<>(); List historyEntries = new ArrayList<>(); + List onlineRoutingEngines = new ArrayList<>(); for (SettingsItem item : settingsItems) { switch (item.getType()) { @@ -942,6 +954,10 @@ public class SettingsHelper { case GPX: tracksFilesList.add((GpxSettingsItem) item); break; + case ONLINE_ROUTING_ENGINES: + OnlineRoutingSettingsItem onlineRoutingSettingsItem = (OnlineRoutingSettingsItem) item; + onlineRoutingEngines.addAll(onlineRoutingSettingsItem.getItems()); + break; default: break; } @@ -1004,6 +1020,9 @@ public class SettingsHelper { if (!historyEntries.isEmpty()) { settingsToOperate.put(ExportSettingsType.SEARCH_HISTORY, historyEntries); } + if (!onlineRoutingEngines.isEmpty()) { + settingsToOperate.put(ExportSettingsType.ONLINE_ROUTING_ENGINES, onlineRoutingEngines); + } return settingsToOperate; } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java index 9af8424ffc..de002efff4 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java @@ -19,5 +19,6 @@ public enum SettingsItemType { FAVOURITES, ACTIVE_MARKERS, HISTORY_MARKERS, - SEARCH_HISTORY + SEARCH_HISTORY, + ONLINE_ROUTING_ENGINES } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java index 39846f1826..47cee4b0fc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java @@ -146,6 +146,9 @@ class SettingsItemsFactory { case GPX: item = new GpxSettingsItem(app, json); break; + case ONLINE_ROUTING_ENGINES: + item = new OnlineRoutingSettingsItem(app, json); + break; } return item; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java index fc6982a7a6..575dc74db2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/DuplicatesSettingsAdapter.java @@ -23,6 +23,7 @@ import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.mapmarkers.MapMarker; +import net.osmand.plus.onlinerouting.OnlineRoutingEngine; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.profiles.ProfileIconColors; import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources; @@ -163,6 +164,9 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter mapMarkers = new ArrayList<>(); List mapMarkersGroups = new ArrayList<>(); List historyEntries = new ArrayList<>(); + List onlineRoutingEngines = new ArrayList<>(); for (Object object : duplicatesList) { if (object instanceof ApplicationMode.ApplicationModeBean) { @@ -250,6 +252,8 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment { } } else if (object instanceof HistoryEntry) { historyEntries.add((HistoryEntry) object); + } else if (object instanceof OnlineRoutingEngine) { + onlineRoutingEngines.add((OnlineRoutingEngine) object); } } if (!profiles.isEmpty()) { @@ -320,6 +324,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment { duplicates.add(getString(R.string.markers_history)); duplicates.addAll(mapMarkersGroups); } + if (!onlineRoutingEngines.isEmpty()) { + duplicates.add(getString(R.string.online_routing_engines)); + duplicates.addAll(onlineRoutingEngines); + } return duplicates; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 2d7d50046d..970acb24bc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -36,6 +36,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.onlinerouting.OnlineRoutingEngine; import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.poi.PoiUIFilter; @@ -50,6 +51,7 @@ import net.osmand.plus.settings.backend.backup.GpxSettingsItem; import net.osmand.plus.settings.backend.backup.HistoryMarkersSettingsItem; import net.osmand.plus.settings.backend.backup.MapSourcesSettingsItem; import net.osmand.plus.settings.backend.backup.MarkersSettingsItem; +import net.osmand.plus.settings.backend.backup.OnlineRoutingSettingsItem; import net.osmand.plus.settings.backend.backup.OsmEditsSettingsItem; import net.osmand.plus.settings.backend.backup.OsmNotesSettingsItem; import net.osmand.plus.settings.backend.backup.PoiUiFiltersSettingsItem; @@ -347,6 +349,7 @@ public class ImportSettingsFragment extends BaseSettingsListFragment { List markersGroups = new ArrayList<>(); List markersHistoryGroups = new ArrayList<>(); List historyEntries = new ArrayList<>(); + List onlineRoutingEngines = new ArrayList<>(); for (Object object : data) { if (object instanceof ApplicationModeBean) { appModeBeans.add((ApplicationModeBean) object); @@ -384,6 +387,8 @@ public class ImportSettingsFragment extends BaseSettingsListFragment { } } else if (object instanceof HistoryEntry) { historyEntries.add((HistoryEntry) object); + } else if (object instanceof OnlineRoutingEngine) { + onlineRoutingEngines.add((OnlineRoutingEngine) object); } } if (!appModeBeans.isEmpty()) { @@ -435,6 +440,10 @@ public class ImportSettingsFragment extends BaseSettingsListFragment { SearchHistorySettingsItem baseItem = getBaseItem(SettingsItemType.SEARCH_HISTORY, SearchHistorySettingsItem.class); settingsItems.add(new SearchHistorySettingsItem(app, baseItem, historyEntries)); } + if (!onlineRoutingEngines.isEmpty()) { + OnlineRoutingSettingsItem baseItem = getBaseItem(SettingsItemType.ONLINE_ROUTING_ENGINES, OnlineRoutingSettingsItem.class); + settingsItems.add(new OnlineRoutingSettingsItem(app, baseItem, onlineRoutingEngines)); + } return settingsItems; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java index 94228d4945..b8f8d31d82 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java @@ -16,7 +16,6 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.settings.backend.ExportSettingsType; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -33,7 +32,7 @@ public class ImportedSettingsItemsAdapter extends private OnItemClickListener listener; ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, Map> itemsMap, - boolean nightMode, OnItemClickListener listener) { + boolean nightMode, OnItemClickListener listener) { this.app = app; this.itemsMap = itemsMap; this.nightMode = nightMode; @@ -154,6 +153,10 @@ public class ImportedSettingsItemsAdapter extends holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_history, activeColorRes)); holder.title.setText(R.string.shared_string_search_history); break; + case ONLINE_ROUTING_ENGINES: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_world_globe_dark, activeColorRes)); + holder.title.setText(R.string.online_routing_engines); + break; } } From d0d95e92cca1ca45d36764e713fd452daf4c1098 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 8 Jan 2021 00:34:09 +0200 Subject: [PATCH 2/2] Fix ImportCompleteFragment and remove duplicated code --- .../backup/AvoidRoadsSettingsItem.java | 5 -- .../backup/CollectionSettingsItem.java | 5 ++ .../backend/backup/FavoritesSettingsItem.java | 5 -- .../backup/HistoryMarkersSettingsItem.java | 5 -- .../backup/MapSourcesSettingsItem.java | 5 -- .../backend/backup/MarkersSettingsItem.java | 5 -- .../backup/OnlineRoutingSettingsItem.java | 5 -- .../backend/backup/OsmEditsSettingsItem.java | 5 -- .../backend/backup/OsmNotesSettingsItem.java | 5 -- .../backup/PoiUiFiltersSettingsItem.java | 5 -- .../backup/QuickActionsSettingsItem.java | 5 -- .../backup/SearchHistorySettingsItem.java | 5 -- .../fragments/ImportCompleteFragment.java | 48 +++++++++++++------ 13 files changed, 38 insertions(+), 70 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java index a65a60b2d7..6f53a11b07 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/AvoidRoadsSettingsItem.java @@ -92,11 +92,6 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem extends SettingsItem { return true; } + @Override + public boolean shouldReadOnCollecting() { + return true; + } + public abstract boolean isDuplicate(@NonNull T item); @NonNull diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FavoritesSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FavoritesSettingsItem.java index acb96be110..515b9885c7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FavoritesSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FavoritesSettingsItem.java @@ -109,11 +109,6 @@ public class FavoritesSettingsItem extends CollectionSettingsItem return false; } - @Override - public boolean shouldReadOnCollecting() { - return true; - } - @NonNull @Override public FavoriteGroup renameItem(@NonNull FavoriteGroup item) { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java index 9f441b7ec8..ba0c3d7dc0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java @@ -103,11 +103,6 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem return "map_sources"; } - @Override - public boolean shouldReadOnCollecting() { - return true; - } - @Override void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException { try { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/MarkersSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/MarkersSettingsItem.java index 0698846638..daa6b9b485 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/MarkersSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/MarkersSettingsItem.java @@ -103,11 +103,6 @@ public class MarkersSettingsItem extends CollectionSettingsItem { return false; } - @Override - public boolean shouldReadOnCollecting() { - return true; - } - @NonNull @Override public MapMarker renameItem(@NonNull MapMarker item) { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java index 19f29daafe..e5ae306cf0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java @@ -87,11 +87,6 @@ public class OnlineRoutingSettingsItem extends CollectionSettingsItem return ctx.getString(R.string.osm_notes); } - @Override - public boolean shouldReadOnCollecting() { - return true; - } - @Override public boolean shouldShowDuplicates() { return false; diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/PoiUiFiltersSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/PoiUiFiltersSettingsItem.java index 29e20679d9..16be1f26bc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/PoiUiFiltersSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/PoiUiFiltersSettingsItem.java @@ -105,11 +105,6 @@ public class PoiUiFiltersSettingsItem extends CollectionSettingsItem