Merge pull request #7856 from osmandapp/fix_7822

Fix #7822
This commit is contained in:
max-klaus 2019-11-05 15:48:37 +03:00 committed by GitHub
commit b03d74854f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 11 deletions

View file

@ -576,7 +576,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
}
bottomShadowVisible = routes.size() == 0;
} else {
RouteMenuAppModes mode = app.getRoutingOptionsHelper().modes.get(routingHelper.getAppMode());
RouteMenuAppModes mode = app.getRoutingOptionsHelper().getRouteMenuAppMode(routingHelper.getAppMode());
boolean avoidPTTypesCustomized = false;
for (LocalRoutingParameter parameter : mode.parameters) {
if (parameter instanceof AvoidPTTypesRoutingParameter) {
@ -916,7 +916,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
final OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
final ApplicationMode applicationMode = routingHelper.getAppMode();
final RouteMenuAppModes mode = app.getRoutingOptionsHelper().modes.get(applicationMode);
final RouteMenuAppModes mode = app.getRoutingOptionsHelper().getRouteMenuAppMode(applicationMode);
updateControlButtons(mapActivity, mainView);
LinearLayout optionsButton = (LinearLayout) mainView.findViewById(R.id.map_options_route_button);

View file

@ -62,19 +62,11 @@ public class RoutingOptionsHelper {
private OsmandApplication app;
private OsmandSettings settings;
Map<ApplicationMode, RouteMenuAppModes> modes = new HashMap<>();
private Map<ApplicationMode, RouteMenuAppModes> modes = new HashMap<>();
public RoutingOptionsHelper(OsmandApplication application) {
app = application;
settings = app.getSettings();
addRouteMenuAppModes(ApplicationMode.CAR, PermanentAppModeOptions.CAR.routingParameters);
addRouteMenuAppModes(ApplicationMode.BICYCLE, PermanentAppModeOptions.BICYCLE.routingParameters);
addRouteMenuAppModes(ApplicationMode.PEDESTRIAN, PermanentAppModeOptions.PEDESTRIAN.routingParameters);
addRouteMenuAppModes(ApplicationMode.PUBLIC_TRANSPORT, PermanentAppModeOptions.PUBLIC_TRANSPORT.routingParameters);
addRouteMenuAppModes(ApplicationMode.BOAT, PermanentAppModeOptions.BOAT.routingParameters);
addRouteMenuAppModes(ApplicationMode.AIRCRAFT, PermanentAppModeOptions.AIRCRAFT.routingParameters);
addRouteMenuAppModes(ApplicationMode.SKI, PermanentAppModeOptions.SKI.routingParameters);
}
private void addRouteMenuAppModes(ApplicationMode am, List<String> routingParameters) {
@ -94,6 +86,13 @@ public class RoutingOptionsHelper {
}
}
public RouteMenuAppModes getRouteMenuAppMode(ApplicationMode appMode) {
if (!modes.containsKey(appMode)) {
addRouteMenuAppModes(appMode, getRoutingParametersForProfileType(appMode));
}
return modes.get(appMode);
}
public void switchSound() {
RoutingHelper routingHelper = app.getRoutingHelper();
boolean mt = !routingHelper.getVoiceRouter().isMute();
@ -1011,4 +1010,27 @@ public class RoutingOptionsHelper {
this.routingParameters = Arrays.asList(routingParameters);
}
}
private List<String> getRoutingParametersForProfileType(ApplicationMode appMode) {
if (appMode != null) {
if (appMode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
return PermanentAppModeOptions.CAR.routingParameters;
} else if (appMode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
return PermanentAppModeOptions.BICYCLE.routingParameters;
} else if (appMode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
return PermanentAppModeOptions.PEDESTRIAN.routingParameters;
} else if (appMode.isDerivedRoutingFrom(ApplicationMode.PUBLIC_TRANSPORT)) {
return PermanentAppModeOptions.PUBLIC_TRANSPORT.routingParameters;
} else if (appMode.isDerivedRoutingFrom(ApplicationMode.BOAT)) {
return PermanentAppModeOptions.BOAT.routingParameters;
} else if (appMode.isDerivedRoutingFrom(ApplicationMode.AIRCRAFT)) {
return PermanentAppModeOptions.AIRCRAFT.routingParameters;
} else if (appMode.isDerivedRoutingFrom(ApplicationMode.SKI)) {
return PermanentAppModeOptions.SKI.routingParameters;
} else {
return new ArrayList<>();
}
}
return null;
}
}