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);
}
}
});
}
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);
}
};
}
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);
}
}
}
};
}
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);
}
}
}
Aggregations