From f3eb10ff8849003e33681ca4626581870428f806 Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Mon, 22 Mar 2021 17:39:21 +0200 Subject: [PATCH] remove temporally RouteLineHelper class --- .../osmand/plus/routing/RouteLineHelper.java | 59 ------------------- .../routing/cards/RouteLineWidthCard.java | 10 +++- .../plus/settings/backend/OsmandSettings.java | 2 + .../fragments/ProfileAppearanceFragment.java | 33 +++++++++-- 4 files changed, 38 insertions(+), 66 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/routing/RouteLineHelper.java diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteLineHelper.java b/OsmAnd/src/net/osmand/plus/routing/RouteLineHelper.java deleted file mode 100644 index f9091621d3..0000000000 --- a/OsmAnd/src/net/osmand/plus/routing/RouteLineHelper.java +++ /dev/null @@ -1,59 +0,0 @@ -package net.osmand.plus.routing; - -import android.graphics.Color; - -import androidx.annotation.NonNull; - -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.ApplicationMode; - -// it's just a test class, maybe it's better to move methods to other places or change the architecture -public class RouteLineHelper { - - public static void saveRouteLineAppearance(@NonNull OsmandApplication app, - @NonNull ApplicationMode appMode, - @NonNull RouteLineDrawInfo drawInfo) { - // save to settings - } - - public static RouteLineDrawInfo createDrawInfoForAppMode(@NonNull OsmandApplication app, - @NonNull ApplicationMode appMode) { - Integer color = getColorFromSettings(app, appMode); - Integer width = getWidthFromSettings(app, appMode); - return new RouteLineDrawInfo(color, width); - } - - public static Integer getColorFromSettings(@NonNull OsmandApplication app, - @NonNull ApplicationMode appMode) { - return null; - } - - public static Integer getWidthFromSettings(@NonNull OsmandApplication app, - @NonNull ApplicationMode appMode) { - return null; - } - - public static int getColor(@NonNull RouteLineDrawInfo drawInfo) { - if (drawInfo.getColor() != null) { - return drawInfo.getColor(); - } - return getMapStyleColor(); - } - - public static int getWidth(@NonNull RouteLineDrawInfo drawInfo) { - if (drawInfo.getWidth() != null) { - return drawInfo.getWidth(); - } - return getMapStyleWidth(); - } - - public static int getMapStyleColor() { - // get color from selected map style - return Color.BLUE; - } - - public static int getMapStyleWidth() { - // get width from selected map style - return 10; - } -} diff --git a/OsmAnd/src/net/osmand/plus/routing/cards/RouteLineWidthCard.java b/OsmAnd/src/net/osmand/plus/routing/cards/RouteLineWidthCard.java index 6088cae2de..d8bac7f25c 100644 --- a/OsmAnd/src/net/osmand/plus/routing/cards/RouteLineWidthCard.java +++ b/OsmAnd/src/net/osmand/plus/routing/cards/RouteLineWidthCard.java @@ -26,10 +26,8 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routing.RouteLineDrawInfo; -import net.osmand.plus.routing.RouteLineHelper; import net.osmand.plus.track.AppearanceViewHolder; import net.osmand.plus.track.TrackAppearanceFragment.OnNeedScrollListener; -import net.osmand.render.RenderingRulesStorage; import java.util.Arrays; import java.util.List; @@ -275,7 +273,13 @@ public class RouteLineWidthCard extends BaseCard { } private int getIconColor(@NonNull WidthMode mode, @ColorInt int defaultColor) { - return mode.width != null ? RouteLineHelper.getColor(routeLineDrawInfo) : defaultColor; + return mode.width != null ? getRouteLineColor() : defaultColor; + } + + private int getRouteLineColor() { + Integer color = routeLineDrawInfo.getColor(); + return color != null ? color : + mapActivity.getMapLayers().getRouteLayer().getRouteLineColor(nightMode); } private void updateButtonBg(AppearanceViewHolder holder, WidthMode item) { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index dac320c5db..797cdb05c3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -2691,6 +2691,8 @@ public class OsmandSettings { public final CommonPreference ROUTE_RECALCULATION_DISTANCE = new FloatPreference(this, "routing_recalc_distance", 0.f).makeProfile(); public final CommonPreference ROUTE_STRAIGHT_ANGLE = new FloatPreference(this, "routing_straight_angle", 30.f).makeProfile(); public final ListStringPreference CUSTOM_ROUTE_LINE_COLORS = (ListStringPreference) new ListStringPreference(this, "custom_route_line_colors", null, ",").makeShared().makeGlobal(); + public final CommonPreference ROUTE_LINE_COLOR = new IntPreference(this, "route_line_color", 0).makeProfile(); + public final CommonPreference ROUTE_LINE_WIDTH = new IntPreference(this, "route_line_width", 0).makeProfile(); public final OsmandPreference USE_OSM_LIVE_FOR_ROUTING = new BooleanPreference(this, "enable_osmc_routing", true).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java index 690953d445..5c9c787100 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java @@ -55,7 +55,6 @@ import net.osmand.plus.profiles.SelectProfileBottomSheet.OnSelectProfileCallback import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.routing.RouteLineDrawInfo; -import net.osmand.plus.routing.RouteLineHelper; import net.osmand.plus.routing.RouteService; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.backup.ProfileSettingsItem; @@ -185,7 +184,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O profile.routeService = baseModeForNewProfile.getRouteService(); profile.locationIcon = baseModeForNewProfile.getLocationIcon(); profile.navigationIcon = baseModeForNewProfile.getNavigationIcon(); - profile.routeLineDrawInfo = RouteLineHelper.createDrawInfoForAppMode(app, profile.parent); + profile.routeLineDrawInfo = createRouteLineDrawInfo(baseModeForNewProfile); } @Override @@ -777,7 +776,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O mode.setCustomIconColor(changedProfile.customColor); mode.setLocationIcon(changedProfile.locationIcon); mode.setNavigationIcon(changedProfile.navigationIcon); - RouteLineHelper.saveRouteLineAppearance(app, mode, changedProfile.routeLineDrawInfo); + saveRouteLineAppearance(mode, changedProfile.routeLineDrawInfo); FragmentActivity activity = getActivity(); if (activity != null) { @@ -805,7 +804,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O if (!ApplicationMode.values(app).contains(mode)) { ApplicationMode.changeProfileAvailability(mode, true, app); } - RouteLineHelper.saveRouteLineAppearance(app, mode, changedProfile.routeLineDrawInfo); + saveRouteLineAppearance(mode, changedProfile.routeLineDrawInfo); return mode; } @@ -1018,6 +1017,32 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O changedProfile.routeLineDrawInfo = routeLineDrawInfo; } + private RouteLineDrawInfo createRouteLineDrawInfo(@NonNull ApplicationMode appMode) { + Integer color = null; + Integer width = null; + if (settings.ROUTE_LINE_COLOR.isSetForMode(appMode)) { + color = settings.ROUTE_LINE_COLOR.getModeValue(appMode); + } + if (settings.ROUTE_LINE_WIDTH.isSetForMode(appMode)) { + width = settings.ROUTE_LINE_WIDTH.getModeValue(appMode); + } + return new RouteLineDrawInfo(color, width); + } + + private void saveRouteLineAppearance(@NonNull ApplicationMode appMode, + @NonNull RouteLineDrawInfo routeLineDrawInfo) { + if (routeLineDrawInfo.getColor() != null) { + settings.ROUTE_LINE_COLOR.setModeValue(appMode, routeLineDrawInfo.getColor()); + } else { + settings.ROUTE_LINE_COLOR.resetToDefault(); + } + if (routeLineDrawInfo.getWidth() != null) { + settings.ROUTE_LINE_WIDTH.setModeValue(appMode, routeLineDrawInfo.getWidth()); + } else { + settings.ROUTE_LINE_WIDTH.resetToDefault(); + } + } + public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable String appMode, boolean imported) { try { Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName);