Search in sources :

Example 26 with SettingsItem

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;
    }
}
Also used : ImportType(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportType) ImportListener(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener) AsyncTask(android.os.AsyncTask) BackupCollectListener(net.osmand.plus.backup.NetworkSettingsHelper.BackupCollectListener) NonNull(androidx.annotation.NonNull) CollectItemsResult(net.osmand.plus.backup.BackupImporter.CollectItemsResult) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) IOException(java.io.IOException) HashMap(java.util.HashMap) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) CollectionSettingsItem(net.osmand.plus.settings.backend.backup.items.CollectionSettingsItem) List(java.util.List) Nullable(androidx.annotation.Nullable) Map(java.util.Map) CheckDuplicatesListener(net.osmand.plus.settings.backend.backup.SettingsHelper.CheckDuplicatesListener) NetworkImportProgressListener(net.osmand.plus.backup.BackupImporter.NetworkImportProgressListener) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) ItemProgressInfo(net.osmand.plus.backup.ExportBackupTask.ItemProgressInfo) ImportItemsListener(net.osmand.plus.backup.ImportBackupItemsTask.ImportItemsListener) ImportItemsListener(net.osmand.plus.backup.ImportBackupItemsTask.ImportItemsListener)

Example 27 with SettingsItem

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;
}
Also used : FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) CollectionSettingsItem(net.osmand.plus.settings.backend.backup.items.CollectionSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) CollectItemsResult(net.osmand.plus.backup.BackupImporter.CollectItemsResult) IOException(java.io.IOException)

Example 28 with SettingsItem

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;
}
Also used : SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) ArrayList(java.util.ArrayList)

Example 29 with SettingsItem

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();
            }
        }
    });
}
Also used : QuickAction(net.osmand.plus.quickaction.QuickAction) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) AvoidSpecificRoads(net.osmand.plus.helpers.AvoidSpecificRoads) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) SQLiteTileSource(net.osmand.plus.resources.SQLiteTileSource) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) CollectListener(net.osmand.plus.settings.backend.backup.SettingsHelper.CollectListener) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) ITileSource(net.osmand.map.ITileSource) List(java.util.List) ArrayList(java.util.ArrayList) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) QuickActionRegistry(net.osmand.plus.quickaction.QuickActionRegistry) File(java.io.File) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem)

Example 30 with SettingsItem

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);
            }
        }
    });
}
Also used : ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) ProgressDialog(android.app.ProgressDialog) ImportListener(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener) CollectListener(net.osmand.plus.settings.backend.backup.SettingsHelper.CollectListener) AvoidRoadsSettingsItem(net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem) ProfileSettingsItem(net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem) MapSourcesSettingsItem(net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem) PoiUiFiltersSettingsItem(net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem) QuickActionsSettingsItem(net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem) NonNull(androidx.annotation.NonNull) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem)

Aggregations

SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)37 ArrayList (java.util.ArrayList)19 FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)18 File (java.io.File)11 List (java.util.List)11 IOException (java.io.IOException)10 GpxSettingsItem (net.osmand.plus.settings.backend.backup.items.GpxSettingsItem)10 ProfileSettingsItem (net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem)10 NonNull (androidx.annotation.NonNull)8 AvoidRoadsSettingsItem (net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem)7 MapSourcesSettingsItem (net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem)7 PoiUiFiltersSettingsItem (net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem)7 QuickActionsSettingsItem (net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem)7 Nullable (androidx.annotation.Nullable)6 HashMap (java.util.HashMap)6 PluginSettingsItem (net.osmand.plus.settings.backend.backup.items.PluginSettingsItem)6 HashSet (java.util.HashSet)5 FileInputStream (java.io.FileInputStream)4 FragmentActivity (androidx.fragment.app.FragmentActivity)3 Map (java.util.Map)3