remove temporally RouteLineHelper class

This commit is contained in:
nazar-kutz 2021-03-22 17:39:21 +02:00
parent 9fda0edc37
commit f3eb10ff88
4 changed files with 38 additions and 66 deletions

View file

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

View file

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

View file

@ -2691,6 +2691,8 @@ public class OsmandSettings {
public final CommonPreference<Float> ROUTE_RECALCULATION_DISTANCE = new FloatPreference(this, "routing_recalc_distance", 0.f).makeProfile();
public final CommonPreference<Float> 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<Integer> ROUTE_LINE_COLOR = new IntPreference(this, "route_line_color", 0).makeProfile();
public final CommonPreference<Integer> ROUTE_LINE_WIDTH = new IntPreference(this, "route_line_width", 0).makeProfile();
public final OsmandPreference<Boolean> USE_OSM_LIVE_FOR_ROUTING = new BooleanPreference(this, "enable_osmc_routing", true).makeProfile();

View file

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