From d0acb1d1d47fc84e9a74b998ed8d3a3d6b719cf8 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Sat, 28 Nov 2020 21:14:45 +0200 Subject: [PATCH] Fix export empty file, refactoring --- .../plus/importfiles/SettingsImportTask.java | 24 ++++++++++--------- .../backend/backup/ProfileSettingsItem.java | 3 --- .../backend/backup/SettingsHelper.java | 22 ++++++----------- .../fragments/ExportSettingsAdapter.java | 9 ++++++- .../fragments/ExportSettingsFragment.java | 7 ++---- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java index 99c321adfd..75c8d55015 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/SettingsImportTask.java @@ -90,14 +90,16 @@ class SettingsImportTask extends BaseLoadAsyncTask { for (PluginSettingsItem pluginItem : pluginSettingsItems) { handlePluginImport(pluginItem, file); } - FragmentActivity activity = activityRef.get(); - if (!pluginIndependentItems.isEmpty() && activity != null) { + if (!pluginIndependentItems.isEmpty()) { if (settingsTypes == null) { - FragmentManager fragmentManager = activity.getSupportFragmentManager(); - ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file); + FragmentActivity activity = activityRef.get(); + if (activity != null) { + FragmentManager fragmentManager = activity.getSupportFragmentManager(); + ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file); + } } else { - Map> allSettingsList = getSettingsToOperate(pluginIndependentItems, false); - List settingsList = settingsHelper.getFilteredSettingsItems(allSettingsList, settingsTypes); + Map> allSettingsMap = getSettingsToOperate(pluginIndependentItems, false); + List settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes); settingsHelper.checkDuplicates(file, settingsList, settingsList, getDuplicatesListener(file, replace)); } } @@ -130,17 +132,17 @@ class SettingsImportTask extends BaseLoadAsyncTask { return new SettingsImportListener() { @Override public void onSettingsImportFinished(boolean succeed, @NonNull List items) { - FragmentActivity activity = activityRef.get(); - if (activity != null && succeed) { - FragmentManager fm = activity.getSupportFragmentManager(); + if (succeed) { app.getRendererRegistry().updateExternalRenderers(); app.getPoiFilters().loadSelectedPoiFilters(); + AppInitializer.loadRoutingFiles(app, null); + FragmentActivity activity = activityRef.get(); if (activity instanceof MapActivity) { ((MapActivity) activity).getMapLayers().getMapWidgetRegistry().updateVisibleWidgets(); ((MapActivity) activity).updateApplicationModeSettings(); } - AppInitializer.loadRoutingFiles(app, null); - if (file != null) { + if (file != null && activity != null) { + FragmentManager fm = activity.getSupportFragmentManager(); ImportCompleteFragment.showInstance(fm, items, file.getName()); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/ProfileSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/ProfileSettingsItem.java index 10e47d4e09..4ddb04daab 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/ProfileSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/ProfileSettingsItem.java @@ -170,9 +170,6 @@ public class ProfileSettingsItem extends OsmandSettingsItem { builder = ApplicationMode.fromModeBean(app, modeBean); appMode = ApplicationMode.saveProfile(builder, app); } else { - if (modeBean == null) { - modeBean = appMode.toModeBean(); - } builder = ApplicationMode.fromModeBean(app, modeBean); appMode = ApplicationMode.saveProfile(builder, app); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 4553cf805f..c092ae054f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -481,24 +481,19 @@ public class SettingsHelper { return getFilteredSettingsItems(typesMap, settingsTypes); } - public List getFilteredSettingsItems(Map> additionalData, - List settingsTypes) { + public List getFilteredSettingsItems(Map> allSettingsMap, + List settingsTypes) { List settingsItems = new ArrayList<>(); for (ExportSettingsType settingsType : settingsTypes) { - List settingsDataObjects = additionalData.get(settingsType); + List settingsDataObjects = allSettingsMap.get(settingsType); if (settingsDataObjects != null) { - for (Object object : settingsDataObjects) { - if (object instanceof ApplicationModeBean) { - settingsItems.add(new ProfileSettingsItem(app, null, (ApplicationModeBean) object)); - } - } - settingsItems.addAll(prepareAdditionalSettingsItems(new ArrayList<>(settingsDataObjects))); + settingsItems.addAll(prepareSettingsItems(new ArrayList<>(settingsDataObjects))); } } return settingsItems; } - public Map getAdditionalData(boolean globalExport) { + public Map getSettingsByCategory(boolean globalExport) { Map dataList = new LinkedHashMap<>(); Map> settingsItems = getSettingsItems(globalExport); @@ -692,7 +687,7 @@ public class SettingsHelper { return files; } - public List prepareAdditionalSettingsItems(List data) { + public List prepareSettingsItems(List data) { List settingsItems = new ArrayList<>(); List quickActions = new ArrayList<>(); List poiUIFilters = new ArrayList<>(); @@ -754,10 +749,7 @@ public class SettingsHelper { } if (!appModeBeans.isEmpty()) { for (ApplicationModeBean modeBean : appModeBeans) { - ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); - if (mode != null) { - settingsItems.add(new ProfileSettingsItem(app, mode)); - } + settingsItems.add(new ProfileSettingsItem(app, null, modeBean)); } } if (!osmNotesPointList.isEmpty()) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsAdapter.java index d479b78a7c..2c45919f2c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsAdapter.java @@ -248,7 +248,14 @@ public class ExportSettingsAdapter extends OsmandBaseExpandableListAdapter { } public boolean hasSelectedData() { - return !selectedItemsMap.isEmpty(); + boolean hasSelectedData = false; + for (ExportSettingsType key : selectedItemsMap.keySet()) { + if (!selectedItemsMap.get(key).isEmpty()) { + hasSelectedData = true; + break; + } + } + return hasSelectedData; } public List getData() { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java index f831fd8fdd..1245290834 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsFragment.java @@ -44,12 +44,9 @@ public class ExportSettingsFragment extends BaseSettingsListFragment { public static final String TAG = ImportSettingsFragment.class.getSimpleName(); public static final Log LOG = PlatformUtil.getLog(ImportSettingsFragment.class.getSimpleName()); - private static final String EXPORT_SETTINGS_TAG = "import_settings_tag"; private static final String GLOBAL_EXPORT_KEY = "global_export_key"; private static final String EXPORT_START_TIME_KEY = "export_start_time_key"; private static final String EXPORTING_STARTED_KEY = "exporting_started_key"; - private static final String INCLUDE_ADDITIONAL_DATA_KEY = "include_additional_data_key"; - private static final String INCLUDE_GLOBAL_SETTINGS_KEY = "include_global_settings_key"; private static final String PROGRESS_MAX_KEY = "progress_max_key"; private static final String PROGRESS_VALUE_KEY = "progress_value_key"; @@ -76,7 +73,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment { progressMax = savedInstanceState.getInt(PROGRESS_MAX_KEY); progressValue = savedInstanceState.getInt(PROGRESS_VALUE_KEY); } - dataList = app.getSettingsHelper().getAdditionalData(globalExport); + dataList = app.getSettingsHelper().getSettingsByCategory(globalExport); requireActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { @Override @@ -139,7 +136,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment { showExportProgressDialog(); File tempDir = FileUtils.getTempDir(app); String fileName = getFileName(); - List items = app.getSettingsHelper().prepareAdditionalSettingsItems(adapter.getData()); + List items = app.getSettingsHelper().prepareSettingsItems(adapter.getData()); progress.setMax(getMaxProgress(items)); app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true); }