Finish refactoring

This commit is contained in:
Victor Shcherb 2019-06-25 11:54:49 +02:00
parent 99c7c6e35d
commit 8d7b122e8d
3 changed files with 40 additions and 27 deletions

View file

@ -192,7 +192,7 @@ public class AppInitializer implements IProgress {
} }
app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(true); app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(true);
app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(true); app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(true);
ApplicationMode.onApplicationStart(app.getSettings()); ApplicationMode.onApplicationStart(app);
initSettings = true; initSettings = true;
} }

View file

@ -90,7 +90,7 @@ public class ApplicationMode {
icon(R.drawable.ic_action_pedestrian_dark, "ic_action_pedestrian_dark").setRoutingProfile("pedestrian").reg(); icon(R.drawable.ic_action_pedestrian_dark, "ic_action_pedestrian_dark").setRoutingProfile("pedestrian").reg();
public static final ApplicationMode PUBLIC_TRANSPORT = createBase( R.string.app_mode_public_transport, "public_transport"). public static final ApplicationMode PUBLIC_TRANSPORT = createBase( R.string.app_mode_public_transport, "public_transport").
icon(R.drawable.ic_action_bus_dark).setRoutingProfile("public_transport").reg(); icon(R.drawable.ic_action_bus_dark, "ic_action_bus_dark").setRoutingProfile("public_transport").reg();
public static final ApplicationMode BOAT = createBase( R.string.app_mode_boat, "boat").speed(5.5f, 20).nauticalLocation(). public static final ApplicationMode BOAT = createBase( R.string.app_mode_boat, "boat").speed(5.5f, 20).nauticalLocation().
icon(R.drawable.ic_action_sail_boat_dark, "ic_action_sail_boat_dark").setRoutingProfile("boat").reg(); icon(R.drawable.ic_action_sail_boat_dark, "ic_action_sail_boat_dark").setRoutingProfile("boat").reg();
@ -110,6 +110,7 @@ public class ApplicationMode {
@Expose ProfileIconColors iconColor = ProfileIconColors.DEFAULT; @Expose ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
@Expose String routingProfile = null; @Expose String routingProfile = null;
@Expose RouteService routeService = RouteService.OSMAND; @Expose RouteService routeService = RouteService.OSMAND;
} }
private static void initRegVisibility() { private static void initRegVisibility() {
@ -173,6 +174,19 @@ public class ApplicationMode {
} }
private ApplicationMode customReg() { private ApplicationMode customReg() {
ApplicationMode m = applicationMode;
m.defaultSpeed = m.parentAppMode.defaultSpeed;
m.minDistanceForTurn = m.parentAppMode.minDistanceForTurn;
m.arrivalDistance = m.parentAppMode.arrivalDistance;
m.offRouteDistance = m.parentAppMode.offRouteDistance;
m.bearingIconDay = m.parentAppMode.bearingIconDay;
m.bearingIconNight = m.parentAppMode.bearingIconNight;
m.headingIconDay = m.parentAppMode.headingIconDay;
m.headingIconNight = m.parentAppMode.headingIconNight;
m.locationIconDay = m.parentAppMode.locationIconDay;
m.locationIconNight = m.parentAppMode.locationIconNight;
m.locationIconDayLost = m.parentAppMode.locationIconDayLost;
m.locationIconNightLost = m.parentAppMode.locationIconNightLost;
values.add(applicationMode); values.add(applicationMode);
return applicationMode; return applicationMode;
} }
@ -541,32 +555,24 @@ public class ApplicationMode {
} }
public static void onApplicationStart(OsmandSettings settings) { public static void onApplicationStart(OsmandApplication app) {
initCustomModes(settings); initCustomModes(app);
initRegVisibility(); initRegVisibility();
} }
private static void initCustomModes(OsmandSettings settings){ private static void initCustomModes(OsmandApplication app){
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
Type t = new TypeToken<ArrayList<ApplicationMode>>() {}.getType(); Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {}.getType();
// TODO ?? clear settings List<ApplicationModeBean> customProfiles = gson.fromJson(app.getSettings().CUSTOM_APP_PROFILES.get(), t);
List<ApplicationMode> customProfiles = gson.fromJson(settings.CUSTOM_APP_PROFILES.get(), t);
if (!Algorithms.isEmpty(customProfiles)) { if (!Algorithms.isEmpty(customProfiles)) {
for (ApplicationMode m : customProfiles) { for (ApplicationModeBean m : customProfiles) {
m.parentAppMode = valueOfStringKey(m.parent, ApplicationMode.PEDESTRIAN); ApplicationModeBuilder b = createCustomMode(valueOfStringKey(m.parent, CAR),
m.defaultSpeed = m.parentAppMode.defaultSpeed; m.userProfileName, m.stringKey);
m.minDistanceForTurn = m.parentAppMode.minDistanceForTurn; b.setRouteService(m.routeService).setRoutingProfile(m.routingProfile);
m.arrivalDistance = m.parentAppMode.arrivalDistance; b.icon(app, m.iconName);
m.offRouteDistance = m.parentAppMode.offRouteDistance; b.setColor(m.iconColor);
m.bearingIconDay = m.parentAppMode.bearingIconDay; b.customReg();
m.bearingIconNight = m.parentAppMode.bearingIconNight;
m.headingIconDay = m.parentAppMode.headingIconDay;
m.headingIconNight = m.parentAppMode.headingIconNight;
m.locationIconDay = m.parentAppMode.locationIconDay;
m.locationIconNight = m.parentAppMode.locationIconNight;
m.locationIconDayLost = m.parentAppMode.locationIconDayLost;
m.locationIconNightLost = m.parentAppMode.locationIconNightLost;
} }
} }
@ -574,11 +580,18 @@ public class ApplicationMode {
private static void saveCustomModeToSettings(OsmandSettings settings){ private static void saveCustomModeToSettings(OsmandSettings settings){
// TODO save ! List<ApplicationModeBean> customModes = new ArrayList<>();
List<ApplicationMode> customModes = new ArrayList<>();
for (ApplicationMode mode : values) { for (ApplicationMode mode : values) {
if (mode.parent != null) { if (mode.parentAppMode != null) {
customModes.add(mode); ApplicationModeBean mb = new ApplicationModeBean();
mb.userProfileName = mode.userProfileName;
mb.iconColor = mode.iconColor;
mb.iconName = mode.iconResName;
mb.parent = mode.parentAppMode.getStringKey();
mb.stringKey = mode.stringKey;
mb.routeService = mode.routeService;
mb.routingProfile = mode.routingProfile;
customModes.add(mb);
} }
} }
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

View file

@ -2768,7 +2768,7 @@ public class OsmandSettings {
.makeGlobal(); .makeGlobal();
public final CommonPreference<String> CUSTOM_APP_PROFILES = public final CommonPreference<String> CUSTOM_APP_PROFILES =
new StringPreference("custom_profiles", "").makeGlobal().cache(); new StringPreference("custom_app_profiles", "").makeGlobal().cache();
public enum DayNightMode { public enum DayNightMode {