Fix export empty file, refactoring
This commit is contained in:
parent
ac497a9f14
commit
d0acb1d1d4
5 changed files with 30 additions and 35 deletions
|
@ -90,14 +90,16 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
|
||||||
for (PluginSettingsItem pluginItem : pluginSettingsItems) {
|
for (PluginSettingsItem pluginItem : pluginSettingsItems) {
|
||||||
handlePluginImport(pluginItem, file);
|
handlePluginImport(pluginItem, file);
|
||||||
}
|
}
|
||||||
FragmentActivity activity = activityRef.get();
|
if (!pluginIndependentItems.isEmpty()) {
|
||||||
if (!pluginIndependentItems.isEmpty() && activity != null) {
|
|
||||||
if (settingsTypes == null) {
|
if (settingsTypes == null) {
|
||||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
FragmentActivity activity = activityRef.get();
|
||||||
ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file);
|
if (activity != null) {
|
||||||
|
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||||
|
ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Map<ExportSettingsType, List<?>> allSettingsList = getSettingsToOperate(pluginIndependentItems, false);
|
Map<ExportSettingsType, List<?>> allSettingsMap = getSettingsToOperate(pluginIndependentItems, false);
|
||||||
List<SettingsItem> settingsList = settingsHelper.getFilteredSettingsItems(allSettingsList, settingsTypes);
|
List<SettingsItem> settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes);
|
||||||
settingsHelper.checkDuplicates(file, settingsList, settingsList, getDuplicatesListener(file, replace));
|
settingsHelper.checkDuplicates(file, settingsList, settingsList, getDuplicatesListener(file, replace));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,17 +132,17 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
|
||||||
return new SettingsImportListener() {
|
return new SettingsImportListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) {
|
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) {
|
||||||
FragmentActivity activity = activityRef.get();
|
if (succeed) {
|
||||||
if (activity != null && succeed) {
|
|
||||||
FragmentManager fm = activity.getSupportFragmentManager();
|
|
||||||
app.getRendererRegistry().updateExternalRenderers();
|
app.getRendererRegistry().updateExternalRenderers();
|
||||||
app.getPoiFilters().loadSelectedPoiFilters();
|
app.getPoiFilters().loadSelectedPoiFilters();
|
||||||
|
AppInitializer.loadRoutingFiles(app, null);
|
||||||
|
FragmentActivity activity = activityRef.get();
|
||||||
if (activity instanceof MapActivity) {
|
if (activity instanceof MapActivity) {
|
||||||
((MapActivity) activity).getMapLayers().getMapWidgetRegistry().updateVisibleWidgets();
|
((MapActivity) activity).getMapLayers().getMapWidgetRegistry().updateVisibleWidgets();
|
||||||
((MapActivity) activity).updateApplicationModeSettings();
|
((MapActivity) activity).updateApplicationModeSettings();
|
||||||
}
|
}
|
||||||
AppInitializer.loadRoutingFiles(app, null);
|
if (file != null && activity != null) {
|
||||||
if (file != null) {
|
FragmentManager fm = activity.getSupportFragmentManager();
|
||||||
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,9 +170,6 @@ public class ProfileSettingsItem extends OsmandSettingsItem {
|
||||||
builder = ApplicationMode.fromModeBean(app, modeBean);
|
builder = ApplicationMode.fromModeBean(app, modeBean);
|
||||||
appMode = ApplicationMode.saveProfile(builder, app);
|
appMode = ApplicationMode.saveProfile(builder, app);
|
||||||
} else {
|
} else {
|
||||||
if (modeBean == null) {
|
|
||||||
modeBean = appMode.toModeBean();
|
|
||||||
}
|
|
||||||
builder = ApplicationMode.fromModeBean(app, modeBean);
|
builder = ApplicationMode.fromModeBean(app, modeBean);
|
||||||
appMode = ApplicationMode.saveProfile(builder, app);
|
appMode = ApplicationMode.saveProfile(builder, app);
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,24 +481,19 @@ public class SettingsHelper {
|
||||||
return getFilteredSettingsItems(typesMap, settingsTypes);
|
return getFilteredSettingsItems(typesMap, settingsTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> additionalData,
|
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> allSettingsMap,
|
||||||
List<ExportSettingsType> settingsTypes) {
|
List<ExportSettingsType> settingsTypes) {
|
||||||
List<SettingsItem> settingsItems = new ArrayList<>();
|
List<SettingsItem> settingsItems = new ArrayList<>();
|
||||||
for (ExportSettingsType settingsType : settingsTypes) {
|
for (ExportSettingsType settingsType : settingsTypes) {
|
||||||
List<?> settingsDataObjects = additionalData.get(settingsType);
|
List<?> settingsDataObjects = allSettingsMap.get(settingsType);
|
||||||
if (settingsDataObjects != null) {
|
if (settingsDataObjects != null) {
|
||||||
for (Object object : settingsDataObjects) {
|
settingsItems.addAll(prepareSettingsItems(new ArrayList<>(settingsDataObjects)));
|
||||||
if (object instanceof ApplicationModeBean) {
|
|
||||||
settingsItems.add(new ProfileSettingsItem(app, null, (ApplicationModeBean) object));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
settingsItems.addAll(prepareAdditionalSettingsItems(new ArrayList<>(settingsDataObjects)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return settingsItems;
|
return settingsItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<ExportSettingsCategory, SettingsCategoryItems> getAdditionalData(boolean globalExport) {
|
public Map<ExportSettingsCategory, SettingsCategoryItems> getSettingsByCategory(boolean globalExport) {
|
||||||
Map<ExportSettingsCategory, SettingsCategoryItems> dataList = new LinkedHashMap<>();
|
Map<ExportSettingsCategory, SettingsCategoryItems> dataList = new LinkedHashMap<>();
|
||||||
|
|
||||||
Map<ExportSettingsType, List<?>> settingsItems = getSettingsItems(globalExport);
|
Map<ExportSettingsType, List<?>> settingsItems = getSettingsItems(globalExport);
|
||||||
|
@ -692,7 +687,7 @@ public class SettingsHelper {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SettingsItem> prepareAdditionalSettingsItems(List<? super Object> data) {
|
public List<SettingsItem> prepareSettingsItems(List<? super Object> data) {
|
||||||
List<SettingsItem> settingsItems = new ArrayList<>();
|
List<SettingsItem> settingsItems = new ArrayList<>();
|
||||||
List<QuickAction> quickActions = new ArrayList<>();
|
List<QuickAction> quickActions = new ArrayList<>();
|
||||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||||
|
@ -754,10 +749,7 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
if (!appModeBeans.isEmpty()) {
|
if (!appModeBeans.isEmpty()) {
|
||||||
for (ApplicationModeBean modeBean : appModeBeans) {
|
for (ApplicationModeBean modeBean : appModeBeans) {
|
||||||
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
|
settingsItems.add(new ProfileSettingsItem(app, null, modeBean));
|
||||||
if (mode != null) {
|
|
||||||
settingsItems.add(new ProfileSettingsItem(app, mode));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!osmNotesPointList.isEmpty()) {
|
if (!osmNotesPointList.isEmpty()) {
|
||||||
|
|
|
@ -248,7 +248,14 @@ public class ExportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSelectedData() {
|
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() {
|
public List<? super Object> getData() {
|
||||||
|
|
|
@ -44,12 +44,9 @@ public class ExportSettingsFragment extends BaseSettingsListFragment {
|
||||||
public static final String TAG = ImportSettingsFragment.class.getSimpleName();
|
public static final String TAG = ImportSettingsFragment.class.getSimpleName();
|
||||||
public static final Log LOG = PlatformUtil.getLog(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 GLOBAL_EXPORT_KEY = "global_export_key";
|
||||||
private static final String EXPORT_START_TIME_KEY = "export_start_time_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 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_MAX_KEY = "progress_max_key";
|
||||||
private static final String PROGRESS_VALUE_KEY = "progress_value_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);
|
progressMax = savedInstanceState.getInt(PROGRESS_MAX_KEY);
|
||||||
progressValue = savedInstanceState.getInt(PROGRESS_VALUE_KEY);
|
progressValue = savedInstanceState.getInt(PROGRESS_VALUE_KEY);
|
||||||
}
|
}
|
||||||
dataList = app.getSettingsHelper().getAdditionalData(globalExport);
|
dataList = app.getSettingsHelper().getSettingsByCategory(globalExport);
|
||||||
|
|
||||||
requireActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
requireActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,7 +136,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment {
|
||||||
showExportProgressDialog();
|
showExportProgressDialog();
|
||||||
File tempDir = FileUtils.getTempDir(app);
|
File tempDir = FileUtils.getTempDir(app);
|
||||||
String fileName = getFileName();
|
String fileName = getFileName();
|
||||||
List<SettingsItem> items = app.getSettingsHelper().prepareAdditionalSettingsItems(adapter.getData());
|
List<SettingsItem> items = app.getSettingsHelper().prepareSettingsItems(adapter.getData());
|
||||||
progress.setMax(getMaxProgress(items));
|
progress.setMax(getMaxProgress(items));
|
||||||
app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true);
|
app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue