From 3c919b6d199c04987b31e49e5ee7f8a11c50ca1d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 31 Mar 2020 15:36:33 +0300 Subject: [PATCH] Change importItems to appliedItems --- .../src/net/osmand/plus/SettingsHelper.java | 114 ++++++++---------- .../plus/settings/ImportCompleteFragment.java | 2 +- .../plus/settings/ImportSettingsFragment.java | 28 ++--- 3 files changed, 64 insertions(+), 80 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 9259ef0e90..546b41361f 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -436,14 +436,14 @@ public class SettingsHelper { public abstract static class CollectionSettingsItem extends SettingsItem { protected List items; - protected List importItems; + protected List appliedItems; protected List duplicateItems; protected List existingItems; @Override protected void init() { items = new ArrayList<>(); - importItems = new ArrayList<>(); + appliedItems = new ArrayList<>(); duplicateItems = new ArrayList<>(); } @@ -462,8 +462,8 @@ public class SettingsHelper { } @NonNull - public List getImportItems() { - return importItems; + public List getAppliedItems() { + return appliedItems; } @NonNull @@ -472,7 +472,7 @@ public class SettingsHelper { } @NonNull - public List excludeDuplicateItems() { + public List processDuplicateItems() { if (!items.isEmpty()) { for (T item : items) { if (isDuplicate(item)) { @@ -483,7 +483,11 @@ public class SettingsHelper { return duplicateItems; } - public abstract void processImportItems(); + public List getNewItems() { + List res = new ArrayList<>(items); + res.removeAll(duplicateItems); + return res; + } public abstract boolean isDuplicate(@NonNull T item); @@ -1324,16 +1328,11 @@ public class SettingsHelper { return actionRegistry.generateUniqueName(item, app); } - @Override - public void processImportItems() { - importItems.addAll(items); - importItems.removeAll(duplicateItems); - } - @Override public void apply() { - if (!items.isEmpty() || !duplicateItems.isEmpty()) { - processImportItems(); + List newItems = getNewItems(); + if (!newItems.isEmpty() || !duplicateItems.isEmpty()) { + appliedItems = new ArrayList<>(newItems); List newActions = new ArrayList<>(existingItems); if (!duplicateItems.isEmpty()) { if (shouldReplace) { @@ -1349,9 +1348,9 @@ public class SettingsHelper { renameItem(duplicateItem); } } - importItems.addAll(duplicateItems); + appliedItems.addAll(duplicateItems); } - newActions.addAll(importItems); + newActions.addAll(appliedItems); actionRegistry.updateQuickActions(newActions); } } @@ -1463,21 +1462,16 @@ public class SettingsHelper { return SettingsItemType.POI_UI_FILTERS; } - @Override - public void processImportItems() { - importItems.addAll(items); - importItems.removeAll(duplicateItems); - - for (PoiUIFilter duplicate : duplicateItems) { - importItems.add(shouldReplace ? duplicate : renameItem(duplicate)); - } - } - @Override public void apply() { - if (!items.isEmpty() || !duplicateItems.isEmpty()) { - processImportItems(); - for (PoiUIFilter filter : importItems) { + List newItems = getNewItems(); + if (!newItems.isEmpty() || !duplicateItems.isEmpty()) { + appliedItems = new ArrayList<>(newItems); + + for (PoiUIFilter duplicate : duplicateItems) { + appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate)); + } + for (PoiUIFilter filter : appliedItems) { app.getPoiFilters().createPoiFilter(filter, false); } app.getSearchUICore().refreshCustomPoiFilters(); @@ -1616,35 +1610,30 @@ public class SettingsHelper { } @Override - public void processImportItems() { - importItems.addAll(items); - importItems.removeAll(duplicateItems); - if (shouldReplace) { - for (ITileSource tileSource : duplicateItems) { - if (tileSource instanceof SQLiteTileSource) { - File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName() + IndexConstants.SQLITE_EXT); - if (f != null && f.exists() && Algorithms.removeAllFiles(f)) { - importItems.add(tileSource); - } - } else if (tileSource instanceof TileSourceManager.TileSourceTemplate) { - File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName()); - if (f != null && f.exists() && f.isDirectory() && Algorithms.removeAllFiles(f)) { - importItems.add(tileSource); + public void apply() { + List newItems = getNewItems(); + if (!newItems.isEmpty() || !duplicateItems.isEmpty()) { + appliedItems = new ArrayList<>(newItems); + if (shouldReplace) { + for (ITileSource tileSource : duplicateItems) { + if (tileSource instanceof SQLiteTileSource) { + File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName() + IndexConstants.SQLITE_EXT); + if (f != null && f.exists() && Algorithms.removeAllFiles(f)) { + appliedItems.add(tileSource); + } + } else if (tileSource instanceof TileSourceManager.TileSourceTemplate) { + File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName()); + if (f != null && f.exists() && f.isDirectory() && Algorithms.removeAllFiles(f)) { + appliedItems.add(tileSource); + } } } + } else { + for (ITileSource tileSource : duplicateItems) { + appliedItems.add(renameItem(tileSource)); + } } - } else { - for (ITileSource tileSource : duplicateItems) { - importItems.add(renameItem(tileSource)); - } - } - } - - @Override - public void apply() { - if (!items.isEmpty() || !duplicateItems.isEmpty()) { - processImportItems(); - for (ITileSource tileSource : importItems) { + for (ITileSource tileSource : appliedItems) { if (tileSource instanceof TileSourceManager.TileSourceTemplate) { app.getSettings().installTileSource((TileSourceManager.TileSourceTemplate) tileSource); } else if (tileSource instanceof SQLiteTileSource) { @@ -1834,16 +1823,11 @@ public class SettingsHelper { return "avoid_roads"; } - @Override - public void processImportItems() { - importItems.addAll(items); - importItems.removeAll(duplicateItems); - } - @Override public void apply() { - if (!items.isEmpty() || !duplicateItems.isEmpty()) { - processImportItems(); + List newItems = getNewItems(); + if (!newItems.isEmpty() || !duplicateItems.isEmpty()) { + appliedItems = new ArrayList<>(newItems); for (AvoidRoadInfo duplicate : duplicateItems) { if (shouldReplace) { LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude); @@ -1854,7 +1838,7 @@ public class SettingsHelper { settings.addImpassableRoad(renameItem(duplicate)); } } - for (AvoidRoadInfo avoidRoad : importItems) { + for (AvoidRoadInfo avoidRoad : appliedItems) { settings.addImpassableRoad(avoidRoad); } specificRoads.loadImpassableRoads(); @@ -2384,7 +2368,7 @@ public class SettingsHelper { duplicateItems.add(((ProfileSettingsItem) item).getModeBean()); } } else if (item instanceof CollectionSettingsItem) { - List duplicates = ((CollectionSettingsItem) item).excludeDuplicateItems(); + List duplicates = ((CollectionSettingsItem) item).processDuplicateItems(); if (!duplicates.isEmpty()) { duplicateItems.addAll(duplicates); } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 5c030eb39a..e3779b707b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -112,7 +112,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { if (settingsItems != null) { ImportedSettingsItemsAdapter adapter = new ImportedSettingsItemsAdapter( app, - getSettingsToOperate(settingsItems, false), + getSettingsToOperate(settingsItems, true), nightMode, new ImportedSettingsItemsAdapter.OnItemClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 0a7d02ce11..e859ae5927 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -174,7 +174,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment adapter = new ExportImportSettingsAdapter(app, nightMode, true); Map> itemsMap = new HashMap<>(); if (settingsItems != null) { - itemsMap = getSettingsToOperate(settingsItems, true); + itemsMap = getSettingsToOperate(settingsItems, false); adapter.updateSettingsList(itemsMap); } expandableList.setAdapter(adapter); @@ -355,7 +355,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment return settingsItems; } - public static Map> getSettingsToOperate(List settingsItems, boolean collectedItems) { + public static Map> getSettingsToOperate(List settingsItems, boolean importComplete) { Map> settingsToOperate = new HashMap<>(); List profiles = new ArrayList<>(); List quickActions = new ArrayList<>(); @@ -370,24 +370,24 @@ public class ImportSettingsFragment extends BaseOsmAndFragment profiles.add(((ProfileSettingsItem) item).getModeBean()); } else if (item.getType().equals(SettingsItemType.QUICK_ACTIONS)) { QuickActionsSettingsItem quickActionsItem = (QuickActionsSettingsItem) item; - if (collectedItems) { - quickActions.addAll(quickActionsItem.getItems()); + if (importComplete) { + quickActions.addAll(quickActionsItem.getAppliedItems()); } else { - quickActions.addAll(quickActionsItem.getImportItems()); + quickActions.addAll(quickActionsItem.getItems()); } } else if (item.getType().equals(SettingsItemType.POI_UI_FILTERS)) { PoiUiFilterSettingsItem poiUiFilterItem = (PoiUiFilterSettingsItem) item; - if (collectedItems) { - poiUIFilters.addAll(poiUiFilterItem.getItems()); + if (importComplete) { + poiUIFilters.addAll(poiUiFilterItem.getAppliedItems()); } else { - poiUIFilters.addAll(poiUiFilterItem.getImportItems()); + poiUIFilters.addAll(poiUiFilterItem.getItems()); } } else if (item.getType().equals(SettingsItemType.MAP_SOURCES)) { MapSourcesSettingsItem mapSourcesItem = (MapSourcesSettingsItem) item; - if (collectedItems) { - tileSourceTemplates.addAll(mapSourcesItem.getItems()); + if (importComplete) { + tileSourceTemplates.addAll(mapSourcesItem.getAppliedItems()); } else { - tileSourceTemplates.addAll(mapSourcesItem.getImportItems()); + tileSourceTemplates.addAll(mapSourcesItem.getItems()); } } else if (item.getType().equals(SettingsItemType.FILE)) { FileSettingsItem fileItem = (FileSettingsItem) item; @@ -398,10 +398,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } } else if (item.getType().equals(SettingsItemType.AVOID_ROADS)) { AvoidRoadsSettingsItem avoidRoadsItem = (AvoidRoadsSettingsItem) item; - if (collectedItems) { - avoidRoads.addAll(avoidRoadsItem.getItems()); + if (importComplete) { + avoidRoads.addAll(avoidRoadsItem.getAppliedItems()); } else { - avoidRoads.addAll(avoidRoadsItem.getImportItems()); + avoidRoads.addAll(avoidRoadsItem.getItems()); } } }