diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index c2437af48f..90b13ae2ff 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -520,9 +520,9 @@ public class ApplicationMode { String parent = settings.PARENT_APP_MODE.getValue(profilePreferences, null); int order = settings.APP_MODE_ORDER.getValue(profilePreferences, values.size()); - ApplicationModeBuilder builder = createCustomMode(valueOfStringKey(parent, CAR), appModeKey); + ApplicationModeBuilder builder = createCustomMode(valueOfStringKey(parent, CAR), appModeKey, app); builder.setOrder(order); - builder.customReg(app); + builder.customReg(); } } @@ -573,7 +573,7 @@ public class ApplicationMode { mode.setNavigationIcon(builder.navigationIcon); mode.setOrder(builder.order); } else { - mode = builder.customReg(app); + mode = builder.customReg(); initRegVisibility(); } reorderAppModes(); @@ -586,8 +586,8 @@ public class ApplicationMode { return gson.fromJson(json, ApplicationModeBean.class); } - public static ApplicationModeBuilder fromModeBean(ApplicationModeBean modeBean) { - ApplicationModeBuilder builder = createCustomMode(valueOfStringKey(modeBean.parent, null), modeBean.stringKey); + public static ApplicationModeBuilder fromModeBean(OsmandApplication app, ApplicationModeBean modeBean) { + ApplicationModeBuilder builder = createCustomMode(valueOfStringKey(modeBean.parent, null), modeBean.stringKey, app); builder.setUserProfileName(modeBean.userProfileName); builder.setIconResName(modeBean.iconName); builder.setIconColor(modeBean.iconColor); @@ -667,8 +667,10 @@ public class ApplicationMode { return builder; } - public static ApplicationModeBuilder createCustomMode(ApplicationMode parent, String stringKey) { - return create(parent, -1, stringKey); + public static ApplicationModeBuilder createCustomMode(ApplicationMode parent, String stringKey, OsmandApplication app) { + ApplicationModeBuilder builder = create(parent, -1, stringKey); + builder.getApplicationMode().app = app; + return builder; } public static class ApplicationModeBuilder { @@ -694,11 +696,9 @@ public class ApplicationMode { return applicationMode; } - private ApplicationMode customReg(OsmandApplication app) { + private ApplicationMode customReg() { values.add(applicationMode); - applicationMode.app = app; - ApplicationMode parent = applicationMode.parentAppMode; applicationMode.minDistanceForTurn = parent.minDistanceForTurn; applicationMode.arrivalDistance = parent.arrivalDistance; diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index ae338eff10..73105d8896 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -35,6 +35,7 @@ import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.ApplicationMode.ApplicationModeBean; +import net.osmand.plus.ApplicationMode.ApplicationModeBuilder; import net.osmand.plus.access.AccessibilityMode; import net.osmand.plus.access.RelativeDirectionStyle; import net.osmand.plus.api.SettingsAPI; @@ -292,7 +293,8 @@ public class OsmandSettings { List customProfiles = gson.fromJson(json, t); if (!Algorithms.isEmpty(customProfiles)) { for (ApplicationModeBean modeBean : customProfiles) { - ApplicationMode.saveProfile(ApplicationMode.fromModeBean(modeBean), ctx); + ApplicationModeBuilder builder = ApplicationMode.fromModeBean(ctx, modeBean); + ApplicationMode.saveProfile(builder, ctx); } } } diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 0d4fd1afc0..4c75032ce0 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -446,7 +446,7 @@ public class SettingsHelper { void readFromJson(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException { String appModeJson = json.getString("appMode"); modeBean = ApplicationMode.fromJson(appModeJson); - builder = ApplicationMode.fromModeBean(modeBean); + builder = ApplicationMode.fromModeBean(app, modeBean); ApplicationMode appMode = builder.getApplicationMode(); if (!appMode.isCustomProfile()) { appMode = ApplicationMode.valueOfStringKey(appMode.getStringKey(), appMode); diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 75e1767817..a99bb97b16 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -655,7 +655,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } if (isNew) { ApplicationMode.ApplicationModeBuilder builder = ApplicationMode - .createCustomMode(changedProfile.parent, changedProfile.stringKey) + .createCustomMode(changedProfile.parent, changedProfile.stringKey, app) .setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes)) .setUserProfileName(changedProfile.name.trim()) .setRoutingProfile(changedProfile.routingProfile)