Change importItems to appliedItems
This commit is contained in:
parent
ecf7c29dcd
commit
3c919b6d19
3 changed files with 64 additions and 80 deletions
|
@ -436,14 +436,14 @@ public class SettingsHelper {
|
|||
public abstract static class CollectionSettingsItem<T> extends SettingsItem {
|
||||
|
||||
protected List<T> items;
|
||||
protected List<T> importItems;
|
||||
protected List<T> appliedItems;
|
||||
protected List<T> duplicateItems;
|
||||
protected List<T> 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<T> getImportItems() {
|
||||
return importItems;
|
||||
public List<T> getAppliedItems() {
|
||||
return appliedItems;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -472,7 +472,7 @@ public class SettingsHelper {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public List<T> excludeDuplicateItems() {
|
||||
public List<T> 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<T> getNewItems() {
|
||||
List<T> 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<QuickAction> newItems = getNewItems();
|
||||
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
|
||||
appliedItems = new ArrayList<>(newItems);
|
||||
List<QuickAction> 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<PoiUIFilter> 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<ITileSource> 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<AvoidRoadInfo> 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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -174,7 +174,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
adapter = new ExportImportSettingsAdapter(app, nightMode, true);
|
||||
Map<Type, List<?>> 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<Type, List<?>> getSettingsToOperate(List<SettingsItem> settingsItems, boolean collectedItems) {
|
||||
public static Map<Type, List<?>> getSettingsToOperate(List<SettingsItem> settingsItems, boolean importComplete) {
|
||||
Map<Type, List<?>> settingsToOperate = new HashMap<>();
|
||||
List<ApplicationMode.ApplicationModeBean> profiles = new ArrayList<>();
|
||||
List<QuickAction> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue