Add AIDL import/export profiles
This commit is contained in:
parent
9a6e401993
commit
47b0bc2ff0
18 changed files with 496 additions and 258 deletions
|
@ -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);
|
||||
}
|
|
@ -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<String> settingsTypeKeyList = new ArrayList<>();
|
||||
boolean replace;
|
||||
|
||||
public ProfileSettingsParams(Uri profileSettingsUri, String latestChanges, int version) {
|
||||
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<ExportSettingsType> 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<String> 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidlapi.profile;
|
||||
|
||||
parcelable ExportProfileParams;
|
|
@ -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<String> settingsTypeKeyList = new ArrayList<>();
|
||||
|
||||
public ExportProfileParams(String profile, ArrayList<ExportSettingsType> settingsTypeList) {
|
||||
|
||||
this.profile = profile;
|
||||
for (ExportSettingsType settingsType : settingsTypeList) {
|
||||
settingsTypeKeyList.add(settingsType.name());
|
||||
}
|
||||
}
|
||||
|
||||
public ExportProfileParams(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
public static final Creator<ExportProfileParams> CREATOR = new Creator<ExportProfileParams>() {
|
||||
@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<String> 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidlapi.profile;
|
||||
|
||||
parcelable ExportSettingsType;
|
|
@ -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;
|
||||
}
|
|
@ -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 {
|
||||
|
||||
|
@ -2249,9 +2251,12 @@ public class OsmandAidlApi {
|
|||
|
||||
private Map<String, FileCopyInfo> copyFilesCache = new ConcurrentHashMap<>();
|
||||
|
||||
public boolean importProfile(final Uri profileUri, String latestChanges, int version) {
|
||||
public boolean importProfile(final Uri profileUri, ArrayList<String> 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<String> settingsTypesKeys) {
|
||||
ApplicationMode appMode = ApplicationMode.valueOfStringKey(appModeKey, null);
|
||||
if (app != null && appMode != null) {
|
||||
List<ExportSettingsType> settingsTypes = new ArrayList<>();
|
||||
for (String key : settingsTypesKeys) {
|
||||
settingsTypes.add(ExportSettingsType.valueOf(key));
|
||||
}
|
||||
List<SettingsHelper.SettingsItem> 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<String> settingsTypeKeyList = new ArrayList<>();
|
||||
boolean replace;
|
||||
|
||||
public ProfileSettingsParams(Uri profileSettingsUri, String latestChanges, int version) {
|
||||
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<ExportSettingsType> 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<String> 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
|
||||
|
|
|
@ -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<List<SettingsItem>> 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<String> settingsTypeKeys = extras.getStringArrayList(SETTINGS_TYPE_LIST_KEY);
|
||||
List<ExportSettingsType> 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<ExportSettingsType> settingsTypes,
|
||||
final boolean replace,
|
||||
final String latestChanges, final int version,
|
||||
final CallbackWithObject<List<SettingsItem>> callback) {
|
||||
final AsyncTask<Void, Void, String> settingsImportTask = new AsyncTask<Void, Void, String>() {
|
||||
|
||||
|
@ -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<SettingsItem> items) {
|
||||
if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
|
@ -746,8 +770,14 @@ public class ImportHelper {
|
|||
handlePluginImport(pluginItem, file);
|
||||
}
|
||||
if (!pluginIndependentItems.isEmpty()) {
|
||||
if (settingsTypes == 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);
|
||||
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<Object> duplicates, List<SettingsItem> 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<SettingsItem> 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<ExportSettingsType, List<?>> getSettingsToOperate(List<SettingsItem> settingsItems, boolean importComplete) {
|
||||
Map<ExportSettingsType, List<?>> settingsToOperate = new HashMap<>();
|
||||
List<ApplicationMode.ApplicationModeBean> profiles = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
List<ITileSource> tileSourceTemplates = new ArrayList<>();
|
||||
List<File> routingFilesList = new ArrayList<>();
|
||||
List<File> renderFilesList = new ArrayList<>();
|
||||
List<AvoidSpecificRoads.AvoidRoadInfo> 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, ""));
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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<SettingsHelper.SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> additionalData,
|
||||
List<ExportSettingsType> settingsTypes) {
|
||||
List<SettingsHelper.SettingsItem> 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<ExportSettingsType, List<?>> getAdditionalData() {
|
||||
Map<ExportSettingsType, List<?>> dataList = new HashMap<>();
|
||||
|
||||
QuickActionRegistry registry = app.getQuickActionRegistry();
|
||||
List<QuickAction> actionsList = registry.getQuickActions();
|
||||
if (!actionsList.isEmpty()) {
|
||||
dataList.put(ExportSettingsType.QUICK_ACTIONS, actionsList);
|
||||
}
|
||||
|
||||
List<PoiUIFilter> poiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||
if (!poiList.isEmpty()) {
|
||||
dataList.put(ExportSettingsType.POI_TYPES, poiList);
|
||||
}
|
||||
|
||||
List<ITileSource> iTileSources = new ArrayList<>();
|
||||
Set<String> 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<String, File> 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<LatLon, AvoidRoadInfo> impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads();
|
||||
if (!impassableRoads.isEmpty()) {
|
||||
dataList.put(ExportSettingsType.AVOID_ROADS, new ArrayList<>(impassableRoads.values()));
|
||||
}
|
||||
return dataList;
|
||||
}
|
||||
|
||||
public List<SettingsItem> prepareAdditionalSettingsItems(List<? super Object> data) {
|
||||
List<SettingsItem> settingsItems = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
List<ITileSource> tileSourceTemplates = new ArrayList<>();
|
||||
List<AvoidRoadInfo> 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;
|
||||
}
|
||||
}
|
|
@ -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<? super Object> data;
|
||||
private Map<Type, List<?>> itemsMap;
|
||||
private List<Type> itemsTypes;
|
||||
private Map<ExportSettingsType, List<?>> itemsMap;
|
||||
private List<ExportSettingsType> 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;
|
||||
|
@ -328,7 +329,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
public void updateSettingsList(Map<Type, List<?>> itemsMap) {
|
||||
public void updateSettingsList(Map<ExportSettingsType, List<?>> itemsMap) {
|
||||
this.itemsMap = itemsMap;
|
||||
this.itemsTypes = new ArrayList<>(itemsMap.keySet());
|
||||
Collections.sort(itemsTypes);
|
||||
|
@ -354,14 +355,4 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
List<? super Object> getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
PROFILE,
|
||||
QUICK_ACTIONS,
|
||||
POI_TYPES,
|
||||
MAP_SOURCES,
|
||||
CUSTOM_RENDER_STYLE,
|
||||
CUSTOM_ROUTING,
|
||||
AVOID_ROADS
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Type, List<?>> dataList = new HashMap<>();
|
||||
private Map<ExportSettingsType, List<?>> 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<Type, List<?>> getAdditionalData() {
|
||||
Map<Type, List<?>> dataList = new HashMap<>();
|
||||
|
||||
|
||||
QuickActionRegistry registry = app.getQuickActionRegistry();
|
||||
List<QuickAction> actionsList = registry.getQuickActions();
|
||||
if (!actionsList.isEmpty()) {
|
||||
dataList.put(Type.QUICK_ACTIONS, actionsList);
|
||||
}
|
||||
|
||||
List<PoiUIFilter> poiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||
if (!poiList.isEmpty()) {
|
||||
dataList.put(Type.POI_TYPES, poiList);
|
||||
}
|
||||
|
||||
List<ITileSource> iTileSources = new ArrayList<>();
|
||||
Set<String> 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<String, File> 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<LatLon, AvoidRoadInfo> impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads();
|
||||
if (!impassableRoads.isEmpty()) {
|
||||
dataList.put(Type.AVOID_ROADS, new ArrayList<>(impassableRoads.values()));
|
||||
}
|
||||
return dataList;
|
||||
}
|
||||
|
||||
private List<SettingsItem> prepareSettingsItemsForExport() {
|
||||
List<SettingsItem> settingsItems = new ArrayList<>();
|
||||
settingsItems.add(new ProfileSettingsItem(app, profile));
|
||||
if (includeAdditionalData) {
|
||||
settingsItems.addAll(prepareAdditionalSettingsItems());
|
||||
}
|
||||
return settingsItems;
|
||||
}
|
||||
|
||||
private List<SettingsItem> prepareAdditionalSettingsItems() {
|
||||
List<SettingsItem> settingsItems = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
List<ITileSource> tileSourceTemplates = new ArrayList<>();
|
||||
List<AvoidRoadInfo> 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;
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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<Type, List<?>> itemsMap = new HashMap<>();
|
||||
Map<ExportSettingsType, List<?>> 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<Type, List<?>> getSettingsToOperate(List<SettingsItem> settingsItems, boolean importComplete) {
|
||||
Map<Type, List<?>> settingsToOperate = new HashMap<>();
|
||||
List<ApplicationModeBean> profiles = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
List<ITileSource> tileSourceTemplates = new ArrayList<>();
|
||||
List<File> routingFilesList = new ArrayList<>();
|
||||
List<File> renderFilesList = new ArrayList<>();
|
||||
List<AvoidRoadInfo> 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;
|
||||
|
|
|
@ -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,14 +25,14 @@ import java.util.Map;
|
|||
|
||||
public class ImportedSettingsItemsAdapter extends
|
||||
RecyclerView.Adapter<ImportedSettingsItemsAdapter.ItemViewHolder> {
|
||||
private Map<Type, List<?>> itemsMap;
|
||||
private List<Type> itemsTypes;
|
||||
private Map<ExportSettingsType, List<?>> itemsMap;
|
||||
private List<ExportSettingsType> itemsTypes;
|
||||
private UiUtilities uiUtils;
|
||||
private OsmandApplication app;
|
||||
private boolean nightMode;
|
||||
private OnItemClickListener listener;
|
||||
|
||||
ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, Map<Type, List<?>> itemsMap,
|
||||
ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, Map<ExportSettingsType, List<?>> itemsMap,
|
||||
boolean nightMode, OnItemClickListener listener) {
|
||||
this.app = app;
|
||||
this.itemsMap = itemsMap;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue