Fix import items bug
This commit is contained in:
parent
568a7a27b4
commit
7d22433ce7
3 changed files with 87 additions and 50 deletions
|
@ -436,12 +436,14 @@ public class SettingsHelper {
|
|||
public abstract static class CollectionSettingsItem<T> extends SettingsItem {
|
||||
|
||||
protected List<T> items;
|
||||
protected List<T> importItems;
|
||||
protected List<T> duplicateItems;
|
||||
protected List<T> existingItems;
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
items = new ArrayList<>();
|
||||
importItems = new ArrayList<>();
|
||||
duplicateItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@ -459,6 +461,11 @@ public class SettingsHelper {
|
|||
return items;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<T> getImportItems() {
|
||||
return importItems;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<T> getDuplicateItems() {
|
||||
return duplicateItems;
|
||||
|
@ -476,6 +483,8 @@ public class SettingsHelper {
|
|||
return duplicateItems;
|
||||
}
|
||||
|
||||
public abstract void processImportItems();
|
||||
|
||||
public abstract boolean isDuplicate(@NonNull T item);
|
||||
|
||||
@NonNull
|
||||
|
@ -1315,11 +1324,16 @@ 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()) {
|
||||
List<QuickAction> actions = new ArrayList<>(items);
|
||||
actions.removeAll(duplicateItems);
|
||||
processImportItems();
|
||||
List<QuickAction> newActions = new ArrayList<>(existingItems);
|
||||
if (!duplicateItems.isEmpty()) {
|
||||
if (shouldReplace) {
|
||||
|
@ -1335,9 +1349,9 @@ public class SettingsHelper {
|
|||
renameItem(duplicateItem);
|
||||
}
|
||||
}
|
||||
newActions.addAll(duplicateItems);
|
||||
importItems.addAll(duplicateItems);
|
||||
}
|
||||
newActions.addAll(actions);
|
||||
newActions.addAll(importItems);
|
||||
actionRegistry.updateQuickActions(newActions);
|
||||
}
|
||||
}
|
||||
|
@ -1449,16 +1463,21 @@ 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()) {
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>(items);
|
||||
poiUIFilters.removeAll(duplicateItems);
|
||||
|
||||
for (PoiUIFilter duplicate : duplicateItems) {
|
||||
poiUIFilters.add(shouldReplace ? duplicate : renameItem(duplicate));
|
||||
}
|
||||
for (PoiUIFilter filter : poiUIFilters) {
|
||||
processImportItems();
|
||||
for (PoiUIFilter filter : importItems) {
|
||||
app.getPoiFilters().createPoiFilter(filter, false);
|
||||
}
|
||||
app.getSearchUICore().refreshCustomPoiFilters();
|
||||
|
@ -1597,34 +1616,35 @@ public class SettingsHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
|
||||
List<ITileSource> tileSources = new ArrayList<>(items);
|
||||
tileSources.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()) {
|
||||
if (f.delete()) {
|
||||
tileSources.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()) {
|
||||
if (f.delete()) {
|
||||
tileSources.add(tileSource);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (ITileSource tileSource : duplicateItems) {
|
||||
tileSources.add(renameItem(tileSource));
|
||||
}
|
||||
}
|
||||
for (ITileSource tileSource : tileSources) {
|
||||
} else {
|
||||
for (ITileSource tileSource : duplicateItems) {
|
||||
importItems.add(renameItem(tileSource));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
|
||||
processImportItems();
|
||||
for (ITileSource tileSource : importItems) {
|
||||
if (tileSource instanceof TileSourceManager.TileSourceTemplate) {
|
||||
app.getSettings().installTileSource((TileSourceManager.TileSourceTemplate) tileSource);
|
||||
} else if (tileSource instanceof SQLiteTileSource) {
|
||||
|
@ -1814,11 +1834,16 @@ 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()) {
|
||||
List<AvoidRoadInfo> avoidRoadInfos = new ArrayList<>(items);
|
||||
avoidRoadInfos.removeAll(duplicateItems);
|
||||
processImportItems();
|
||||
for (AvoidRoadInfo duplicate : duplicateItems) {
|
||||
if (shouldReplace) {
|
||||
LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude);
|
||||
|
@ -1829,7 +1854,7 @@ public class SettingsHelper {
|
|||
settings.addImpassableRoad(renameItem(duplicate));
|
||||
}
|
||||
}
|
||||
for (AvoidRoadInfo avoidRoad : avoidRoadInfos) {
|
||||
for (AvoidRoadInfo avoidRoad : importItems) {
|
||||
settings.addImpassableRoad(avoidRoad);
|
||||
}
|
||||
specificRoads.loadImpassableRoads();
|
||||
|
|
|
@ -112,7 +112,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
|
|||
if (settingsItems != null) {
|
||||
ImportedSettingsItemsAdapter adapter = new ImportedSettingsItemsAdapter(
|
||||
app,
|
||||
getSettingsToOperate(settingsItems),
|
||||
getSettingsToOperate(settingsItems, false),
|
||||
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);
|
||||
itemsMap = getSettingsToOperate(settingsItems, true);
|
||||
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) {
|
||||
public static Map<Type, List<?>> getSettingsToOperate(List<SettingsItem> settingsItems, boolean collectedItems) {
|
||||
Map<Type, List<?>> settingsToOperate = new HashMap<>();
|
||||
List<ApplicationMode.ApplicationModeBean> profiles = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
|
@ -370,16 +370,25 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
profiles.add(((ProfileSettingsItem) item).getModeBean());
|
||||
} else if (item.getType().equals(SettingsItemType.QUICK_ACTIONS)) {
|
||||
QuickActionsSettingsItem quickActionsItem = (QuickActionsSettingsItem) item;
|
||||
quickActions.addAll(quickActionsItem.getItems());
|
||||
quickActions.addAll(quickActionsItem.getDuplicateItems());
|
||||
if (collectedItems) {
|
||||
quickActions.addAll(quickActionsItem.getItems());
|
||||
} else {
|
||||
quickActions.addAll(quickActionsItem.getImportItems());
|
||||
}
|
||||
} else if (item.getType().equals(SettingsItemType.POI_UI_FILTERS)) {
|
||||
PoiUiFilterSettingsItem poiUiFilterItem = (PoiUiFilterSettingsItem) item;
|
||||
poiUIFilters.addAll(poiUiFilterItem.getItems());
|
||||
poiUIFilters.addAll(poiUiFilterItem.getDuplicateItems());
|
||||
if (collectedItems) {
|
||||
poiUIFilters.addAll(poiUiFilterItem.getItems());
|
||||
} else {
|
||||
poiUIFilters.addAll(poiUiFilterItem.getImportItems());
|
||||
}
|
||||
} else if (item.getType().equals(SettingsItemType.MAP_SOURCES)) {
|
||||
MapSourcesSettingsItem mapSourcesItem = (MapSourcesSettingsItem) item;
|
||||
tileSourceTemplates.addAll(mapSourcesItem.getItems());
|
||||
tileSourceTemplates.addAll(mapSourcesItem.getDuplicateItems());
|
||||
if (collectedItems) {
|
||||
tileSourceTemplates.addAll(mapSourcesItem.getItems());
|
||||
} else {
|
||||
tileSourceTemplates.addAll(mapSourcesItem.getImportItems());
|
||||
}
|
||||
} else if (item.getType().equals(SettingsItemType.FILE)) {
|
||||
FileSettingsItem fileItem = (FileSettingsItem) item;
|
||||
if (fileItem.getSubtype() == FileSubtype.RENDERING_STYLE) {
|
||||
|
@ -389,8 +398,11 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
}
|
||||
} else if (item.getType().equals(SettingsItemType.AVOID_ROADS)) {
|
||||
AvoidRoadsSettingsItem avoidRoadsItem = (AvoidRoadsSettingsItem) item;
|
||||
avoidRoads.addAll(avoidRoadsItem.getItems());
|
||||
avoidRoads.addAll(avoidRoadsItem.getDuplicateItems());
|
||||
if (collectedItems) {
|
||||
avoidRoads.addAll(avoidRoadsItem.getItems());
|
||||
} else {
|
||||
avoidRoads.addAll(avoidRoadsItem.getImportItems());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue