diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteLineDrawInfo.java b/OsmAnd/src/net/osmand/plus/routing/RouteLineDrawInfo.java index d4660bffc9..627be2d9e8 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteLineDrawInfo.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteLineDrawInfo.java @@ -17,6 +17,7 @@ public class RouteLineDrawInfo { private static final String CENTER_X = "center_x"; private static final String CENTER_Y = "center_y"; private static final String SCREEN_HEIGHT = "screen_height"; + private static final String APP_MODE_KEY = "app_mode_key"; // parameters to save @ColorInt @@ -30,6 +31,7 @@ public class RouteLineDrawInfo { private int centerX; private int centerY; private int screenHeight; + private String appModeKey; public RouteLineDrawInfo(@Nullable @ColorInt Integer color, @Nullable String width) { @@ -49,16 +51,7 @@ public class RouteLineDrawInfo { this.centerX = existed.centerX; this.centerY = existed.centerY; this.screenHeight = existed.screenHeight; - } - - @Nullable - public Integer getColor() { - return color; - } - - @Nullable - public String getWidth() { - return width; + this.appModeKey = existed.appModeKey; } public void setColor(@Nullable Integer color) { @@ -89,6 +82,20 @@ public class RouteLineDrawInfo { this.screenHeight = screenHeight; } + public void setAppModeKey(@Nullable String appModeKey) { + this.appModeKey = appModeKey; + } + + @Nullable + public Integer getColor() { + return color; + } + + @Nullable + public String getWidth() { + return width; + } + public int getIconId() { return iconId; } @@ -110,6 +117,11 @@ public class RouteLineDrawInfo { return screenHeight; } + @Nullable + public String getAppModeKey() { + return appModeKey; + } + private void readBundle(@NonNull Bundle bundle) { color = bundle.getInt(LINE_COLOR); width = bundle.getString(LINE_WIDTH); @@ -118,6 +130,7 @@ public class RouteLineDrawInfo { centerX = bundle.getInt(CENTER_X); centerY = bundle.getInt(CENTER_Y); screenHeight = bundle.getInt(SCREEN_HEIGHT); + appModeKey = bundle.getString(APP_MODE_KEY); } public void saveToBundle(@NonNull Bundle bundle) { @@ -132,6 +145,7 @@ public class RouteLineDrawInfo { bundle.putInt(CENTER_X, (int) centerX); bundle.putInt(CENTER_Y, (int) centerY); bundle.putInt(SCREEN_HEIGHT, screenHeight); + bundle.putString(APP_MODE_KEY, appModeKey); } @Override diff --git a/OsmAnd/src/net/osmand/plus/routing/cards/RouteLineColorCard.java b/OsmAnd/src/net/osmand/plus/routing/cards/RouteLineColorCard.java index e94ca1d00a..dc33b3d113 100644 --- a/OsmAnd/src/net/osmand/plus/routing/cards/RouteLineColorCard.java +++ b/OsmAnd/src/net/osmand/plus/routing/cards/RouteLineColorCard.java @@ -47,7 +47,6 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP private static final int NIGHT_TITLE_ID = R.string.night; private final Fragment targetFragment; - private ApplicationMode appMode; private ColorsCard colorsCard; private ColorTypeAdapter colorAdapter; @@ -78,13 +77,11 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP public RouteLineColorCard(@NonNull MapActivity mapActivity, @NonNull Fragment targetFragment, @NonNull RouteLineDrawInfo routeLineDrawInfo, - @NonNull ApplicationMode appMode, @NonNull DayNightMode initMapTheme, @NonNull DayNightMode selectedMapTheme) { super(mapActivity); this.targetFragment = targetFragment; this.routeLineDrawInfo = routeLineDrawInfo; - this.appMode = appMode; this.initMapTheme = initMapTheme; this.selectedMapTheme = selectedMapTheme; } @@ -179,7 +176,7 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP selectedColor = colors.get(0); } ListStringPreference preference = app.getSettings().CUSTOM_ROUTE_LINE_COLORS; - colorsCard = new ColorsCard(mapActivity, selectedColor, targetFragment, colors, preference, appMode); + colorsCard = new ColorsCard(mapActivity, selectedColor, targetFragment, colors, preference, null); colorsCard.setListener(this); container.addView(colorsCard.build(mapActivity)); } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java index bcb0a120eb..7635a7f046 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java @@ -730,7 +730,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O private void updateRouteLinePreference() { Preference preference = findPreference(CUSTOMIZE_ROUTE_LINE); if (preference != null) { - boolean isDefaultProfile = getSelectedAppMode().equals(ApplicationMode.DEFAULT); + boolean isDefaultProfile = getSelectedAppMode().equals(ApplicationMode.DEFAULT) && !isNewProfile; boolean isPublicTransport = PUBLIC_TRANSPORT_KEY.equals(changedProfile.routingProfile); preference.setVisible(!isDefaultProfile && !isPublicTransport); preference.setIcon(getIcon(R.drawable.ic_action_route_distance, getActiveColorRes())); @@ -995,12 +995,12 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O String prefId = preference.getKey(); if (CUSTOMIZE_ROUTE_LINE.equals(prefId)) { MapActivity mapActivity = getMapActivity(); - ApplicationMode appMode = getSelectedAppMode(); - if (mapActivity != null && appMode != null) { + if (mapActivity != null) { RouteLineDrawInfo drawInfo = changedProfile.routeLineDrawInfo; drawInfo.setIconId(changedProfile.navigationIcon.getIconId()); drawInfo.setIconColor(changedProfile.getActualColor()); - RouteLineAppearanceFragment.showInstance(mapActivity, drawInfo, appMode, this); + drawInfo.setAppModeKey(profile.stringKey); + RouteLineAppearanceFragment.showInstance(mapActivity, drawInfo, this); } } return super.onPreferenceClick(preference); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/RouteLineAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/RouteLineAppearanceFragment.java index 0baf7bed3d..44765dfc05 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/RouteLineAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/RouteLineAppearanceFragment.java @@ -43,8 +43,6 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple private static final String INIT_MAP_THEME = "init_map_theme"; private static final String SELECTED_MAP_THEME = "selected_map_theme"; - private ApplicationMode appMode; - private RouteLineDrawInfo routeLineDrawInfo; private int toolbarHeightPx; @@ -164,7 +162,7 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple MapActivity mapActivity = requireMapActivity(); ViewGroup cardsContainer = getCardsContainer(); - colorCard = new RouteLineColorCard(mapActivity, this, routeLineDrawInfo, appMode, initMapTheme, selectedMapTheme); + colorCard = new RouteLineColorCard(mapActivity, this, routeLineDrawInfo, initMapTheme, selectedMapTheme); cardsContainer.addView(colorCard.build(mapActivity)); widthCard = new RouteLineWidthCard(mapActivity, routeLineDrawInfo, createScrollListener()); @@ -392,14 +390,12 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull RouteLineDrawInfo drawInfo, - @NonNull ApplicationMode appMode, @NonNull Fragment target) { try { RouteLineAppearanceFragment fragment = new RouteLineAppearanceFragment(); fragment.setRetainInstance(true); fragment.setTargetFragment(target, 0); fragment.routeLineDrawInfo = new RouteLineDrawInfo(drawInfo); - fragment.appMode = appMode; mapActivity.getSupportFragmentManager() .beginTransaction() diff --git a/OsmAnd/src/net/osmand/plus/views/layers/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/RouteLayer.java index 9fb0816b7c..2d38319c39 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/RouteLayer.java @@ -276,7 +276,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont private void updateRouteLineAppearance(RotatedTileBox tileBox, boolean defaultPaintUpdated, boolean night) { OsmandSettings settings = view.getApplication().getSettings(); - ApplicationMode appMode = settings.getApplicationMode(); + ApplicationMode appMode = getApplicationMode(); int color = getRouteLineColor(settings, appMode, defaultPaintUpdated); attrs.paint.setColor(color); @@ -293,15 +293,12 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont defaultRouteLineColor = attrs.paint.getColor(); } - int storedValue = settings.ROUTE_LINE_COLOR.getModeValue(appMode); - Integer fromSettings = storedValue != 0 ? storedValue : null; - - Integer color = null; + Integer color; if (routeLineDrawInfo != null) { color = routeLineDrawInfo.getColor(); - } - if (color == null) { - color = fromSettings; + } else { + int storedValue = settings.ROUTE_LINE_COLOR.getModeValue(appMode); + color = storedValue != 0 ? storedValue : null; } return color != null ? color : defaultRouteLineColor; } @@ -314,13 +311,11 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont defaultRouteLineWidth = attrs.paint.getStrokeWidth(); } - String fromSettings = settings.ROUTE_LINE_WIDTH.getModeValue(appMode); - String widthKey = null; + String widthKey; if (routeLineDrawInfo != null) { widthKey = routeLineDrawInfo.getWidth(); - } - if (widthKey == null) { - widthKey = fromSettings; + } else { + widthKey = settings.ROUTE_LINE_WIDTH.getModeValue(appMode); } return widthKey != null ? getWidthByKey(tileBox, widthKey) : defaultRouteLineWidth; } @@ -352,6 +347,18 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont return DEFAULT_WIDTH_MULTIPLIER * view.getDensity(); } + @NonNull + private ApplicationMode getApplicationMode() { + ApplicationMode appMode = null; + if (routeLineDrawInfo != null) { + String modeKey = routeLineDrawInfo.getAppModeKey(); + if (modeKey != null) { + appMode = ApplicationMode.valueOfStringKey(modeKey, null); + } + } + return appMode != null ? appMode : helper.getAppMode(); + } + private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) { QuadRect latLonBounds = tileBox.getLatLonBounds(); List xAxisPoints = trackChartPoints.getXAxisPoints();