Search in sources :

Example 1 with ImportListener

use of net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener in project Osmand by osmandapp.

the class FileImportDuplicatesFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settingsHelper = app.getFileSettingsHelper();
    ImportFileTask importTask = settingsHelper.getImportTask();
    if (importTask != null) {
        if (settingsItems == null) {
            settingsItems = importTask.getSelectedItems();
        }
        if (duplicatesList == null) {
            duplicatesList = importTask.getDuplicates();
        }
        if (file == null) {
            file = importTask.getFile();
        }
        Fragment target = getTargetFragment();
        if (target instanceof ImportSettingsFragment) {
            ImportListener importListener = ((ImportSettingsFragment) target).getImportListener();
            importTask.setImportListener(importListener);
        }
    }
}
Also used : ImportFileTask(net.osmand.plus.settings.backend.backup.ImportFileTask) Fragment(androidx.fragment.app.Fragment) ImportListener(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener)

Example 2 with ImportListener

use of net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener in project Osmand by osmandapp.

the class FileImportDuplicatesFragment method importItems.

@Override
protected void importItems(boolean shouldReplace) {
    super.importItems(shouldReplace);
    if (settingsItems != null && file != null) {
        Fragment target = getTargetFragment();
        if (target instanceof ImportSettingsFragment) {
            ImportListener importListener = ((ImportSettingsFragment) target).getImportListener();
            settingsHelper.importSettings(file, settingsItems, "", 1, importListener);
        }
    }
}
Also used : Fragment(androidx.fragment.app.Fragment) ImportListener(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener)

Example 3 with ImportListener

use of net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener in project Osmand by osmandapp.

the class SettingsImportTask method handlePluginImport.

private void handlePluginImport(final PluginSettingsItem pluginItem, final File file) {
    FragmentActivity activity = activityRef.get();
    final ProgressDialog progress;
    if (AndroidUtils.isActivityNotDestroyed(activity)) {
        progress = new ProgressDialog(activity);
        progress.setTitle(app.getString(R.string.loading_smth, ""));
        progress.setMessage(app.getString(R.string.importing_from, pluginItem.getPublicName(app)));
        progress.setIndeterminate(true);
        progress.setCancelable(false);
        progress.show();
    } else {
        progress = null;
    }
    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) {
            FragmentActivity activity = activityRef.get();
            if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) {
                progress.dismiss();
            }
            AudioVideoNotesPlugin pluginAudioVideo = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
            if (pluginAudioVideo != null) {
                pluginAudioVideo.indexingFiles(true, true);
            }
            CustomOsmandPlugin plugin = pluginItem.getPlugin();
            plugin.loadResources();
            if (!Algorithms.isEmpty(plugin.getDownloadMaps())) {
                app.getDownloadThread().runReloadIndexFilesSilent();
            }
            if (!Algorithms.isEmpty(plugin.getRendererNames())) {
                app.getRendererRegistry().updateExternalRenderers();
            }
            if (!Algorithms.isEmpty(plugin.getRouterNames())) {
                loadRoutingFiles(app, null);
            }
            if (!silentImport && activity != null) {
                plugin.onInstall(app, activity);
            }
            String pluginId = pluginItem.getPluginId();
            File pluginDir = app.getAppPath(IndexConstants.PLUGINS_DIR + pluginId);
            if (!pluginDir.exists()) {
                pluginDir.mkdirs();
            }
            app.getFileSettingsHelper().exportSettings(pluginDir, "items", null, items, false);
        }
    };
    List<SettingsItem> pluginItems = new ArrayList<>(pluginItem.getPluginDependentItems());
    pluginItems.add(0, pluginItem);
    app.getFileSettingsHelper().checkDuplicates(file, pluginItems, pluginItems, new CheckDuplicatesListener() {

        @Override
        public void onDuplicatesChecked(@NonNull List<Object> duplicates, List<SettingsItem> items) {
            for (SettingsItem item : items) {
                item.setShouldReplace(true);
            }
            app.getFileSettingsHelper().importSettings(file, items, "", 1, importListener);
        }
    });
}
Also used : AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) CustomOsmandPlugin(net.osmand.plus.plugins.CustomOsmandPlugin) ArrayList(java.util.ArrayList) ProgressDialog(android.app.ProgressDialog) ImportListener(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener) FragmentActivity(androidx.fragment.app.FragmentActivity) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List) CallbackWithObject(net.osmand.CallbackWithObject) File(java.io.File) CheckDuplicatesListener(net.osmand.plus.settings.backend.backup.SettingsHelper.CheckDuplicatesListener)

Example 4 with ImportListener

use of net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener in project Osmand by osmandapp.

the class RestoreDuplicatesFragment method importItems.

@Override
protected void importItems(boolean shouldReplace) {
    super.importItems(shouldReplace);
    if (settingsItems != null) {
        Fragment target = getTargetFragment();
        if (target instanceof ImportSettingsFragment) {
            try {
                ImportListener importListener = ((ImportSettingsFragment) target).getImportListener();
                settingsHelper.importSettings(RESTORE_ITEMS_KEY, settingsItems, false, importListener);
            } catch (IllegalStateException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }
}
Also used : ImportSettingsFragment(net.osmand.plus.settings.fragments.ImportSettingsFragment) FileImportDuplicatesFragment(net.osmand.plus.settings.fragments.FileImportDuplicatesFragment) ImportDuplicatesFragment(net.osmand.plus.settings.fragments.ImportDuplicatesFragment) ImportSettingsFragment(net.osmand.plus.settings.fragments.ImportSettingsFragment) Fragment(androidx.fragment.app.Fragment) ImportListener(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener)

Example 5 with ImportListener

use of net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener 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)

Aggregations

ImportListener (net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener)9 NonNull (androidx.annotation.NonNull)5 List (java.util.List)5 Fragment (androidx.fragment.app.Fragment)4 ArrayList (java.util.ArrayList)4 AudioVideoNotesPlugin (net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin)3 SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)3 ProgressDialog (android.app.ProgressDialog)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 CheckDuplicatesListener (net.osmand.plus.settings.backend.backup.SettingsHelper.CheckDuplicatesListener)2 PluginSettingsItem (net.osmand.plus.settings.backend.backup.items.PluginSettingsItem)2 ProfileSettingsItem (net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem)2 FileImportDuplicatesFragment (net.osmand.plus.settings.fragments.FileImportDuplicatesFragment)2 ImportDuplicatesFragment (net.osmand.plus.settings.fragments.ImportDuplicatesFragment)2 ImportSettingsFragment (net.osmand.plus.settings.fragments.ImportSettingsFragment)2 AsyncTask (android.os.AsyncTask)1 Nullable (androidx.annotation.Nullable)1 FragmentManager (androidx.fragment.app.FragmentManager)1 File (java.io.File)1 IOException (java.io.IOException)1