Directions > Options: Description elevation add

This commit is contained in:
androiddevkkotlin 2020-12-06 00:43:51 +02:00
parent d405a20c3e
commit 13795524f8
2 changed files with 38 additions and 11 deletions

View file

@ -55,12 +55,15 @@ import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.util.Algorithms;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE;
import static net.osmand.plus.settings.fragments.RouteParametersFragment.RELIEF_SMOOTHNESS_FACTOR;
import static net.osmand.plus.settings.fragments.RouteParametersFragment.getRoutingParameterTitle;
import static net.osmand.plus.settings.fragments.RouteParametersFragment.isRoutingParameterSelected;
import static net.osmand.router.GeneralRouter.USE_HEIGHT_OBSTACLES;
public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
@ -80,6 +83,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
private CommonPreference<Boolean> useHeightPref;
private StateChangedListener<Boolean> voiceMuteChangeListener;
private StateChangedListener<Boolean> useHeightChangeListener;
private List<RoutingParameter> reliefParameters = new ArrayList<>();
@Override
public void onCreate(Bundle savedInstanceState) {
@ -104,6 +108,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
}
};
useHeightPref = settings.getCustomRoutingBooleanProperty(USE_HEIGHT_OBSTACLES, false);
reliefParameters = getReliefParameters();
}
@Override
@ -259,7 +264,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
.create();
}
private BaseBottomSheetItem inflateElevationParameter(final LocalRoutingParameter optionsItem) {
private BaseBottomSheetItem inflateElevationParameter(final LocalRoutingParameter parameter) {
final BottomSheetItemWithCompoundButton[] item = new BottomSheetItemWithCompoundButton[1];
final boolean active = !useHeightPref.getModeValue(applicationMode);
final View itemView = UiUtilities.getInflater(app, nightMode).inflate(
@ -273,7 +278,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
itemsContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (USE_HEIGHT_OBSTACLES.equals(optionsItem.getKey()) && hasReliefParameters()) {
if (USE_HEIGHT_OBSTACLES.equals(parameter.getKey()) && hasReliefParameters()) {
FragmentManager fm = getFragmentManager();
if (fm != null) {
ElevationDateBottomSheet.showInstance(fm, applicationMode, RouteOptionsBottomSheet.this, false);
@ -284,14 +289,15 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
applyParameter(item[0], optionsItem);
applyParameter(item[0], parameter);
item[0].setDescription(getElevationDescription(parameter));
}
});
item[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setCompoundButtonColorId(selectedModeColorId)
.setDescription(getString(R.string.routing_attr_height_obstacles_name))
.setIcon(getContentIcon(active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId()))
.setDescription(getElevationDescription(parameter))
.setIcon(getContentIcon(active ? parameter.getActiveIconId() : parameter.getDisabledIconId()))
.setTitle(getString(R.string.routing_attr_height_obstacles_name))
.setCustomView(itemView)
.create();
@ -299,6 +305,22 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
return item[0];
}
private String getElevationDescription(LocalRoutingParameter parameter) {
String description;
if (parameter.isSelected(settings)) {
description = getString(R.string.shared_string_enabled);
for (RoutingParameter routingParameter : reliefParameters) {
if (isRoutingParameterSelected(settings, applicationMode, routingParameter)) {
description = getString(R.string.ltr_or_rtl_combine_via_comma, description,
getRoutingParameterTitle(app, routingParameter));
}
}
} else {
description = getString(R.string.shared_string_disabled);
}
return description;
}
private BaseBottomSheetItem createTimeConditionalRoutingItem(final LocalRoutingParameter optionsItem) {
final BottomSheetItemWithCompoundButton[] timeConditionalRoutingItem = new BottomSheetItemWithCompoundButton[1];
timeConditionalRoutingItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
@ -531,14 +553,19 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
}
private boolean hasReliefParameters() {
return !Algorithms.isEmpty(reliefParameters);
}
private List<RoutingParameter> getReliefParameters() {
List<RoutingParameter> reliefFactorParameters = new ArrayList<>();
Map<String, RoutingParameter> parameters = app.getRouter(applicationMode).getParameters();
for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
RoutingParameter routingParameter = e.getValue();
for (Map.Entry<String, RoutingParameter> entry : parameters.entrySet()) {
RoutingParameter routingParameter = entry.getValue();
if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) {
return true;
reliefFactorParameters.add(routingParameter);
}
}
return false;
return reliefFactorParameters;
}
private void applyParameter(BottomSheetItemWithCompoundButton bottomSheetItem, LocalRoutingParameter parameter) {

View file

@ -290,7 +290,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
switchPreferenceEx.setIcon(getRoutingPrefIcon(p.getId()));
screen.addPreference(switchPreferenceEx);
setupOtherBooleanParameterSummary(app, am, p, switchPreferenceEx);
setupOtherBooleanParameterSummary(am, p, switchPreferenceEx);
} else {
Object[] vls = p.getPossibleValues();
String[] svlss = new String[vls.length];
@ -340,7 +340,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
setupFastRecalculationPref();
}
private void setupOtherBooleanParameterSummary(OsmandApplication app, ApplicationMode am, RoutingParameter p, SwitchPreferenceEx switchPreferenceEx) {
private void setupOtherBooleanParameterSummary(ApplicationMode am, RoutingParameter p, SwitchPreferenceEx switchPreferenceEx) {
if (USE_HEIGHT_OBSTACLES.equals(p.getId()) && !Algorithms.isEmpty(reliefFactorParameters)) {
String summaryOn = getString(R.string.shared_string_enabled);
for (RoutingParameter parameter : reliefFactorParameters) {