From 47b0bc2ff07dc7c5a07cc0624bd652fc527797fa Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 1 Oct 2020 15:57:45 +0300 Subject: [PATCH] Add AIDL import/export profiles --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 8 + .../customization/ProfileSettingsParams.java | 42 ++++- .../aidlapi/profile/ExportProfileParams.aidl | 3 + .../aidlapi/profile/ExportProfileParams.java | 61 +++++++ .../aidlapi/profile/ExportSettingsType.aidl | 3 + .../aidlapi/profile/ExportSettingsType.java | 11 ++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 32 +++- .../net/osmand/aidl/OsmandAidlService.java | 3 +- .../net/osmand/aidl/OsmandAidlServiceV2.java | 15 +- .../customization/ProfileSettingsParams.java | 21 ++- .../net/osmand/plus/helpers/ImportHelper.java | 166 +++++++++++++++++- .../settings/backend/ExportSettingsType.java | 11 ++ .../plus/settings/backend/SettingsHelper.java | 107 +++++++++++ .../ExportImportSettingsAdapter.java | 37 ++-- .../fragments/ExportProfileBottomSheet.java | 119 +------------ .../fragments/ImportCompleteFragment.java | 9 +- .../fragments/ImportSettingsFragment.java | 92 +--------- .../ImportedSettingsItemsAdapter.java | 14 +- 18 files changed, 496 insertions(+), 258 deletions(-) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/profile/ExportProfileParams.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/profile/ExportProfileParams.java create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/profile/ExportSettingsType.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/profile/ExportSettingsType.java create mode 100644 OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index 3edd8c94da..3a8edb6d80 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -20,6 +20,8 @@ import net.osmand.aidlapi.mapmarker.UpdateMapMarkerParams; import net.osmand.aidlapi.calculateroute.CalculateRouteParams; +import net.osmand.aidlapi.profile.ExportProfileParams; + import net.osmand.aidlapi.gpx.ImportGpxParams; import net.osmand.aidlapi.gpx.ShowGpxParams; import net.osmand.aidlapi.gpx.StartGpxRecordingParams; @@ -103,6 +105,10 @@ import net.osmand.aidlapi.events.AKeyEventsParams; import net.osmand.aidlapi.info.AppInfoParams; +import net.osmand.aidlapi.profile.ExportProfileParams; +import net.osmand.aidlapi.profile.ExportSettingsType; + + // NOTE: Add new methods at the end of file!!! interface IOsmAndAidlInterface { @@ -867,4 +873,6 @@ interface IOsmAndAidlInterface { AppInfoParams getAppInfo(); boolean setMapMargins(in MapMarginsParams params); + + boolean exportProfile(in ExportProfileParams params); } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java index 36959ef776..427ccc71fd 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/customization/ProfileSettingsParams.java @@ -5,15 +5,31 @@ import android.os.Bundle; import android.os.Parcel; import net.osmand.aidlapi.AidlParams; +import net.osmand.aidlapi.profile.ExportSettingsType; + +import java.util.ArrayList; + +import static net.osmand.aidlapi.profile.ExportProfileParams.SETTINGS_TYPE_KEY; public class ProfileSettingsParams extends AidlParams { + public static final String VERSION_KEY = "version"; + public static final String REPLACE_KEY = "replace"; + public static final String LATEST_CHANGES_KEY = "latestChanges"; + public static final String PROFILE_SETTINGS_URI_KEY = "profileSettingsUri"; private Uri profileSettingsUri; private String latestChanges; private int version; + ArrayList settingsTypeKeyList = new ArrayList<>(); + boolean replace; - public ProfileSettingsParams(Uri profileSettingsUri, String latestChanges, int version) { + public ProfileSettingsParams(Uri profileSettingsUri, ArrayList settingsTypeList, boolean replace, + String latestChanges, int version) { this.profileSettingsUri = profileSettingsUri; + for (ExportSettingsType settingsType : settingsTypeList) { + settingsTypeKeyList.add(settingsType.name()); + } + this.replace = replace; this.latestChanges = latestChanges; this.version = version; } @@ -46,17 +62,29 @@ public class ProfileSettingsParams extends AidlParams { return profileSettingsUri; } + public ArrayList getSettingsTypeKeys() { + return settingsTypeKeyList; + } + + public boolean isReplace() { + return replace; + } + @Override public void writeToBundle(Bundle bundle) { - bundle.putInt("version", version); - bundle.putString("latestChanges", latestChanges); - bundle.putParcelable("profileSettingsUri", profileSettingsUri); + bundle.putInt(VERSION_KEY, version); + bundle.putString(LATEST_CHANGES_KEY, latestChanges); + bundle.putParcelable(PROFILE_SETTINGS_URI_KEY, profileSettingsUri); + bundle.putStringArrayList(SETTINGS_TYPE_KEY, settingsTypeKeyList); + bundle.putBoolean(REPLACE_KEY, replace); } @Override protected void readFromBundle(Bundle bundle) { - version = bundle.getInt("version"); - latestChanges = bundle.getString("latestChanges"); - profileSettingsUri = bundle.getParcelable("profileSettingsUri"); + version = bundle.getInt(VERSION_KEY); + latestChanges = bundle.getString(LATEST_CHANGES_KEY); + profileSettingsUri = bundle.getParcelable(PROFILE_SETTINGS_URI_KEY); + settingsTypeKeyList = bundle.getStringArrayList(SETTINGS_TYPE_KEY); + replace = bundle.getBoolean(REPLACE_KEY); } } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportProfileParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportProfileParams.aidl new file mode 100644 index 0000000000..0dfefce6be --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportProfileParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.profile; + +parcelable ExportProfileParams; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportProfileParams.java b/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportProfileParams.java new file mode 100644 index 0000000000..6298ccba04 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportProfileParams.java @@ -0,0 +1,61 @@ +package net.osmand.aidlapi.profile; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +import java.util.ArrayList; +import java.util.List; + +public class ExportProfileParams extends AidlParams { + + public static final String PROFILE_KEY = "profile"; + public static final String SETTINGS_TYPE_KEY = "settings_type"; + private String profile; + ArrayList settingsTypeKeyList = new ArrayList<>(); + + public ExportProfileParams(String profile, ArrayList settingsTypeList) { + + this.profile = profile; + for (ExportSettingsType settingsType : settingsTypeList) { + settingsTypeKeyList.add(settingsType.name()); + } + } + + public ExportProfileParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public ExportProfileParams createFromParcel(Parcel in) { + return new ExportProfileParams(in); + } + + @Override + public ExportProfileParams[] newArray(int size) { + return new ExportProfileParams[size]; + } + }; + + public String getProfile() { + return profile; + } + + public List getSettingsTypeKeys() { + return settingsTypeKeyList; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putString(PROFILE_KEY, profile); + bundle.putStringArrayList(SETTINGS_TYPE_KEY, settingsTypeKeyList); + } + + @Override + protected void readFromBundle(Bundle bundle) { + profile = bundle.getString(PROFILE_KEY); + settingsTypeKeyList = bundle.getStringArrayList(SETTINGS_TYPE_KEY); + } +} \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportSettingsType.aidl b/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportSettingsType.aidl new file mode 100644 index 0000000000..13ac783db1 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportSettingsType.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.profile; + +parcelable ExportSettingsType; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportSettingsType.java b/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportSettingsType.java new file mode 100644 index 0000000000..19bdad37dc --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/profile/ExportSettingsType.java @@ -0,0 +1,11 @@ +package net.osmand.aidlapi.profile; + +public enum ExportSettingsType { + PROFILE, + QUICK_ACTIONS, + POI_TYPES, + MAP_SOURCES, + CUSTOM_RENDER_STYLE, + CUSTOM_ROUTING, + AVOID_ROADS; +} diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 58dbdd1559..a86f48f714 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -81,6 +81,7 @@ import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.SettingsHelper; +import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.layers.AidlMapLayer; @@ -135,6 +136,7 @@ import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_NAME; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_TURN; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DISTANCE; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_IMMINENT; +import static net.osmand.plus.settings.backend.SettingsHelper.REPLACE_KEY; public class OsmandAidlApi { @@ -205,7 +207,7 @@ public class OsmandAidlApi { private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR; - private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[] { + private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{ ApplicationMode.CAR, ApplicationMode.BICYCLE, ApplicationMode.PEDESTRIAN @@ -285,7 +287,7 @@ public class OsmandAidlApi { } private void initOsmandTelegram() { - String[] packages = new String[] {"net.osmand.telegram", "net.osmand.telegram.debug"}; + String[] packages = new String[]{"net.osmand.telegram", "net.osmand.telegram.debug"}; Intent intent = new Intent("net.osmand.telegram.InitApp"); for (String pack : packages) { intent.setComponent(new ComponentName(pack, "net.osmand.telegram.InitAppBroadcastReceiver")); @@ -1016,7 +1018,7 @@ public class OsmandAidlApi { } if (!newName.equals(f.getName()) || !newDescription.equals(f.getDescription()) || !newCategory.equals(f.getCategory()) || !newAddress.equals(f.getAddress())) { - favoritesHelper.editFavouriteName(f, newName, newCategory, newDescription,newAddress); + favoritesHelper.editFavouriteName(f, newName, newCategory, newDescription, newAddress); } refreshMap(); return true; @@ -2249,9 +2251,12 @@ public class OsmandAidlApi { private Map copyFilesCache = new ConcurrentHashMap<>(); - public boolean importProfile(final Uri profileUri, String latestChanges, int version) { + public boolean importProfile(final Uri profileUri, ArrayList settingsTypeKeys, boolean replace, + String latestChanges, int version) { if (profileUri != null) { Bundle bundle = new Bundle(); + bundle.putStringArrayList(SettingsHelper.SETTINGS_TYPE_LIST_KEY, settingsTypeKeys); + bundle.putBoolean(REPLACE_KEY, replace); bundle.putString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY, latestChanges); bundle.putInt(SettingsHelper.SETTINGS_VERSION_KEY, version); @@ -2324,6 +2329,25 @@ public class OsmandAidlApi { return true; } + public boolean exportProfile(String appModeKey, List settingsTypesKeys) { + ApplicationMode appMode = ApplicationMode.valueOfStringKey(appModeKey, null); + if (app != null && appMode != null) { + List settingsTypes = new ArrayList<>(); + for (String key : settingsTypesKeys) { + settingsTypes.add(ExportSettingsType.valueOf(key)); + } + List settingsItems = new ArrayList<>(); + settingsItems.add(new SettingsHelper.ProfileSettingsItem(app, appMode)); + File tempDir = FileUtils.getTempDir(app); + String fileName = appMode.toHumanString(); + SettingsHelper settingsHelper = app.getSettingsHelper(); + settingsItems.addAll(settingsHelper.getFilteredSettingsItems(settingsHelper.getAdditionalData(), settingsTypes)); + settingsHelper.exportSettings(tempDir, fileName, null, settingsItems, true); + return true; + } + return false; + } + private static class FileCopyInfo { long startTime; long lastAccessTime; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index f1c9493fc8..17c87431e8 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -1299,7 +1299,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean importProfile(ProfileSettingsParams params) { try { OsmandAidlApi api = getApi("importProfile"); - return api != null && api.importProfile(params.getProfileSettingsUri(), params.getLatestChanges(), params.getVersion()); + return api != null && api.importProfile(params.getProfileSettingsUri(), params.getSettingsTypeKeys(), + params.isReplace(), params.getLatestChanges(), params.getVersion()); } catch (Exception e) { handleException(e); return false; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 333fd01895..4cd13d12da 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -85,6 +85,7 @@ import net.osmand.aidlapi.note.StartVideoRecordingParams; import net.osmand.aidlapi.note.StopRecordingParams; import net.osmand.aidlapi.note.TakePhotoNoteParams; import net.osmand.aidlapi.plugins.PluginParams; +import net.osmand.aidlapi.profile.ExportProfileParams; import net.osmand.aidlapi.quickaction.QuickActionInfoParams; import net.osmand.aidlapi.quickaction.QuickActionParams; import net.osmand.aidlapi.search.SearchParams; @@ -1258,7 +1259,19 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener public boolean importProfile(ProfileSettingsParams params) { try { OsmandAidlApi api = getApi("importProfile"); - return api != null && api.importProfile(params.getProfileSettingsUri(), params.getLatestChanges(), params.getVersion()); + return api != null && api.importProfile(params.getProfileSettingsUri(), params.getSettingsTypeKeys(), + params.isReplace(), params.getLatestChanges(), params.getVersion()); + } catch (Exception e) { + handleException(e); + return false; + } + } + + @Override + public boolean exportProfile(ExportProfileParams params) { + try { + OsmandAidlApi api = getApi("exportProfile"); + return api != null && api.exportProfile(params.getProfile(), params.getSettingsTypeKeys()); } catch (Exception e) { handleException(e); return false; diff --git a/OsmAnd/src/net/osmand/aidl/customization/ProfileSettingsParams.java b/OsmAnd/src/net/osmand/aidl/customization/ProfileSettingsParams.java index 6c2f82cd8f..cd5cfecddf 100644 --- a/OsmAnd/src/net/osmand/aidl/customization/ProfileSettingsParams.java +++ b/OsmAnd/src/net/osmand/aidl/customization/ProfileSettingsParams.java @@ -4,13 +4,20 @@ import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; +import net.osmand.aidlapi.profile.ExportSettingsType; + +import java.util.ArrayList; + public class ProfileSettingsParams implements Parcelable { private Uri profileSettingsUri; private String latestChanges; private int version; + ArrayList settingsTypeKeyList = new ArrayList<>(); + boolean replace; - public ProfileSettingsParams(Uri profileSettingsUri, String latestChanges, int version) { + public ProfileSettingsParams(Uri profileSettingsUri, ArrayList settingsTypeList, + boolean replace, String latestChanges, int version) { this.profileSettingsUri = profileSettingsUri; this.latestChanges = latestChanges; this.version = version; @@ -44,17 +51,29 @@ public class ProfileSettingsParams implements Parcelable { return profileSettingsUri; } + public ArrayList getSettingsTypeKeys() { + return settingsTypeKeyList; + } + + public boolean isReplace() { + return replace; + } + @Override public void writeToParcel(Parcel out, int flags) { out.writeInt(version); out.writeString(latestChanges); out.writeParcelable(profileSettingsUri, flags); + out.writeStringList(settingsTypeKeyList); + out.writeInt(replace ? 1 : 0); } private void readFromParcel(Parcel in) { version = in.readInt(); latestChanges = in.readString(); profileSettingsUri = in.readParcelable(Uri.class.getClassLoader()); + in.readStringList(settingsTypeKeyList); + replace = in.readInt() == 1; } @Override diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index e3dcb9cd2d..ec2cf92031 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -30,6 +30,7 @@ import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint.BackgroundType; +import net.osmand.map.ITileSource; import net.osmand.plus.AppInitializer; import net.osmand.plus.CustomOsmandPlugin; import net.osmand.plus.FavouritesDbHelper; @@ -42,7 +43,11 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.dialogs.ImportGpxBottomSheetDialogFragment; import net.osmand.plus.measurementtool.MeasurementToolFragment; +import net.osmand.plus.poi.PoiUIFilter; +import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.SettingsHelper; import net.osmand.plus.settings.backend.SettingsHelper.CheckDuplicatesListener; import net.osmand.plus.settings.backend.SettingsHelper.PluginSettingsItem; @@ -50,6 +55,7 @@ import net.osmand.plus.settings.backend.SettingsHelper.ProfileSettingsItem; import net.osmand.plus.settings.backend.SettingsHelper.SettingsCollectListener; import net.osmand.plus.settings.backend.SettingsHelper.SettingsImportListener; import net.osmand.plus.settings.backend.SettingsHelper.SettingsItem; +import net.osmand.plus.settings.fragments.ImportCompleteFragment; import net.osmand.plus.settings.fragments.ImportSettingsFragment; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.router.RoutingConfiguration; @@ -70,8 +76,10 @@ import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.zip.ZipInputStream; import static android.app.Activity.RESULT_OK; @@ -87,6 +95,7 @@ import static net.osmand.plus.AppInitializer.loadRoutingFiles; import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB; import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; +import static net.osmand.plus.settings.backend.SettingsHelper.*; /** * @author Koen Rabaey @@ -691,17 +700,31 @@ public class ImportHelper { } private void handleOsmAndSettingsImport(Uri intentUri, String fileName, Bundle extras, CallbackWithObject> callback) { - if (extras != null && extras.containsKey(SettingsHelper.SETTINGS_VERSION_KEY) && extras.containsKey(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY)) { - int version = extras.getInt(SettingsHelper.SETTINGS_VERSION_KEY, -1); - String latestChanges = extras.getString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY); - handleOsmAndSettingsImport(intentUri, fileName, latestChanges, version, callback); + if (extras != null && extras.containsKey(SETTINGS_VERSION_KEY) + && extras.containsKey(REPLACE_KEY) + && extras.containsKey(SETTINGS_LATEST_CHANGES_KEY) + && extras.containsKey(SETTINGS_TYPE_LIST_KEY)) { + int version = extras.getInt(SETTINGS_VERSION_KEY, -1); + String latestChanges = extras.getString(SETTINGS_LATEST_CHANGES_KEY); + boolean replace = extras.getBoolean(REPLACE_KEY); + ArrayList settingsTypeKeys = extras.getStringArrayList(SETTINGS_TYPE_LIST_KEY); + List settingsTypes = new ArrayList<>(); + if (settingsTypeKeys != null) { + for (String key : settingsTypeKeys) { + settingsTypes.add(ExportSettingsType.valueOf(key)); + } + } + handleOsmAndSettingsImport(intentUri, fileName, settingsTypes, replace, latestChanges, version, callback); } else { - handleOsmAndSettingsImport(intentUri, fileName, null, -1, callback); + handleOsmAndSettingsImport(intentUri, fileName, null, false, null, -1, callback); } } @SuppressLint("StaticFieldLeak") - private void handleOsmAndSettingsImport(final Uri uri, final String name, final String latestChanges, final int version, + private void handleOsmAndSettingsImport(final Uri uri, final String name, + final List settingsTypes, + final boolean replace, + final String latestChanges, final int version, final CallbackWithObject> callback) { final AsyncTask settingsImportTask = new AsyncTask() { @@ -726,7 +749,8 @@ public class ImportHelper { File tempDir = FileUtils.getTempDir(app); final File file = new File(tempDir, name); if (error == null && file.exists()) { - app.getSettingsHelper().collectSettings(file, latestChanges, version, new SettingsCollectListener() { + final SettingsHelper settingsHelper = app.getSettingsHelper(); + settingsHelper.collectSettings(file, latestChanges, version, new SettingsCollectListener() { @Override public void onSettingsCollectFinished(boolean succeed, boolean empty, @NonNull List items) { if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) { @@ -746,8 +770,14 @@ public class ImportHelper { handlePluginImport(pluginItem, file); } if (!pluginIndependentItems.isEmpty()) { - FragmentManager fragmentManager = activity.getSupportFragmentManager(); - ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file); + if (settingsTypes == null) { + FragmentManager fragmentManager = activity.getSupportFragmentManager(); + ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file); + } else { + Map> allSettingsList = getSettingsToOperate(pluginIndependentItems, false); + List settingsList = settingsHelper.getFilteredSettingsItems(allSettingsList, settingsTypes); + settingsHelper.checkDuplicates(file, settingsList, settingsList, getDuplicatesListener(file, replace)); + } } } else if (empty) { app.showShortToastMessage(app.getString(R.string.file_import_error, name, app.getString(R.string.shared_string_unexpected_error))); @@ -765,6 +795,124 @@ public class ImportHelper { executeImportTask(settingsImportTask); } + private CheckDuplicatesListener getDuplicatesListener(final File file, final boolean replace) { + return new CheckDuplicatesListener() { + @Override + public void onDuplicatesChecked(@NonNull List duplicates, List items) { + if (replace) { + for (SettingsItem item : items) { + item.setShouldReplace(true); + } + } + app.getSettingsHelper().importSettings(file, items, "", 1, getImportListener(file)); + } + }; + } + + private SettingsImportListener getImportListener(final File file) { + return new SettingsImportListener() { + @Override + public void onSettingsImportFinished(boolean succeed, @NonNull List items) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null && succeed) { + FragmentManager fm = mapActivity.getSupportFragmentManager(); + app.getRendererRegistry().updateExternalRenderers(); + AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() { + @Override + public void onRoutingFilesLoaded() { + } + }); + if (file != null) { + ImportCompleteFragment.showInstance(fm, items, file.getName()); + } + } + } + }; + } + + public static Map> getSettingsToOperate(List settingsItems, boolean importComplete) { + Map> settingsToOperate = new HashMap<>(); + List profiles = new ArrayList<>(); + List quickActions = new ArrayList<>(); + List poiUIFilters = new ArrayList<>(); + List tileSourceTemplates = new ArrayList<>(); + List routingFilesList = new ArrayList<>(); + List renderFilesList = new ArrayList<>(); + List avoidRoads = new ArrayList<>(); + for (SettingsItem item : settingsItems) { + switch (item.getType()) { + case PROFILE: + profiles.add(((ProfileSettingsItem) item).getModeBean()); + break; + case FILE: + FileSettingsItem fileItem = (FileSettingsItem) item; + if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.RENDERING_STYLE) { + renderFilesList.add(fileItem.getFile()); + } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.ROUTING_CONFIG) { + routingFilesList.add(fileItem.getFile()); + } + break; + case QUICK_ACTIONS: + QuickActionsSettingsItem quickActionsItem = (QuickActionsSettingsItem) item; + if (importComplete) { + quickActions.addAll(quickActionsItem.getAppliedItems()); + } else { + quickActions.addAll(quickActionsItem.getItems()); + } + break; + case POI_UI_FILTERS: + PoiUiFiltersSettingsItem poiUiFilterItem = (PoiUiFiltersSettingsItem) item; + if (importComplete) { + poiUIFilters.addAll(poiUiFilterItem.getAppliedItems()); + } else { + poiUIFilters.addAll(poiUiFilterItem.getItems()); + } + break; + case MAP_SOURCES: + MapSourcesSettingsItem mapSourcesItem = (MapSourcesSettingsItem) item; + if (importComplete) { + tileSourceTemplates.addAll(mapSourcesItem.getAppliedItems()); + } else { + tileSourceTemplates.addAll(mapSourcesItem.getItems()); + } + break; + case AVOID_ROADS: + AvoidRoadsSettingsItem avoidRoadsItem = (AvoidRoadsSettingsItem) item; + if (importComplete) { + avoidRoads.addAll(avoidRoadsItem.getAppliedItems()); + } else { + avoidRoads.addAll(avoidRoadsItem.getItems()); + } + break; + default: + break; + } + } + + if (!profiles.isEmpty()) { + settingsToOperate.put(ExportSettingsType.PROFILE, profiles); + } + if (!quickActions.isEmpty()) { + settingsToOperate.put(ExportSettingsType.QUICK_ACTIONS, quickActions); + } + if (!poiUIFilters.isEmpty()) { + settingsToOperate.put(ExportSettingsType.POI_TYPES, poiUIFilters); + } + if (!tileSourceTemplates.isEmpty()) { + settingsToOperate.put(ExportSettingsType.MAP_SOURCES, tileSourceTemplates); + } + if (!renderFilesList.isEmpty()) { + settingsToOperate.put(ExportSettingsType.CUSTOM_RENDER_STYLE, renderFilesList); + } + if (!routingFilesList.isEmpty()) { + settingsToOperate.put(ExportSettingsType.CUSTOM_ROUTING, routingFilesList); + } + if (!avoidRoads.isEmpty()) { + settingsToOperate.put(ExportSettingsType.AVOID_ROADS, avoidRoads); + } + return settingsToOperate; + } + private void handlePluginImport(final PluginSettingsItem pluginItem, final File file) { final ProgressDialog progress = new ProgressDialog(activity); progress.setTitle(app.getString(R.string.loading_smth, "")); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java new file mode 100644 index 0000000000..bda48d389f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java @@ -0,0 +1,11 @@ +package net.osmand.plus.settings.backend; + +public enum ExportSettingsType { + PROFILE, + QUICK_ACTIONS, + POI_TYPES, + MAP_SOURCES, + CUSTOM_RENDER_STYLE, + CUSTOM_ROUTING, + AVOID_ROADS +} diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/SettingsHelper.java index 2b5b4282d4..01ca1cb38c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/SettingsHelper.java @@ -100,6 +100,8 @@ public class SettingsHelper { public static final int VERSION = 1; + public static final String SETTINGS_TYPE_LIST_KEY = "settings_type_list_key"; + public static final String REPLACE_KEY = "replace"; public static final String SETTINGS_LATEST_CHANGES_KEY = "settings_latest_changes"; public static final String SETTINGS_VERSION_KEY = "settings_version"; @@ -2928,4 +2930,109 @@ public class SettingsHelper { CHECK_DUPLICATES, IMPORT } + + public List getFilteredSettingsItems(Map> additionalData, + List settingsTypes) { + List settingsItems = new ArrayList<>(); + for (ExportSettingsType settingsType : settingsTypes) { + List settingsDataObjects = additionalData.get(settingsType); + if (settingsDataObjects != null) { + settingsItems.addAll(app.getSettingsHelper().prepareAdditionalSettingsItems( + new ArrayList<>(settingsDataObjects))); + } + } + return settingsItems; + } + + public Map> getAdditionalData() { + Map> dataList = new HashMap<>(); + + QuickActionRegistry registry = app.getQuickActionRegistry(); + List actionsList = registry.getQuickActions(); + if (!actionsList.isEmpty()) { + dataList.put(ExportSettingsType.QUICK_ACTIONS, actionsList); + } + + List poiList = app.getPoiFilters().getUserDefinedPoiFilters(false); + if (!poiList.isEmpty()) { + dataList.put(ExportSettingsType.POI_TYPES, poiList); + } + + List iTileSources = new ArrayList<>(); + Set tileSourceNames = app.getSettings().getTileSourceEntries(true).keySet(); + for (String name : tileSourceNames) { + File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + name); + if (f != null) { + ITileSource template; + if (f.getName().endsWith(SQLiteTileSource.EXT)) { + template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates()); + } else { + template = TileSourceManager.createTileSourceTemplate(f); + } + if (template.getUrlTemplate() != null) { + iTileSources.add(template); + } + } + } + if (!iTileSources.isEmpty()) { + dataList.put(ExportSettingsType.MAP_SOURCES, iTileSources); + } + + Map externalRenderers = app.getRendererRegistry().getExternalRenderers(); + if (!externalRenderers.isEmpty()) { + dataList.put(ExportSettingsType.CUSTOM_RENDER_STYLE, new ArrayList<>(externalRenderers.values())); + } + + File routingProfilesFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR); + if (routingProfilesFolder.exists() && routingProfilesFolder.isDirectory()) { + File[] fl = routingProfilesFolder.listFiles(); + if (fl != null && fl.length > 0) { + dataList.put(ExportSettingsType.CUSTOM_ROUTING, Arrays.asList(fl)); + } + } + + Map impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads(); + if (!impassableRoads.isEmpty()) { + dataList.put(ExportSettingsType.AVOID_ROADS, new ArrayList<>(impassableRoads.values())); + } + return dataList; + } + + public List prepareAdditionalSettingsItems(List data) { + List settingsItems = new ArrayList<>(); + List quickActions = new ArrayList<>(); + List poiUIFilters = new ArrayList<>(); + List tileSourceTemplates = new ArrayList<>(); + List avoidRoads = new ArrayList<>(); + for (Object object : data) { + if (object instanceof QuickAction) { + quickActions.add((QuickAction) object); + } else if (object instanceof PoiUIFilter) { + poiUIFilters.add((PoiUIFilter) object); + } else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) { + tileSourceTemplates.add((ITileSource) object); + } else if (object instanceof File) { + try { + settingsItems.add(new FileSettingsItem(app, (File) object)); + } catch (IllegalArgumentException e) { + LOG.warn("Trying to export unsuported file type", e); + } + } else if (object instanceof AvoidRoadInfo) { + avoidRoads.add((AvoidRoadInfo) object); + } + } + if (!quickActions.isEmpty()) { + settingsItems.add(new QuickActionsSettingsItem(app, quickActions)); + } + if (!poiUIFilters.isEmpty()) { + settingsItems.add(new PoiUiFiltersSettingsItem(app, poiUIFilters)); + } + if (!tileSourceTemplates.isEmpty()) { + settingsItems.add(new MapSourcesSettingsItem(app, tileSourceTemplates)); + } + if (!avoidRoads.isEmpty()) { + settingsItems.add(new AvoidRoadsSettingsItem(app, avoidRoads)); + } + return settingsItems; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java index 18e8900203..01199ccff2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java @@ -16,6 +16,7 @@ import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; +import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmandApplication; @@ -50,8 +51,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { private OsmandApplication app; private UiUtilities uiUtilities; private List data; - private Map> itemsMap; - private List itemsTypes; + private Map> itemsMap; + private List itemsTypes; private boolean nightMode; private boolean importState; private int activeColorRes; @@ -82,7 +83,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { } boolean isLastGroup = groupPosition == getGroupCount() - 1; - final Type type = itemsTypes.get(groupPosition); + final ExportSettingsType type = itemsTypes.get(groupPosition); TextView titleTv = group.findViewById(R.id.title_tv); TextView subTextTv = group.findViewById(R.id.sub_text_tv); @@ -146,7 +147,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { boolean isLastGroup = groupPosition == getGroupCount() - 1; boolean itemSelected = data.contains(currentItem); - final Type type = itemsTypes.get(groupPosition); + final ExportSettingsType type = itemsTypes.get(groupPosition); TextView title = child.findViewById(R.id.title_tv); TextView subText = child.findViewById(R.id.sub_title_tv); @@ -299,7 +300,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { return app.getString(R.string.n_items_of_z, String.valueOf(amount), String.valueOf(listItems.size())); } - private int getGroupTitle(Type type) { + private int getGroupTitle(ExportSettingsType type) { switch (type) { case PROFILE: return R.string.shared_string_profiles; @@ -320,15 +321,15 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { } } - private void setupIcon(ImageView icon, int iconRes, boolean itemSelected) { - if (itemSelected) { - icon.setImageDrawable(uiUtilities.getIcon(iconRes, activeColorRes)); - } else { - icon.setImageDrawable(uiUtilities.getIcon(iconRes, nightMode)); - } - } + private void setupIcon(ImageView icon, int iconRes, boolean itemSelected) { + if (itemSelected) { + icon.setImageDrawable(uiUtilities.getIcon(iconRes, activeColorRes)); + } else { + icon.setImageDrawable(uiUtilities.getIcon(iconRes, nightMode)); + } + } - public void updateSettingsList(Map> itemsMap) { + public void updateSettingsList(Map> itemsMap) { this.itemsMap = itemsMap; this.itemsTypes = new ArrayList<>(itemsMap.keySet()); Collections.sort(itemsTypes); @@ -354,14 +355,4 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { List getData() { return this.data; } - - public enum Type { - PROFILE, - QUICK_ACTIONS, - POI_TYPES, - MAP_SOURCES, - CUSTOM_RENDER_STYLE, - CUSTOM_ROUTING, - AVOID_ROADS - } } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportProfileBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportProfileBottomSheet.java index 40fa4e290c..c95f7d578c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportProfileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportProfileBottomSheet.java @@ -24,43 +24,27 @@ import net.osmand.AndroidUtils; import net.osmand.FileUtils; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; -import net.osmand.data.LatLon; -import net.osmand.map.ITileSource; -import net.osmand.map.TileSourceManager; -import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; -import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; -import net.osmand.plus.poi.PoiUIFilter; -import net.osmand.plus.quickaction.QuickAction; -import net.osmand.plus.quickaction.QuickActionRegistry; +import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.SettingsHelper; -import net.osmand.plus.settings.backend.SettingsHelper.AvoidRoadsSettingsItem; -import net.osmand.plus.settings.backend.SettingsHelper.FileSettingsItem; -import net.osmand.plus.settings.backend.SettingsHelper.MapSourcesSettingsItem; -import net.osmand.plus.settings.backend.SettingsHelper.PoiUiFiltersSettingsItem; import net.osmand.plus.settings.backend.SettingsHelper.ProfileSettingsItem; -import net.osmand.plus.settings.backend.SettingsHelper.QuickActionsSettingsItem; import net.osmand.plus.settings.backend.SettingsHelper.SettingsItem; import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet; -import net.osmand.plus.settings.fragments.ExportImportSettingsAdapter.Type; import org.apache.commons.logging.Log; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { @@ -73,7 +57,7 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { private OsmandApplication app; private ApplicationMode profile; - private Map> dataList = new HashMap<>(); + private Map> dataList = new HashMap<>(); private ExportImportSettingsAdapter adapter; private SettingsHelper.SettingsExportListener exportListener; @@ -87,7 +71,7 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { super.onCreate(savedInstanceState); app = requiredMyApplication(); profile = getAppMode(); - dataList = getAdditionalData(); + dataList = app.getSettingsHelper().getAdditionalData(); if (savedInstanceState != null) { includeAdditionalData = savedInstanceState.getBoolean(INCLUDE_ADDITIONAL_DATA_KEY); exportingProfile = savedInstanceState.getBoolean(EXPORTING_PROFILE_KEY); @@ -146,7 +130,7 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { topSwitchDivider.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE); bottomSwitchDivider.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE); if (includeAdditionalData) { - adapter.updateSettingsList(getAdditionalData()); + adapter.updateSettingsList(app.getSettingsHelper().getAdditionalData()); adapter.selectAll(true); } else { adapter.selectAll(false); @@ -224,104 +208,11 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { } } - private Map> getAdditionalData() { - Map> dataList = new HashMap<>(); - - - QuickActionRegistry registry = app.getQuickActionRegistry(); - List actionsList = registry.getQuickActions(); - if (!actionsList.isEmpty()) { - dataList.put(Type.QUICK_ACTIONS, actionsList); - } - - List poiList = app.getPoiFilters().getUserDefinedPoiFilters(false); - if (!poiList.isEmpty()) { - dataList.put(Type.POI_TYPES, poiList); - } - - List iTileSources = new ArrayList<>(); - Set tileSourceNames = app.getSettings().getTileSourceEntries(true).keySet(); - for (String name : tileSourceNames) { - File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + name); - if (f != null) { - ITileSource template; - if (f.getName().endsWith(SQLiteTileSource.EXT)) { - template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates()); - } else { - template = TileSourceManager.createTileSourceTemplate(f); - } - if (template.getUrlTemplate() != null) { - iTileSources.add(template); - } - } - } - if (!iTileSources.isEmpty()) { - dataList.put(Type.MAP_SOURCES, iTileSources); - } - - Map externalRenderers = app.getRendererRegistry().getExternalRenderers(); - if (!externalRenderers.isEmpty()) { - dataList.put(Type.CUSTOM_RENDER_STYLE, new ArrayList<>(externalRenderers.values())); - } - - File routingProfilesFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR); - if (routingProfilesFolder.exists() && routingProfilesFolder.isDirectory()) { - File[] fl = routingProfilesFolder.listFiles(); - if (fl != null && fl.length > 0) { - dataList.put(Type.CUSTOM_ROUTING, Arrays.asList(fl)); - } - } - - Map impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads(); - if (!impassableRoads.isEmpty()) { - dataList.put(Type.AVOID_ROADS, new ArrayList<>(impassableRoads.values())); - } - return dataList; - } - private List prepareSettingsItemsForExport() { List settingsItems = new ArrayList<>(); settingsItems.add(new ProfileSettingsItem(app, profile)); if (includeAdditionalData) { - settingsItems.addAll(prepareAdditionalSettingsItems()); - } - return settingsItems; - } - - private List prepareAdditionalSettingsItems() { - List settingsItems = new ArrayList<>(); - List quickActions = new ArrayList<>(); - List poiUIFilters = new ArrayList<>(); - List tileSourceTemplates = new ArrayList<>(); - List avoidRoads = new ArrayList<>(); - for (Object object : adapter.getData()) { - if (object instanceof QuickAction) { - quickActions.add((QuickAction) object); - } else if (object instanceof PoiUIFilter) { - poiUIFilters.add((PoiUIFilter) object); - } else if (object instanceof TileSourceTemplate || object instanceof SQLiteTileSource) { - tileSourceTemplates.add((ITileSource) object); - } else if (object instanceof File) { - try { - settingsItems.add(new FileSettingsItem(app, (File) object)); - } catch (IllegalArgumentException e) { - LOG.warn("Trying to export unsuported file type", e); - } - } else if (object instanceof AvoidRoadInfo) { - avoidRoads.add((AvoidRoadInfo) object); - } - } - if (!quickActions.isEmpty()) { - settingsItems.add(new QuickActionsSettingsItem(app, quickActions)); - } - if (!poiUIFilters.isEmpty()) { - settingsItems.add(new PoiUiFiltersSettingsItem(app, poiUIFilters)); - } - if (!tileSourceTemplates.isEmpty()) { - settingsItems.add(new MapSourcesSettingsItem(app, tileSourceTemplates)); - } - if (!avoidRoads.isEmpty()) { - settingsItems.add(new AvoidRoadsSettingsItem(app, avoidRoads)); + settingsItems.addAll(app.getSettingsHelper().prepareAdditionalSettingsItems(adapter.getData())); } return settingsItems; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java index a18e2f6aa9..e152d5ea68 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java @@ -22,6 +22,8 @@ import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.helpers.ImportHelper; +import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.SettingsHelper.SettingsItem; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -31,7 +33,6 @@ import net.osmand.plus.dialogs.SelectMapStyleBottomSheetDialogFragment; import net.osmand.plus.quickaction.QuickActionListFragment; import net.osmand.plus.routepreparationmenu.AvoidRoadsBottomSheetDialogFragment; import net.osmand.plus.search.QuickSearchDialogFragment; -import net.osmand.plus.settings.fragments.ExportImportSettingsAdapter.Type; import java.util.List; @@ -117,11 +118,11 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { if (settingsItems != null) { ImportedSettingsItemsAdapter adapter = new ImportedSettingsItemsAdapter( app, - ImportSettingsFragment.getSettingsToOperate(settingsItems, true), + ImportHelper.getSettingsToOperate(settingsItems, true), nightMode, new ImportedSettingsItemsAdapter.OnItemClickListener() { @Override - public void onItemClick(Type type) { + public void onItemClick(ExportSettingsType type) { navigateTo(type); } }); @@ -137,7 +138,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { } } - private void navigateTo(Type type) { + private void navigateTo(ExportSettingsType type) { FragmentManager fm = getFragmentManager(); Activity activity = requireActivity(); if (fm == null || fm.isStateSaved()) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 284964b88d..051bf422f8 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -34,11 +34,11 @@ import net.osmand.plus.AppInitializer; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.SQLiteTileSource; +import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean; import net.osmand.plus.settings.backend.SettingsHelper; import net.osmand.plus.settings.backend.SettingsHelper.AvoidRoadsSettingsItem; import net.osmand.plus.settings.backend.SettingsHelper.FileSettingsItem; -import net.osmand.plus.settings.backend.SettingsHelper.FileSettingsItem.FileSubtype; import net.osmand.plus.settings.backend.SettingsHelper.ImportAsyncTask; import net.osmand.plus.settings.backend.SettingsHelper.ImportType; import net.osmand.plus.settings.backend.SettingsHelper.MapSourcesSettingsItem; @@ -53,7 +53,6 @@ import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; -import net.osmand.plus.settings.fragments.ExportImportSettingsAdapter.Type; import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; @@ -65,6 +64,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static net.osmand.plus.helpers.ImportHelper.getSettingsToOperate; + public class ImportSettingsFragment extends BaseOsmAndFragment implements View.OnClickListener { @@ -180,7 +181,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } adapter = new ExportImportSettingsAdapter(app, nightMode, true); - Map> itemsMap = new HashMap<>(); + Map> itemsMap = new HashMap<>(); if (settingsItems != null) { itemsMap = getSettingsToOperate(settingsItems, false); adapter.updateSettingsList(itemsMap); @@ -196,7 +197,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } else { toolbarLayout.setTitle(getString(R.string.shared_string_import)); } - if (itemsMap.size() == 1 && itemsMap.containsKey(Type.PROFILE)) { + if (itemsMap.size() == 1 && itemsMap.containsKey(ExportSettingsType.PROFILE)) { expandableList.expandGroup(0); } } @@ -420,89 +421,6 @@ public class ImportSettingsFragment extends BaseOsmAndFragment return settingsItems; } - public static Map> getSettingsToOperate(List settingsItems, boolean importComplete) { - Map> settingsToOperate = new HashMap<>(); - List profiles = new ArrayList<>(); - List quickActions = new ArrayList<>(); - List poiUIFilters = new ArrayList<>(); - List tileSourceTemplates = new ArrayList<>(); - List routingFilesList = new ArrayList<>(); - List renderFilesList = new ArrayList<>(); - List avoidRoads = new ArrayList<>(); - for (SettingsItem item : settingsItems) { - switch (item.getType()) { - case PROFILE: - profiles.add(((ProfileSettingsItem) item).getModeBean()); - break; - case FILE: - FileSettingsItem fileItem = (FileSettingsItem) item; - if (fileItem.getSubtype() == FileSubtype.RENDERING_STYLE) { - renderFilesList.add(fileItem.getFile()); - } else if (fileItem.getSubtype() == FileSubtype.ROUTING_CONFIG) { - routingFilesList.add(fileItem.getFile()); - } - break; - case QUICK_ACTIONS: - QuickActionsSettingsItem quickActionsItem = (QuickActionsSettingsItem) item; - if (importComplete) { - quickActions.addAll(quickActionsItem.getAppliedItems()); - } else { - quickActions.addAll(quickActionsItem.getItems()); - } - break; - case POI_UI_FILTERS: - PoiUiFiltersSettingsItem poiUiFilterItem = (PoiUiFiltersSettingsItem) item; - if (importComplete) { - poiUIFilters.addAll(poiUiFilterItem.getAppliedItems()); - } else { - poiUIFilters.addAll(poiUiFilterItem.getItems()); - } - break; - case MAP_SOURCES: - MapSourcesSettingsItem mapSourcesItem = (MapSourcesSettingsItem) item; - if (importComplete) { - tileSourceTemplates.addAll(mapSourcesItem.getAppliedItems()); - } else { - tileSourceTemplates.addAll(mapSourcesItem.getItems()); - } - break; - case AVOID_ROADS: - AvoidRoadsSettingsItem avoidRoadsItem = (AvoidRoadsSettingsItem) item; - if (importComplete) { - avoidRoads.addAll(avoidRoadsItem.getAppliedItems()); - } else { - avoidRoads.addAll(avoidRoadsItem.getItems()); - } - break; - default: - break; - } - } - - if (!profiles.isEmpty()) { - settingsToOperate.put(Type.PROFILE, profiles); - } - if (!quickActions.isEmpty()) { - settingsToOperate.put(Type.QUICK_ACTIONS, quickActions); - } - if (!poiUIFilters.isEmpty()) { - settingsToOperate.put(Type.POI_TYPES, poiUIFilters); - } - if (!tileSourceTemplates.isEmpty()) { - settingsToOperate.put(Type.MAP_SOURCES, tileSourceTemplates); - } - if (!renderFilesList.isEmpty()) { - settingsToOperate.put(Type.CUSTOM_RENDER_STYLE, renderFilesList); - } - if (!routingFilesList.isEmpty()) { - settingsToOperate.put(Type.CUSTOM_ROUTING, routingFilesList); - } - if (!avoidRoads.isEmpty()) { - settingsToOperate.put(Type.AVOID_ROADS, avoidRoads); - } - return settingsToOperate; - } - @Override public int getStatusBarColorId() { return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light; diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java index 270391c619..e663e6f189 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java @@ -14,7 +14,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.helpers.FontCache; -import net.osmand.plus.settings.fragments.ExportImportSettingsAdapter.Type; +import net.osmand.plus.settings.backend.ExportSettingsType; import java.util.ArrayList; @@ -25,15 +25,15 @@ import java.util.Map; public class ImportedSettingsItemsAdapter extends RecyclerView.Adapter { - private Map> itemsMap; - private List itemsTypes; + private Map> itemsMap; + private List itemsTypes; private UiUtilities uiUtils; private OsmandApplication app; private boolean nightMode; private OnItemClickListener listener; - ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, Map> itemsMap, - boolean nightMode, OnItemClickListener listener) { + ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, Map> itemsMap, + boolean nightMode, OnItemClickListener listener) { this.app = app; this.itemsMap = itemsMap; this.nightMode = nightMode; @@ -53,7 +53,7 @@ public class ImportedSettingsItemsAdapter extends @Override public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) { - final Type currentItemType = itemsTypes.get(position); + final ExportSettingsType currentItemType = itemsTypes.get(position); boolean isLastItem = itemsTypes.size() - 1 == position; int activeColorRes = nightMode ? R.color.active_color_primary_dark @@ -130,6 +130,6 @@ public class ImportedSettingsItemsAdapter extends } interface OnItemClickListener { - void onItemClick(Type type); + void onItemClick(ExportSettingsType type); } }