Fix export empty file, refactoring

This commit is contained in:
Dima-1 2020-11-28 21:14:45 +02:00
parent ac497a9f14
commit d0acb1d1d4
5 changed files with 30 additions and 35 deletions

View file

@ -90,14 +90,16 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
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<ExportSettingsType, List<?>> allSettingsList = getSettingsToOperate(pluginIndependentItems, false);
List<SettingsItem> settingsList = settingsHelper.getFilteredSettingsItems(allSettingsList, settingsTypes);
Map<ExportSettingsType, List<?>> allSettingsMap = getSettingsToOperate(pluginIndependentItems, false);
List<SettingsItem> settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes);
settingsHelper.checkDuplicates(file, settingsList, settingsList, getDuplicatesListener(file, replace));
}
}
@ -130,17 +132,17 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
return new SettingsImportListener() {
@Override
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> 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());
}
}

View file

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

View file

@ -481,24 +481,19 @@ public class SettingsHelper {
return getFilteredSettingsItems(typesMap, settingsTypes);
}
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> additionalData,
List<ExportSettingsType> settingsTypes) {
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> allSettingsMap,
List<ExportSettingsType> settingsTypes) {
List<SettingsItem> 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<ExportSettingsCategory, SettingsCategoryItems> getAdditionalData(boolean globalExport) {
public Map<ExportSettingsCategory, SettingsCategoryItems> getSettingsByCategory(boolean globalExport) {
Map<ExportSettingsCategory, SettingsCategoryItems> dataList = new LinkedHashMap<>();
Map<ExportSettingsType, List<?>> settingsItems = getSettingsItems(globalExport);
@ -692,7 +687,7 @@ public class SettingsHelper {
return files;
}
public List<SettingsItem> prepareAdditionalSettingsItems(List<? super Object> data) {
public List<SettingsItem> prepareSettingsItems(List<? super Object> data) {
List<SettingsItem> settingsItems = new ArrayList<>();
List<QuickAction> quickActions = new ArrayList<>();
List<PoiUIFilter> 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()) {

View file

@ -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<? super Object> getData() {

View file

@ -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<SettingsItem> items = app.getSettingsHelper().prepareAdditionalSettingsItems(adapter.getData());
List<SettingsItem> items = app.getSettingsHelper().prepareSettingsItems(adapter.getData());
progress.setMax(getMaxProgress(items));
app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true);
}