Migrate custom app modes
This commit is contained in:
parent
826eba624d
commit
2ada619bae
2 changed files with 58 additions and 37 deletions
|
@ -350,7 +350,9 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIconResName(String iconResName) {
|
public void setIconResName(String iconResName) {
|
||||||
app.getSettings().ICON_RES_NAME.setModeValue(this, iconResName);
|
if (!Algorithms.isEmpty(iconResName)) {
|
||||||
|
app.getSettings().ICON_RES_NAME.setModeValue(this, iconResName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAppModeIcon() {
|
private void updateAppModeIcon() {
|
||||||
|
@ -420,7 +422,9 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserProfileName(String userProfileName) {
|
public void setUserProfileName(String userProfileName) {
|
||||||
app.getSettings().USER_PROFILE_NAME.setModeValue(this, userProfileName);
|
if (!Algorithms.isEmpty(userProfileName)) {
|
||||||
|
app.getSettings().USER_PROFILE_NAME.setModeValue(this, userProfileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRoutingProfile() {
|
public String getRoutingProfile() {
|
||||||
|
@ -428,7 +432,9 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoutingProfile(String routingProfile) {
|
public void setRoutingProfile(String routingProfile) {
|
||||||
app.getSettings().ROUTING_PROFILE.setModeValue(this, routingProfile);
|
if (!Algorithms.isEmpty(routingProfile)) {
|
||||||
|
app.getSettings().ROUTING_PROFILE.setModeValue(this, routingProfile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RouteService getRouteService() {
|
public RouteService getRouteService() {
|
||||||
|
@ -436,7 +442,9 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRouteService(RouteService routeService) {
|
public void setRouteService(RouteService routeService) {
|
||||||
app.getSettings().ROUTE_SERVICE.setModeValue(this, routeService);
|
if (routeService != null) {
|
||||||
|
app.getSettings().ROUTE_SERVICE.setModeValue(this, routeService);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigationIcon getNavigationIcon() {
|
public NavigationIcon getNavigationIcon() {
|
||||||
|
@ -444,7 +452,9 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNavigationIcon(NavigationIcon navigationIcon) {
|
public void setNavigationIcon(NavigationIcon navigationIcon) {
|
||||||
app.getSettings().NAVIGATION_ICON.setModeValue(this, navigationIcon);
|
if (navigationIcon != null) {
|
||||||
|
app.getSettings().NAVIGATION_ICON.setModeValue(this, navigationIcon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocationIcon getLocationIcon() {
|
public LocationIcon getLocationIcon() {
|
||||||
|
@ -452,7 +462,9 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocationIcon(LocationIcon locationIcon) {
|
public void setLocationIcon(LocationIcon locationIcon) {
|
||||||
app.getSettings().LOCATION_ICON.setModeValue(this, locationIcon);
|
if (locationIcon != null) {
|
||||||
|
app.getSettings().LOCATION_ICON.setModeValue(this, locationIcon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileIconColors getIconColorInfo() {
|
public ProfileIconColors getIconColorInfo() {
|
||||||
|
@ -460,7 +472,9 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIconColor(ProfileIconColors iconColor) {
|
public void setIconColor(ProfileIconColors iconColor) {
|
||||||
app.getSettings().ICON_COLOR.setModeValue(this, iconColor);
|
if (iconColor != null) {
|
||||||
|
app.getSettings().ICON_COLOR.setModeValue(this, iconColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOrder() {
|
public int getOrder() {
|
||||||
|
@ -556,6 +570,7 @@ public class ApplicationMode {
|
||||||
mode = builder.customReg(app);
|
mode = builder.customReg(app);
|
||||||
initRegVisibility();
|
initRegVisibility();
|
||||||
}
|
}
|
||||||
|
reorderAppModes();
|
||||||
saveCustomAppModesToSettings(app);
|
saveCustomAppModesToSettings(app);
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
@ -566,7 +581,7 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApplicationModeBuilder fromModeBean(ApplicationModeBean modeBean) {
|
public static ApplicationModeBuilder fromModeBean(ApplicationModeBean modeBean) {
|
||||||
ApplicationModeBuilder builder = createCustomMode(valueOfStringKey(modeBean.parent, null), modeBean.stringKey);
|
ApplicationModeBuilder builder = createCustomMode(valueOfStringKey(modeBean.parent, CAR), modeBean.stringKey);
|
||||||
builder.setUserProfileName(modeBean.userProfileName);
|
builder.setUserProfileName(modeBean.userProfileName);
|
||||||
builder.setIconResName(modeBean.iconName);
|
builder.setIconResName(modeBean.iconName);
|
||||||
builder.setIconColor(modeBean.iconColor);
|
builder.setIconColor(modeBean.iconColor);
|
||||||
|
@ -659,9 +674,9 @@ public class ApplicationMode {
|
||||||
private String routingProfile;
|
private String routingProfile;
|
||||||
private String iconResName;
|
private String iconResName;
|
||||||
private ProfileIconColors iconColor;
|
private ProfileIconColors iconColor;
|
||||||
private Integer order;
|
|
||||||
private LocationIcon locationIcon;
|
private LocationIcon locationIcon;
|
||||||
private NavigationIcon navigationIcon;
|
private NavigationIcon navigationIcon;
|
||||||
|
private int order = -1;
|
||||||
|
|
||||||
public ApplicationMode getApplicationMode() {
|
public ApplicationMode getApplicationMode() {
|
||||||
return applicationMode;
|
return applicationMode;
|
||||||
|
@ -677,34 +692,21 @@ public class ApplicationMode {
|
||||||
values.add(applicationMode);
|
values.add(applicationMode);
|
||||||
|
|
||||||
applicationMode.app = app;
|
applicationMode.app = app;
|
||||||
applicationMode.minDistanceForTurn = applicationMode.parentAppMode.minDistanceForTurn;
|
|
||||||
applicationMode.arrivalDistance = applicationMode.parentAppMode.arrivalDistance;
|
|
||||||
applicationMode.offRouteDistance = applicationMode.parentAppMode.offRouteDistance;
|
|
||||||
|
|
||||||
if (userProfileName != null) {
|
ApplicationMode parent = applicationMode.parentAppMode;
|
||||||
applicationMode.setUserProfileName(userProfileName);
|
applicationMode.minDistanceForTurn = parent.minDistanceForTurn;
|
||||||
}
|
applicationMode.arrivalDistance = parent.arrivalDistance;
|
||||||
if (routeService != null) {
|
applicationMode.offRouteDistance = parent.offRouteDistance;
|
||||||
applicationMode.setRouteService(routeService);
|
|
||||||
}
|
applicationMode.setParentAppMode(parent);
|
||||||
if (routingProfile != null) {
|
applicationMode.setUserProfileName(userProfileName);
|
||||||
applicationMode.setRoutingProfile(routingProfile);
|
applicationMode.setRouteService(routeService);
|
||||||
}
|
applicationMode.setRoutingProfile(routingProfile);
|
||||||
if (iconResName != null) {
|
applicationMode.setIconResName(iconResName);
|
||||||
applicationMode.setIconResName(iconResName);
|
applicationMode.setIconColor(iconColor);
|
||||||
}
|
applicationMode.setLocationIcon(locationIcon);
|
||||||
if (iconColor != null) {
|
applicationMode.setNavigationIcon(navigationIcon);
|
||||||
applicationMode.setIconColor(iconColor);
|
applicationMode.setOrder(order != -1 ? order : values.size());
|
||||||
}
|
|
||||||
if (order != null) {
|
|
||||||
applicationMode.setOrder(order);
|
|
||||||
}
|
|
||||||
if (locationIcon != null) {
|
|
||||||
applicationMode.setLocationIcon(locationIcon);
|
|
||||||
}
|
|
||||||
if (navigationIcon != null) {
|
|
||||||
applicationMode.setNavigationIcon(navigationIcon);
|
|
||||||
}
|
|
||||||
|
|
||||||
return applicationMode;
|
return applicationMode;
|
||||||
}
|
}
|
||||||
|
@ -801,6 +803,6 @@ public class ApplicationMode {
|
||||||
@Expose
|
@Expose
|
||||||
NavigationIcon navIcon = null;
|
NavigationIcon navIcon = null;
|
||||||
@Expose
|
@Expose
|
||||||
int order;
|
int order = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,6 +19,10 @@ import android.support.annotation.StringRes;
|
||||||
import android.support.v4.util.Pair;
|
import android.support.v4.util.Pair;
|
||||||
import android.support.v7.preference.PreferenceDataStore;
|
import android.support.v7.preference.PreferenceDataStore;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.StateChangedListener;
|
import net.osmand.StateChangedListener;
|
||||||
import net.osmand.ValueHolder;
|
import net.osmand.ValueHolder;
|
||||||
|
@ -30,6 +34,7 @@ import net.osmand.map.ITileSource;
|
||||||
import net.osmand.map.TileSourceManager;
|
import net.osmand.map.TileSourceManager;
|
||||||
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||||
import net.osmand.osm.io.NetworkUtils;
|
import net.osmand.osm.io.NetworkUtils;
|
||||||
|
import net.osmand.plus.ApplicationMode.ApplicationModeBean;
|
||||||
import net.osmand.plus.access.AccessibilityMode;
|
import net.osmand.plus.access.AccessibilityMode;
|
||||||
import net.osmand.plus.access.RelativeDirectionStyle;
|
import net.osmand.plus.access.RelativeDirectionStyle;
|
||||||
import net.osmand.plus.api.SettingsAPI;
|
import net.osmand.plus.api.SettingsAPI;
|
||||||
|
@ -54,6 +59,7 @@ import org.json.JSONObject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -277,6 +283,19 @@ public class OsmandSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String json = settingsAPI.getString(globalPreferences, "custom_app_profiles", "");
|
||||||
|
if (!Algorithms.isEmpty(json)) {
|
||||||
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||||
|
Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {
|
||||||
|
}.getType();
|
||||||
|
List<ApplicationModeBean> customProfiles = gson.fromJson(json, t);
|
||||||
|
if (!Algorithms.isEmpty(customProfiles)) {
|
||||||
|
for (ApplicationModeBean modeBean : customProfiles) {
|
||||||
|
ApplicationMode.saveProfile(ApplicationMode.fromModeBean(modeBean), ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void migrateHomeWorkParkingToFavorites() {
|
void migrateHomeWorkParkingToFavorites() {
|
||||||
|
|
Loading…
Reference in a new issue