Search in sources :

Example 6 with ImportListener

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

Example 7 with ImportListener

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

the class ImportSettingsFragment method getImportListener.

public ImportListener getImportListener() {
    return 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 (succeed) {
                app.getRendererRegistry().updateExternalRenderers();
                AppInitializer.loadRoutingFiles(app, null);
                reloadIndexes(items);
                AudioVideoNotesPlugin plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
                if (plugin != null) {
                    plugin.indexingFiles(true, true);
                }
            }
            importFinished(succeed, needRestart, items);
        }
    };
}
Also used : AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) NonNull(androidx.annotation.NonNull) List(java.util.List) ImportListener(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener)

Example 8 with ImportListener

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

the class SettingsImportTask method getImportListener.

private ImportListener getImportListener(final File file) {
    return 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 (succeed) {
                app.getRendererRegistry().updateExternalRenderers();
                app.getPoiFilters().loadSelectedPoiFilters();
                AppInitializer.loadRoutingFiles(app, null);
                FragmentActivity activity = activityRef.get();
                AudioVideoNotesPlugin plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
                if (plugin != null) {
                    plugin.indexingFiles(true, true);
                }
                if (activity instanceof MapActivity) {
                    ((MapActivity) activity).getMapLayers().getMapWidgetRegistry().updateVisibleWidgets();
                    ((MapActivity) activity).updateApplicationModeSettings();
                }
                if (!silentImport && file != null && activity != null) {
                    FragmentManager fm = activity.getSupportFragmentManager();
                    ImportCompleteFragment.showInstance(fm, items, file.getName(), needRestart);
                }
            }
        }
    };
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentActivity(androidx.fragment.app.FragmentActivity) AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List) ImportListener(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener) MapActivity(net.osmand.plus.activities.MapActivity)

Example 9 with ImportListener

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

the class RestoreDuplicatesFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settingsHelper = app.getNetworkSettingsHelper();
    ImportBackupTask importTask = settingsHelper.getImportTask(RESTORE_ITEMS_KEY);
    if (importTask != null) {
        if (settingsItems == null) {
            settingsItems = importTask.getSelectedItems();
        }
        if (duplicatesList == null) {
            duplicatesList = importTask.getDuplicates();
        }
        Fragment target = getTargetFragment();
        if (target instanceof RestoreSettingsFragment) {
            ImportListener importListener = ((RestoreSettingsFragment) target).getImportListener();
            importTask.setImportListener(importListener);
        }
    }
}
Also used : ImportBackupTask(net.osmand.plus.backup.ImportBackupTask) 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)

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