use of net.osmand.plus.settings.backend.backup.SettingsHelper.CheckDuplicatesListener 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);
}
});
}
Aggregations