This commit is contained in:
Vitaliy 2020-05-07 16:20:20 +03:00
parent 66060f78b2
commit 9a01fc9277
5 changed files with 54 additions and 16 deletions

View file

@ -3540,7 +3540,7 @@
<string name="shared_string_routing">ניתוב</string> <string name="shared_string_routing">ניתוב</string>
<string name="listed_exist">%1$s מוצג, כבר קיים ב־OsmAnd.</string> <string name="listed_exist">%1$s מוצג, כבר קיים ב־OsmAnd.</string>
<string name="clear_recorded_data_warning">למחוק את הנתונים שהוקלטו\?</string> <string name="clear_recorded_data_warning">למחוק את הנתונים שהוקלטו\?</string>
<string name="importing_from">מיובאים נתונים מתוך %1</string> <string name="importing_from">מיובאים נתונים מתוך %1$s</string>
<string name="shared_string_importing">מתבצע ייבוא</string> <string name="shared_string_importing">מתבצע ייבוא</string>
<string name="checking_for_duplicate_description">OsmAnd יחפש כפילויות של %1$s עם פריטים קיימים ביישומון. <string name="checking_for_duplicate_description">OsmAnd יחפש כפילויות של %1$s עם פריטים קיימים ביישומון.
\n \n

View file

@ -1,6 +1,7 @@
package net.osmand.plus; package net.osmand.plus;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -9,6 +10,7 @@ import android.text.Html;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.JsonUtils; import net.osmand.JsonUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
@ -104,7 +106,7 @@ public class CustomOsmandPlugin extends OsmandPlugin {
// called from UI // called from UI
File pluginItemsFile = getPluginItemsFile(); File pluginItemsFile = getPluginItemsFile();
if (pluginItemsFile.exists()) { if (pluginItemsFile.exists()) {
addPluginItemsFromFile(pluginItemsFile); addPluginItemsFromFile(pluginItemsFile, activity);
} }
} }
return true; return true;
@ -212,7 +214,26 @@ public class CustomOsmandPlugin extends OsmandPlugin {
this.resourceDirName = resourceDirName; this.resourceDirName = resourceDirName;
} }
private void addPluginItemsFromFile(final File file) { 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 SettingsHelper.SettingsImportListener importListener = new SettingsHelper.SettingsImportListener() {
@Override
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
progress.dismiss();
}
}
};
app.getSettingsHelper().collectSettings(file, "", 1, new SettingsCollectListener() { app.getSettingsHelper().collectSettings(file, "", 1, new SettingsCollectListener() {
@Override @Override
public void onSettingsCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items) { public void onSettingsCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items) {
@ -231,7 +252,7 @@ public class CustomOsmandPlugin extends OsmandPlugin {
item.setShouldReplace(true); item.setShouldReplace(true);
} }
} }
app.getSettingsHelper().importSettings(file, items, "", 1, null); app.getSettingsHelper().importSettings(file, items, "", 1, importListener);
} }
} }
}); });

View file

@ -134,6 +134,7 @@ public class PluginDisabledBottomSheet extends MenuBottomSheetDialogFragment {
public static void showInstance(@NonNull FragmentManager fm, String pluginId, Boolean usedOnMap) { public static void showInstance(@NonNull FragmentManager fm, String pluginId, Boolean usedOnMap) {
try { try {
if (!fm.isStateSaved()) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(PLUGIN_ID_KEY, pluginId); args.putString(PLUGIN_ID_KEY, pluginId);
@ -141,6 +142,7 @@ public class PluginDisabledBottomSheet extends MenuBottomSheetDialogFragment {
dialog.setArguments(args); dialog.setArguments(args);
dialog.setUsedOnMap(usedOnMap); dialog.setUsedOnMap(usedOnMap);
dialog.show(fm, PluginDisabledBottomSheet.TAG); dialog.show(fm, PluginDisabledBottomSheet.TAG);
}
} catch (RuntimeException e) { } catch (RuntimeException e) {
LOG.error("showInstance", e); LOG.error("showInstance", e);
} }

View file

@ -322,6 +322,7 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm
public static void showInstance(@NonNull FragmentManager fm, String pluginId, Boolean usedOnMap) { public static void showInstance(@NonNull FragmentManager fm, String pluginId, Boolean usedOnMap) {
try { try {
if (!fm.isStateSaved()) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(PLUGIN_ID_KEY, pluginId); args.putString(PLUGIN_ID_KEY, pluginId);
@ -329,6 +330,7 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm
dialog.setArguments(args); dialog.setArguments(args);
dialog.setUsedOnMap(usedOnMap); dialog.setUsedOnMap(usedOnMap);
dialog.show(fm, PluginInstalledBottomSheetDialog.TAG); dialog.show(fm, PluginInstalledBottomSheetDialog.TAG);
}
} catch (RuntimeException e) { } catch (RuntimeException e) {
LOG.error("showInstance", e); LOG.error("showInstance", e);
} }

View file

@ -840,9 +840,22 @@ public class ImportHelper {
} }
private void handlePluginImport(final PluginSettingsItem pluginItem, final File file) { private void handlePluginImport(final PluginSettingsItem pluginItem, final File file) {
final ProgressDialog 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);
if (AndroidUtils.isActivityNotDestroyed(activity)) {
progress.show();
}
final SettingsImportListener importListener = new SettingsImportListener() { final SettingsImportListener importListener = new SettingsImportListener() {
@Override @Override
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) { public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
progress.dismiss();
}
CustomOsmandPlugin plugin = pluginItem.getPlugin(); CustomOsmandPlugin plugin = pluginItem.getPlugin();
plugin.loadResources(); plugin.loadResources();