use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class ImportBackupTask method onPostExecute.
@Override
protected void onPostExecute(@Nullable List<SettingsItem> items) {
if (items != null && importType != ImportType.CHECK_DUPLICATES) {
this.items = items;
} else {
selectedItems = items;
}
switch(importType) {
case COLLECT:
case COLLECT_AND_READ:
collectListener.onBackupCollectFinished(items != null, false, this.items, remoteFiles);
helper.importAsyncTasks.remove(key);
break;
case CHECK_DUPLICATES:
if (duplicatesListener != null) {
duplicatesListener.onDuplicatesChecked(duplicates, selectedItems);
}
helper.importAsyncTasks.remove(key);
break;
case IMPORT:
case IMPORT_FORCE_READ:
if (items != null && items.size() > 0) {
boolean forceReadData = importType == ImportType.IMPORT_FORCE_READ;
ImportItemsListener itemsListener = (succeed, needRestart) -> {
helper.importAsyncTasks.remove(key);
helper.finishImport(importListener, succeed, items, needRestart);
};
new ImportBackupItemsTask(app, importer, items, itemsListener, forceReadData).executeOnExecutor(app.getBackupHelper().getExecutor());
}
break;
}
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class ImportBackupTask method doInBackground.
@Override
protected List<SettingsItem> doInBackground(Void... voids) {
switch(importType) {
case COLLECT:
case COLLECT_AND_READ:
try {
CollectItemsResult result = importer.collectItems(importType == ImportType.COLLECT_AND_READ);
remoteFiles = result.remoteFiles;
return result.items;
} catch (IllegalArgumentException e) {
NetworkSettingsHelper.LOG.error("Failed to collect items for backup", e);
} catch (IOException e) {
NetworkSettingsHelper.LOG.error("Failed to collect items for backup", e);
}
break;
case CHECK_DUPLICATES:
this.duplicates = getDuplicatesData(selectedItems);
return selectedItems;
case IMPORT:
case IMPORT_FORCE_READ:
if (items != null && items.size() > 0) {
BackupHelper backupHelper = app.getBackupHelper();
PrepareBackupResult backup = backupHelper.getBackup();
for (SettingsItem item : items) {
item.apply();
String fileName = item.getFileName();
if (fileName != null) {
RemoteFile remoteFile = backup.getRemoteFile(item.getType().name(), fileName);
if (remoteFile != null) {
backupHelper.updateFileUploadTime(remoteFile.getType(), remoteFile.getName(), remoteFile.getClienttimems());
}
}
}
}
return items;
}
return null;
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class NetworkSettingsHelper method collectFormattedWarnings.
private String collectFormattedWarnings(@NonNull List<SettingsItem> items) {
List<String> warnings = new ArrayList<>();
for (SettingsItem item : items) {
warnings.addAll(item.getWarnings());
}
String error = null;
if (!Algorithms.isEmpty(warnings)) {
error = AndroidUtils.formatWarnings(warnings).toString();
}
return error;
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class CustomOsmandPlugin method removePluginItemsFromFile.
private void removePluginItemsFromFile(final File file, final PluginItemsListener itemsListener) {
app.getFileSettingsHelper().collectSettings(file, "", 1, new CollectListener() {
@Override
public void onCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items) {
if (succeed && !items.isEmpty()) {
for (SettingsItem item : items) {
if (item instanceof QuickActionsSettingsItem) {
QuickActionsSettingsItem quickActionsSettingsItem = (QuickActionsSettingsItem) item;
List<QuickAction> quickActions = quickActionsSettingsItem.getItems();
QuickActionRegistry actionRegistry = app.getQuickActionRegistry();
for (QuickAction action : quickActions) {
QuickAction savedAction = actionRegistry.getQuickAction(app, action.getType(), action.getName(app), action.getParams());
if (savedAction != null) {
actionRegistry.deleteQuickAction(savedAction);
}
}
} else if (item instanceof MapSourcesSettingsItem) {
MapSourcesSettingsItem mapSourcesSettingsItem = (MapSourcesSettingsItem) item;
List<ITileSource> mapSources = mapSourcesSettingsItem.getItems();
for (ITileSource tileSource : mapSources) {
String tileSourceName = tileSource.getName();
if (tileSource instanceof SQLiteTileSource) {
tileSourceName += SQLITE_EXT;
}
ITileSource savedTileSource = app.getSettings().getTileSourceByName(tileSourceName, false);
if (savedTileSource != null) {
if (savedTileSource instanceof SQLiteTileSource) {
SQLiteTileSource sqLiteTileSource = ((SQLiteTileSource) savedTileSource);
sqLiteTileSource.closeDB();
}
File tPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
File dir = new File(tPath, tileSourceName);
Algorithms.removeAllFiles(dir);
}
}
} else if (item instanceof PoiUiFiltersSettingsItem) {
PoiUiFiltersSettingsItem poiUiFiltersSettingsItem = (PoiUiFiltersSettingsItem) item;
List<PoiUIFilter> poiUIFilters = poiUiFiltersSettingsItem.getItems();
for (PoiUIFilter filter : poiUIFilters) {
app.getPoiFilters().removePoiFilter(filter);
}
app.getPoiFilters().reloadAllPoiFilters();
app.getPoiFilters().loadSelectedPoiFilters();
app.getSearchUICore().refreshCustomPoiFilters();
} else if (item instanceof AvoidRoadsSettingsItem) {
AvoidRoadsSettingsItem avoidRoadsSettingsItem = (AvoidRoadsSettingsItem) item;
List<AvoidSpecificRoads.AvoidRoadInfo> avoidRoadInfos = avoidRoadsSettingsItem.getItems();
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : avoidRoadInfos) {
app.getAvoidSpecificRoads().removeImpassableRoad(avoidRoad);
}
} else if (item instanceof ProfileSettingsItem) {
ProfileSettingsItem profileSettingsItem = (ProfileSettingsItem) item;
ApplicationMode mode = profileSettingsItem.getAppMode();
ApplicationMode savedMode = ApplicationMode.valueOfStringKey(mode.getStringKey(), null);
if (savedMode != null) {
ApplicationMode.changeProfileAvailability(savedMode, false, app);
}
}
}
}
if (itemsListener != null) {
itemsListener.onItemsRemoved();
}
}
});
}
use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.
the class CustomOsmandPlugin method addPluginItemsFromFile.
private void addPluginItemsFromFile(final File file, final Activity activity) {
final ProgressDialog progress = new ProgressDialog(activity);
progress.setTitle(app.getString(R.string.loading_smth, ""));
progress.setMessage(app.getString(R.string.loading_data));
progress.setIndeterminate(true);
progress.setCancelable(false);
if (AndroidUtils.isActivityNotDestroyed(activity)) {
progress.show();
}
final ImportListener importListener = new ImportListener() {
@Override
public void onImportItemStarted(@NonNull String type, @NonNull String fileName, int work) {
}
@Override
public void onImportItemProgress(@NonNull String type, @NonNull String fileName, int value) {
}
@Override
public void onImportItemFinished(@NonNull String type, @NonNull String fileName) {
}
@Override
public void onImportFinished(boolean succeed, boolean needRestart, @NonNull List<SettingsItem> items) {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
progress.dismiss();
}
}
};
app.getFileSettingsHelper().collectSettings(file, "", 1, new CollectListener() {
@Override
public void onCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items) {
if (succeed && !items.isEmpty()) {
for (Iterator<SettingsItem> iterator = items.iterator(); iterator.hasNext(); ) {
SettingsItem item = iterator.next();
if (item instanceof ProfileSettingsItem) {
ProfileSettingsItem profileSettingsItem = (ProfileSettingsItem) item;
ApplicationMode mode = profileSettingsItem.getAppMode();
ApplicationMode savedMode = ApplicationMode.valueOfStringKey(mode.getStringKey(), null);
if (savedMode != null) {
ApplicationMode.changeProfileAvailability(savedMode, true, app);
}
iterator.remove();
} else if (!(item instanceof PluginSettingsItem)) {
item.setShouldReplace(true);
}
}
app.getFileSettingsHelper().importSettings(file, items, "", 1, importListener);
}
}
});
}
Aggregations