Merge pull request #9935 from osmandapp/convexis_api

Convexis api
This commit is contained in:
Vitaliy 2020-10-07 13:29:20 +03:00 committed by GitHub
commit 8e07c8290a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 568 additions and 306 deletions

View file

@ -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,8 @@ import net.osmand.aidlapi.events.AKeyEventsParams;
import net.osmand.aidlapi.info.AppInfoParams;
import net.osmand.aidlapi.profile.ExportProfileParams;
// NOTE: Add new methods at the end of file!!!
interface IOsmAndAidlInterface {
@ -867,4 +871,6 @@ interface IOsmAndAidlInterface {
AppInfoParams getAppInfo();
boolean setMapMargins(in MapMarginsParams params);
boolean exportProfile(in ExportProfileParams params);
}

View file

@ -4,6 +4,8 @@ public interface OsmAndCustomizationConstants {
// Navigation Drawer:
String DRAWER_ITEM_ID_SCHEME = "drawer.action.";
String DRAWER_SWITCH_PROFILE_ID = DRAWER_ITEM_ID_SCHEME + "switch_profile";
String DRAWER_CONFIGURE_PROFILE_ID = DRAWER_ITEM_ID_SCHEME + "configure_profile";
String DRAWER_DASHBOARD_ID = DRAWER_ITEM_ID_SCHEME + "dashboard";
String DRAWER_MAP_MARKERS_ID = DRAWER_ITEM_ID_SCHEME + "map_markers";
String DRAWER_MY_PLACES_ID = DRAWER_ITEM_ID_SCHEME + "my_places";

View file

@ -9,12 +9,21 @@ import net.osmand.aidlapi.AidlParams;
public class CopyFileParams extends AidlParams {
public static final String DESTINATION_DIR_KEY = "destinationDir";
public static final String FILE_NAME_KEY = "fileName";
public static final String FILE_PART_DATA_KEY = "filePartData";
public static final String START_TIME_KEY = "startTime";
public static final String DONE_KEY = "done";
private String destinationDir;
private String fileName;
private byte[] filePartData;
private long startTime;
private boolean done;
public CopyFileParams(@NonNull String fileName, @NonNull byte[] filePartData, long startTime, boolean done) {
public CopyFileParams(@NonNull String destinationDir, @NonNull String fileName, @NonNull byte[] filePartData,
long startTime, boolean done) {
this.destinationDir = destinationDir;
this.fileName = fileName;
this.filePartData = filePartData;
this.startTime = startTime;
@ -37,6 +46,10 @@ public class CopyFileParams extends AidlParams {
}
};
public String getDestinationDir() {
return destinationDir;
}
public String getFileName() {
return fileName;
}
@ -55,23 +68,26 @@ public class CopyFileParams extends AidlParams {
@Override
public void writeToBundle(Bundle bundle) {
bundle.putString("fileName", fileName);
bundle.putByteArray("filePartData", filePartData);
bundle.putLong("startTime", startTime);
bundle.putBoolean("done", done);
bundle.putString(DESTINATION_DIR_KEY, destinationDir);
bundle.putString(FILE_NAME_KEY, fileName);
bundle.putByteArray(FILE_PART_DATA_KEY, filePartData);
bundle.putLong(START_TIME_KEY, startTime);
bundle.putBoolean(DONE_KEY, done);
}
@Override
protected void readFromBundle(Bundle bundle) {
fileName = bundle.getString("fileName");
filePartData = bundle.getByteArray("filePartData");
startTime = bundle.getLong("startTime");
done = bundle.getBoolean("done");
destinationDir = bundle.getString(DESTINATION_DIR_KEY);
fileName = bundle.getString(FILE_NAME_KEY);
filePartData = bundle.getByteArray(FILE_PART_DATA_KEY);
startTime = bundle.getLong(START_TIME_KEY);
done = bundle.getBoolean(DONE_KEY);
}
@Override
public String toString() {
return "CopyFileParams {" +
" destinationDir=" + destinationDir +
" fileName=" + fileName +
", filePartData size=" + filePartData.length +
", startTime=" + startTime +

View file

@ -5,15 +5,31 @@ import android.os.Bundle;
import android.os.Parcel;
import net.osmand.aidlapi.AidlParams;
import net.osmand.aidlapi.profile.AExportSettingsType;
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;
private ArrayList<String> settingsTypeKeyList = new ArrayList<>();
boolean replace;
public ProfileSettingsParams(Uri profileSettingsUri, String latestChanges, int version) {
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<AExportSettingsType> settingsTypeList, boolean replace,
String latestChanges, int version) {
this.profileSettingsUri = profileSettingsUri;
for (AExportSettingsType 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);
}
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidlapi.profile;
parcelable AExportSettingsType;

View file

@ -0,0 +1,11 @@
package net.osmand.aidlapi.profile;
public enum AExportSettingsType {
PROFILE,
QUICK_ACTIONS,
POI_TYPES,
MAP_SOURCES,
CUSTOM_RENDER_STYLE,
CUSTOM_ROUTING,
AVOID_ROADS;
}

View file

@ -0,0 +1,3 @@
package net.osmand.aidlapi.profile;
parcelable ExportProfileParams;

View file

@ -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;
private ArrayList<String> settingsTypeKeyList = new ArrayList<>();
public ExportProfileParams(String profile, ArrayList<AExportSettingsType> settingsTypeList) {
this.profile = profile;
for (AExportSettingsType 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);
}
}

View file

@ -205,10 +205,7 @@ public class FileUtils {
if (!src.exists()) {
return null;
}
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
if (!tempDir.exists()) {
tempDir.mkdirs();
}
File tempDir = getTempDir(app);
File dest = new File(tempDir, src.getName());
try {
Algorithms.fileCopy(src, dest);
@ -218,6 +215,14 @@ public class FileUtils {
return dest;
}
public static File getTempDir(OsmandApplication app) {
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
if (!tempDir.exists()) {
tempDir.mkdirs();
}
return tempDir;
}
public interface RenameCallback {
void renamedTo(File file);
}

View file

@ -26,9 +26,11 @@ import com.google.gson.reflect.TypeToken;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.FileUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.PlatformUtil;
@ -80,6 +82,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;
@ -129,11 +132,13 @@ import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PART_SIZE_LIMIT_E
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_UNSUPPORTED_FILE_TYPE_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.OK_RESPONSE;
import static net.osmand.plus.FavouritesDbHelper.FILE_TO_SAVE;
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_LANES;
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 {
@ -204,7 +209,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
@ -284,7 +289,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"));
@ -1015,7 +1020,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;
@ -2260,6 +2265,21 @@ public class OsmandAidlApi {
return false;
}
public boolean importProfileV2(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);
MapActivity.launchMapActivityMoveToTop(app, null, profileUri, bundle);
return true;
}
return false;
}
public void registerLayerContextMenu(ContextMenuAdapter adapter, MapActivity mapActivity) {
for (ConnectedApp connectedApp : getConnectedApps()) {
if (!connectedApp.getLayers().isEmpty()) {
@ -2323,6 +2343,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 exportDir = app.getSettings().getExternalStorageDirectory();
String fileName = appMode.toHumanString();
SettingsHelper settingsHelper = app.getSettingsHelper();
settingsItems.addAll(settingsHelper.getFilteredSettingsItems(settingsHelper.getAdditionalData(), settingsTypes));
settingsHelper.exportSettings(exportDir, fileName, null, settingsItems, true);
return true;
}
return false;
}
private static class FileCopyInfo {
long startTime;
long lastAccessTime;
@ -2349,13 +2388,35 @@ public class OsmandAidlApi {
}
}
private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) {
File file = app.getAppPath(IndexConstants.TEMP_DIR + fileName);
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
if (!tempDir.exists()) {
tempDir.mkdirs();
int copyFileV2(String destinationDir, String fileName, byte[] filePartData, long startTime, boolean done) {
if (Algorithms.isEmpty(fileName) || filePartData == null) {
return COPY_FILE_PARAMS_ERROR;
}
File destFile = app.getAppPath(destinationDir + fileName);
if (filePartData.length > COPY_FILE_PART_SIZE_LIMIT) {
return COPY_FILE_PART_SIZE_LIMIT_ERROR;
}
int result = copyFileImpl(fileName, filePartData, startTime, done, destinationDir);
if (done) {
if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) && IndexConstants.MAPS_PATH.equals(destinationDir)) {
app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList<String>());
app.getDownloadThread().updateLoadedFiles();
} else if (fileName.endsWith(IndexConstants.GPX_FILE_EXT)) {
if (destinationDir.startsWith(IndexConstants.GPX_INDEX_DIR)
&& !FILE_TO_SAVE.equals(fileName)) {
destinationDir = destinationDir.replaceFirst(IndexConstants.GPX_INDEX_DIR, "");
showGpx(new File(destinationDir, fileName).getPath());
} else if (destinationDir.isEmpty() && FILE_TO_SAVE.equals(fileName)) {
app.getFavorites().loadFavorites();
}
}
}
return result;
}
private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) {
File tempDir = FileUtils.getTempDir(app);
File file = new File(tempDir, fileName);
File destFile = app.getAppPath(new File(destinationDir, fileName).getPath());
long currentTime = System.currentTimeMillis();
try {
FileCopyInfo info = copyFilesCache.get(fileName);

View file

@ -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.getLatestChanges(),
params.getVersion());
} catch (Exception e) {
handleException(e);
return false;

View file

@ -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;
@ -1091,7 +1092,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
if (api == null) {
return CANNOT_ACCESS_API_ERROR;
}
return api.copyFile(params.getFileName(), params.getFilePartData(), params.getStartTime(), params.isDone());
return api.copyFileV2(params.getDestinationDir(), params.getFileName(), params.getFilePartData(),
params.getStartTime(), params.isDone());
} catch (Exception e) {
handleException(e);
return UNKNOWN_API_ERROR;
@ -1258,7 +1260,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.importProfileV2(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;

View file

@ -91,6 +91,7 @@ import java.util.Map;
import static net.osmand.IndexConstants.GPX_FILE_EXT;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_MAP_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_PROFILE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_SCREEN_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DASHBOARD_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIRECTIONS_ID;
@ -104,6 +105,7 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_OSMAND_LIVE
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_PLUGINS_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SEARCH_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SWITCH_PROFILE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_TRAVEL_GUIDES_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_GPX_WAYPOINT;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_ID;
@ -145,7 +147,7 @@ public class MapActivityActions implements DialogProvider {
private static final int DIALOG_RELOAD_TITLE = 103;
private static final int DIALOG_SAVE_DIRECTIONS = 106;
private static final int DRAWER_MODE_NORMAL = 0;
private static final int DRAWER_MODE_SWITCH_PROFILE = 1;
@ -476,7 +478,7 @@ public class MapActivityActions implements DialogProvider {
mapActivity.showQuickSearch(latitude, longitude);
} else if (standardId == R.string.context_menu_item_directions_from) {
//if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
enterDirectionsFromPoint(latitude, longitude);
enterDirectionsFromPoint(latitude, longitude);
//} else {
// ActivityCompat.requestPermissions(mapActivity,
// new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
@ -535,17 +537,17 @@ public class MapActivityActions implements DialogProvider {
}
public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, LatLon from, PointDescription fromName,
boolean useIntermediatePointsByDefault, boolean showMenu) {
boolean useIntermediatePointsByDefault, boolean showMenu) {
enterRoutePlanningModeGivenGpx(gpxFile, from, fromName, useIntermediatePointsByDefault, showMenu, MapRouteInfoMenu.DEFAULT_MENU_STATE);
}
public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, LatLon from, PointDescription fromName,
boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
enterRoutePlanningModeGivenGpx(gpxFile, null, from, fromName, useIntermediatePointsByDefault, showMenu, menuState);
}
public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, ApplicationMode appMode, LatLon from, PointDescription fromName,
boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
settings.USE_INTERMEDIATE_POINTS_NAVIGATION.set(useIntermediatePointsByDefault);
OsmandApplication app = mapActivity.getMyApplication();
TargetPointsHelper targets = app.getTargetPointsHelper();
@ -727,7 +729,7 @@ public class MapActivityActions implements DialogProvider {
private ContextMenuAdapter createSwitchProfileOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
drawerMode = DRAWER_MODE_NORMAL;
createProfilesController(app, optionsMenuHelper, nightMode, true);
List<ApplicationMode> activeModes = ApplicationMode.values(app);
ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get();
@ -759,7 +761,7 @@ public class MapActivityActions implements DialogProvider {
})
.createItem());
}
int activeColorPrimaryResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item)
.setColor(activeColorPrimaryResId)
@ -778,7 +780,7 @@ public class MapActivityActions implements DialogProvider {
}
private ContextMenuAdapter createNormalOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
createProfilesController(app, optionsMenuHelper, nightMode, false);
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.home, mapActivity)
@ -1055,6 +1057,7 @@ public class MapActivityActions implements DialogProvider {
int icArrowResId = listExpanded ? R.drawable.ic_action_arrow_drop_up : R.drawable.ic_action_arrow_drop_down;
final int nextMode = listExpanded ? DRAWER_MODE_NORMAL : DRAWER_MODE_SWITCH_PROFILE;
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_switch_profile)
.setId(DRAWER_SWITCH_PROFILE_ID)
.setIcon(currentMode.getIconRes())
.setSecondaryIcon(icArrowResId)
.setColor(currentMode.getIconColorInfo().getColor(nightMode))
@ -1070,6 +1073,7 @@ public class MapActivityActions implements DialogProvider {
})
.createItem());
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_configure_profile)
.setId(DRAWER_CONFIGURE_PROFILE_ID)
.setColor(currentMode.getIconColorInfo().getColor(nightMode))
.setTitle(getString(R.string.configure_profile))
.setListener(new ItemClickListener() {
@ -1084,8 +1088,8 @@ public class MapActivityActions implements DialogProvider {
}
private String getProfileDescription(OsmandApplication app, ApplicationMode mode,
Map<String, RoutingProfileDataObject> profilesObjects, String defaultDescription){
String description = defaultDescription;
Map<String, RoutingProfileDataObject> profilesObjects, String defaultDescription) {
String description = defaultDescription;
String routingProfileKey = mode.getRoutingProfile();
if (!Algorithms.isEmpty(routingProfileKey)) {

View file

@ -21,6 +21,7 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.FileUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
@ -29,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;
@ -41,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;
@ -49,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;
@ -69,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;
@ -86,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
@ -690,17 +700,29 @@ 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(SETTINGS_LATEST_CHANGES_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>() {
@ -715,20 +737,18 @@ public class ImportHelper {
@Override
protected String doInBackground(Void... voids) {
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
if (!tempDir.exists()) {
tempDir.mkdirs();
}
File tempDir = FileUtils.getTempDir(app);
File dest = new File(tempDir, name);
return copyFile(app, dest, uri, true);
}
@Override
protected void onPostExecute(String error) {
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
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)) {
@ -748,8 +768,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<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)));
@ -767,6 +793,120 @@ 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, null);
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, ""));

View file

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

View file

@ -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,108 @@ public class SettingsHelper {
CHECK_DUPLICATES,
IMPORT
}
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> additionalData,
List<ExportSettingsType> settingsTypes) {
List<SettingsItem> settingsItems = new ArrayList<>();
for (ExportSettingsType settingsType : settingsTypes) {
List<?> settingsDataObjects = additionalData.get(settingsType);
if (settingsDataObjects != null) {
settingsItems.addAll(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;
}
}

View file

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

View file

@ -21,45 +21,30 @@ import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
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 {
@ -72,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;
@ -86,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);
@ -145,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);
@ -223,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;
}
@ -329,7 +221,7 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
if (app != null) {
exportingProfile = true;
showExportProgressDialog();
File tempDir = getTempDir();
File tempDir = FileUtils.getTempDir(app);
String fileName = profile.toHumanString();
app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), prepareSettingsItemsForExport(), true);
}
@ -391,19 +283,11 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
}
private File getExportFile() {
File tempDir = getTempDir();
File tempDir = FileUtils.getTempDir(app);
String fileName = profile.toHumanString();
return new File(tempDir, fileName + IndexConstants.OSMAND_SETTINGS_FILE_EXT);
}
private File getTempDir() {
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
if (!tempDir.exists()) {
tempDir.mkdirs();
}
return tempDir;
}
private void shareProfile(@NonNull File file, @NonNull ApplicationMode profile) {
try {
final Intent sendIntent = new Intent();

View file

@ -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()) {

View file

@ -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);
}
}
@ -266,11 +267,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
FragmentManager fm = getFragmentManager();
if (succeed) {
app.getRendererRegistry().updateExternalRenderers();
AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
@Override
public void onRoutingFilesLoaded() {
}
});
AppInitializer.loadRoutingFiles(app, null);
if (fm != null && file != null) {
ImportCompleteFragment.showInstance(fm, items, file.getName());
}
@ -420,89 +417,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;

View file

@ -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<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,
boolean nightMode, OnItemClickListener listener) {
ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, Map<ExportSettingsType, List<?>> 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);
}
}