Merge pull request #10355 from osmandapp/export_fixes

Fix profiles export
This commit is contained in:
vshcherb 2020-12-07 17:29:12 +01:00 committed by GitHub
commit ca0c794a71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 15 deletions

View file

@ -2313,7 +2313,7 @@ public class OsmandAidlApi {
File exportDir = app.getSettings().getExternalStorageDirectory();
String fileName = appMode.toHumanString();
SettingsHelper settingsHelper = app.getSettingsHelper();
settingsItems.addAll(settingsHelper.getFilteredSettingsItems(settingsTypes, false));
settingsItems.addAll(settingsHelper.getFilteredSettingsItems(settingsTypes, false, true));
settingsHelper.exportSettings(exportDir, fileName, null, settingsItems, true);
return true;
}

View file

@ -100,7 +100,7 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
}
} else {
Map<ExportSettingsType, List<?>> allSettingsMap = getSettingsToOperate(pluginIndependentItems, false);
List<SettingsItem> settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes);
List<SettingsItem> settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes, false);
settingsHelper.checkDuplicates(file, settingsList, settingsList, getDuplicatesListener(file, replace));
}
}

View file

@ -473,31 +473,31 @@ public class SettingsHelper {
exportSettings(fileDir, fileName, listener, new ArrayList<>(Arrays.asList(items)), exportItemsFiles);
}
public List<SettingsItem> getFilteredSettingsItems(List<ExportSettingsType> settingsTypes, boolean globalExport) {
public List<SettingsItem> getFilteredSettingsItems(List<ExportSettingsType> settingsTypes, boolean addProfiles, boolean export) {
Map<ExportSettingsType, List<?>> typesMap = new HashMap<>();
typesMap.putAll(getSettingsItems(globalExport));
typesMap.putAll(getSettingsItems(addProfiles));
typesMap.putAll(getMyPlacesItems());
typesMap.putAll(getResourcesItems());
return getFilteredSettingsItems(typesMap, settingsTypes);
return getFilteredSettingsItems(typesMap, settingsTypes, export);
}
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> allSettingsMap,
List<ExportSettingsType> settingsTypes) {
List<ExportSettingsType> settingsTypes, boolean export) {
List<SettingsItem> settingsItems = new ArrayList<>();
for (ExportSettingsType settingsType : settingsTypes) {
List<?> settingsDataObjects = allSettingsMap.get(settingsType);
if (settingsDataObjects != null) {
settingsItems.addAll(prepareSettingsItems(new ArrayList<>(settingsDataObjects)));
settingsItems.addAll(prepareSettingsItems(settingsDataObjects, export));
}
}
return settingsItems;
}
public Map<ExportSettingsCategory, SettingsCategoryItems> getSettingsByCategory(boolean globalExport) {
public Map<ExportSettingsCategory, SettingsCategoryItems> getSettingsByCategory(boolean addProfiles) {
Map<ExportSettingsCategory, SettingsCategoryItems> dataList = new LinkedHashMap<>();
Map<ExportSettingsType, List<?>> settingsItems = getSettingsItems(globalExport);
Map<ExportSettingsType, List<?>> settingsItems = getSettingsItems(addProfiles);
Map<ExportSettingsType, List<?>> myPlacesItems = getMyPlacesItems();
Map<ExportSettingsType, List<?>> resourcesItems = getResourcesItems();
@ -514,10 +514,10 @@ public class SettingsHelper {
return dataList;
}
private Map<ExportSettingsType, List<?>> getSettingsItems(boolean globalExport) {
private Map<ExportSettingsType, List<?>> getSettingsItems(boolean addProfiles) {
Map<ExportSettingsType, List<?>> settingsItems = new LinkedHashMap<>();
if (globalExport) {
if (addProfiles) {
List<ApplicationModeBean> appModeBeans = new ArrayList<>();
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
appModeBeans.add(mode.toModeBean());
@ -688,7 +688,7 @@ public class SettingsHelper {
return files;
}
public List<SettingsItem> prepareSettingsItems(List<? super Object> data) {
public List<SettingsItem> prepareSettingsItems(List<?> data, boolean export) {
List<SettingsItem> settingsItems = new ArrayList<>();
List<QuickAction> quickActions = new ArrayList<>();
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
@ -755,7 +755,14 @@ public class SettingsHelper {
}
if (!appModeBeans.isEmpty()) {
for (ApplicationModeBean modeBean : appModeBeans) {
settingsItems.add(new ProfileSettingsItem(app, null, modeBean));
if (export) {
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
if (mode != null) {
settingsItems.add(new ProfileSettingsItem(app, mode));
}
} else {
settingsItems.add(new ProfileSettingsItem(app, null, modeBean));
}
}
}
if (!osmNotesPointList.isEmpty()) {

View file

@ -24,14 +24,18 @@ import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
import net.osmand.plus.settings.backend.ExportSettingsType;
import net.osmand.plus.settings.backend.backup.FileSettingsItem;
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsExportListener;
import net.osmand.plus.settings.backend.backup.SettingsItem;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@ -73,7 +77,10 @@ public class ExportSettingsFragment extends BaseSettingsListFragment {
progressValue = savedInstanceState.getInt(PROGRESS_VALUE_KEY);
}
exportMode = true;
dataList = app.getSettingsHelper().getSettingsByCategory(globalExport);
dataList = app.getSettingsHelper().getSettingsByCategory(true);
if (!globalExport && savedInstanceState == null) {
updateSelectedProfile();
}
}
@Nullable
@ -122,6 +129,20 @@ public class ExportSettingsFragment extends BaseSettingsListFragment {
}
}
private void updateSelectedProfile() {
List<Object> profileItems = getItemsForType(ExportSettingsType.PROFILE);
if (!Algorithms.isEmpty(profileItems)) {
for (Object item : profileItems) {
if (item instanceof ApplicationModeBean && appMode.getStringKey().equals(((ApplicationModeBean) item).stringKey)) {
List<Object> selectedProfiles = new ArrayList<>();
selectedProfiles.add(item);
selectedItemsMap.put(ExportSettingsType.PROFILE, selectedProfiles);
break;
}
}
}
}
private void prepareFile() {
if (app != null) {
exportingStarted = true;
@ -129,7 +150,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment {
showExportProgressDialog();
File tempDir = FileUtils.getTempDir(app);
String fileName = getFileName();
List<SettingsItem> items = app.getSettingsHelper().prepareSettingsItems(adapter.getData());
List<SettingsItem> items = app.getSettingsHelper().prepareSettingsItems(adapter.getData(), true);
progress.setMax(getMaxProgress(items));
app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true);
}