Second dialog

This commit is contained in:
androiddevkkotlin 2020-11-29 21:43:48 +02:00
parent 85c75ca283
commit afb6639d76
4 changed files with 209 additions and 143 deletions

View file

@ -45,14 +45,15 @@ import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.TimeConditional
import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.bottomsheets.ElevationDateBottomSheet; import net.osmand.plus.settings.bottomsheets.ElevationDateBottomSheet;
import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -73,13 +74,16 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
@ColorRes @ColorRes
private int selectedModeColorId; private int selectedModeColorId;
private boolean currentMuteState; private boolean currentMuteState;
private boolean currentUseHeightState;
private MapActivity mapActivity; private MapActivity mapActivity;
StateChangedListener<Boolean> voiceMuteChangeListener; private CommonPreference<Boolean> useHeightPref;
private StateChangedListener<Boolean> voiceMuteChangeListener;
private StateChangedListener<Boolean> useHeightChangeListener;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
app = getMyApplication(); app = requiredMyApplication();
settings = app.getSettings(); settings = app.getSettings();
routingHelper = app.getRoutingHelper(); routingHelper = app.getRoutingHelper();
routingOptionsHelper = app.getRoutingOptionsHelper(); routingOptionsHelper = app.getRoutingOptionsHelper();
@ -92,16 +96,13 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
updateWhenMuteChanged(); updateWhenMuteChanged();
} }
}; };
} useHeightChangeListener = new StateChangedListener<Boolean>() {
@Override
public void updateWhenMuteChanged() { public void stateChanged(Boolean change) {
if (app != null) { updateWhenUseHeightChanged();
boolean changedState = app.getSettings().VOICE_MUTE.getModeValue(applicationMode);
if (changedState != currentMuteState) {
currentMuteState = changedState;
updateParameters();
} }
} };
useHeightPref = settings.getCustomRoutingBooleanProperty(USE_HEIGHT_OBSTACLES, false);
} }
@Override @Override
@ -144,12 +145,17 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
itemWithCompoundButton.setChecked(itemWithCompoundButton.isChecked()); itemWithCompoundButton.setChecked(itemWithCompoundButton.isChecked());
} }
} }
currentUseHeightState = useHeightPref.getModeValue(applicationMode);
currentMuteState = app.getSettings().VOICE_MUTE.getModeValue(applicationMode);
useHeightPref.addListener(useHeightChangeListener);
app.getSettings().VOICE_MUTE.addListener(voiceMuteChangeListener); app.getSettings().VOICE_MUTE.addListener(voiceMuteChangeListener);
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
useHeightPref.removeListener(useHeightChangeListener);
app.getSettings().VOICE_MUTE.removeListener(voiceMuteChangeListener); app.getSettings().VOICE_MUTE.removeListener(voiceMuteChangeListener);
} }
@ -172,6 +178,24 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
} }
} }
public void updateWhenMuteChanged() {
boolean changedState = app.getSettings().VOICE_MUTE.getModeValue(applicationMode);
if (changedState != currentMuteState) {
currentMuteState = changedState;
updateParameters();
updateMenu();
}
}
public void updateWhenUseHeightChanged() {
boolean changedState = useHeightPref.getModeValue(applicationMode);
if (changedState != currentUseHeightState) {
currentUseHeightState = changedState;
updateParameters();
updateMenu();
}
}
private BaseBottomSheetItem createMuteSoundItem(final LocalRoutingParameter optionsItem) { private BaseBottomSheetItem createMuteSoundItem(final LocalRoutingParameter optionsItem) {
boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode); boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode);
int selectedModeColor = ContextCompat.getColor(app, selectedModeColorId); int selectedModeColor = ContextCompat.getColor(app, selectedModeColorId);
@ -437,27 +461,17 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
builder.setLayoutId(R.layout.bottom_sheet_item_with_switch_56dp); builder.setLayoutId(R.layout.bottom_sheet_item_with_switch_56dp);
if (parameter.routingParameter != null && parameter.routingParameter.getId().equals(GeneralRouter.USE_SHORTEST_WAY)) { if (parameter.routingParameter != null && parameter.routingParameter.getId().equals(GeneralRouter.USE_SHORTEST_WAY)) {
// if short route settings - it should be inverse of fast_route_mode // if short route settings - it should be inverse of fast_route_mode
builder.setChecked(!settings.FAST_ROUTE_MODE.getModeValue(routingHelper.getAppMode())); builder.setChecked(!settings.FAST_ROUTE_MODE.getModeValue(applicationMode));
} else { } else {
builder.setChecked(parameter.isSelected(settings)); builder.setChecked(parameter.isSelected(settings));
} }
builder.setOnClickListener(new View.OnClickListener() { builder.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
GeneralRouter router = app.getRouter(applicationMode); if (USE_HEIGHT_OBSTACLES.equals(parameter.getKey()) && hasReliefParameters()) {
List<GeneralRouter.RoutingParameter> reliefFactorParameters = new ArrayList<GeneralRouter.RoutingParameter>(); FragmentManager fm = getFragmentManager();
Map<String, GeneralRouter.RoutingParameter> parameters = router.getParameters(); if (fm != null) {
for (Map.Entry<String, GeneralRouter.RoutingParameter> e : parameters.entrySet()) { ElevationDateBottomSheet.showInstance(fm, applicationMode, RouteOptionsBottomSheet.this, false);
GeneralRouter.RoutingParameter routingParameter = e.getValue();
if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) {
reliefFactorParameters.add(routingParameter);
}
}
if (!reliefFactorParameters.isEmpty() && parameter.getKey().equals(USE_HEIGHT_OBSTACLES)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
ElevationDateBottomSheet.showInstance(fragmentManager, reliefFactorParameters, applicationMode, RouteOptionsBottomSheet.this, false);
} }
} else { } else {
applyParameter(item[0], parameter); applyParameter(item[0], parameter);
@ -473,6 +487,17 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
} }
} }
private boolean hasReliefParameters() {
Map<String, RoutingParameter> parameters = app.getRouter(applicationMode).getParameters();
for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
RoutingParameter routingParameter = e.getValue();
if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) {
return true;
}
}
return false;
}
private void applyParameter(BottomSheetItemWithCompoundButton bottomSheetItem, LocalRoutingParameter parameter) { private void applyParameter(BottomSheetItemWithCompoundButton bottomSheetItem, LocalRoutingParameter parameter) {
routingOptionsHelper.addNewRouteMenuParameter(applicationMode, parameter); routingOptionsHelper.addNewRouteMenuParameter(applicationMode, parameter);
boolean selected = !parameter.isSelected(settings); boolean selected = !parameter.isSelected(settings);

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@ -18,172 +19,210 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.BooleanPreference; import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.fragments.ApplyQueryType;
import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.settings.fragments.OnPreferenceChanged; import net.osmand.plus.settings.fragments.OnConfirmPreferenceChange;
import net.osmand.router.GeneralRouter.RoutingParameter; import net.osmand.router.GeneralRouter.RoutingParameter;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import static net.osmand.AndroidUtils.createCheckedColorStateList;
import static net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.getCustomButtonView; import static net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.getCustomButtonView;
import static net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.updateCustomButtonView; import static net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.updateCustomButtonView;
import static net.osmand.plus.settings.fragments.RouteParametersFragment.setRoutingParameterSelected; import static net.osmand.plus.settings.fragments.BaseSettingsFragment.APP_MODE_KEY;
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.plus.settings.fragments.RouteParametersFragment.updateSelectedParameters;
import static net.osmand.router.GeneralRouter.USE_HEIGHT_OBSTACLES; import static net.osmand.router.GeneralRouter.USE_HEIGHT_OBSTACLES;
public class ElevationDateBottomSheet extends MenuBottomSheetDialogFragment { public class ElevationDateBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = ElevationDateBottomSheet.class.getSimpleName(); public static final String TAG = ElevationDateBottomSheet.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(ElevationDateBottomSheet.class); private static final Log LOG = PlatformUtil.getLog(ElevationDateBottomSheet.class);
private OsmandApplication app; private OsmandApplication app;
private ApplicationMode appMode; private ApplicationMode appMode;
private List<RoutingParameter> reliefFactorParameters = new ArrayList<RoutingParameter>(); private List<RoutingParameter> parameters;
private static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key"; private CommonPreference<Boolean> useHeightPref;
private BottomSheetItemWithCompoundButton useHeightButton;
private List<BottomSheetItemWithCompoundButton> reliefFactorButtons = new ArrayList<>();
private final List<BottomSheetItemWithCompoundButton> reliefFactorButtons = new ArrayList<>();
private int selectedEntryIndex = -1; private int selectedEntryIndex = -1;
public void setAppMode(ApplicationMode appMode) { private String on;
this.appMode = appMode; private String off;
} private int activeColor;
private int disabledColor;
private int appModeColor;
public ApplicationMode getAppMode() { @Override
return appMode != null ? appMode : app.getSettings().getApplicationMode(); public void onCreate(Bundle savedInstanceState) {
app = requiredMyApplication();
if (savedInstanceState != null) {
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
}
super.onCreate(savedInstanceState);
Map<String, RoutingParameter> routingParameterMap = app.getRouter(appMode).getParameters();
RoutingParameter parameter = routingParameterMap.get(USE_HEIGHT_OBSTACLES);
if (parameter != null) {
useHeightPref = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
} else {
useHeightPref = app.getSettings().getCustomRoutingBooleanProperty(USE_HEIGHT_OBSTACLES, false);
}
parameters = getReliefParametersForMode(routingParameterMap);
for (int i = 0; i < parameters.size(); i++) {
if (isRoutingParameterSelected(app.getSettings(), appMode, parameters.get(i))) {
selectedEntryIndex = i;
}
}
} }
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication(); Context themedCtx = UiUtilities.getThemedContext(requireContext(), nightMode);
Context ctx = requireContext();
on = getString(R.string.shared_string_enable);
off = getString(R.string.shared_string_disable);
appModeColor = appMode.getIconColorInfo().getColor(nightMode);
activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary);
items.add(new TitleItem(getString(R.string.routing_attr_height_obstacles_name)));
createUseHeightButton(themedCtx);
int contentPaddingSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small); int contentPaddingSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
items.add(new DividerSpaceItem(app, contentPaddingSmall));
items.add(new LongDescriptionItem(getString(R.string.elevation_data)));
items.add(new DividerSpaceItem(app, contentPaddingSmall));
final BooleanPreference pref = (BooleanPreference) app.getSettings().getCustomRoutingBooleanProperty(USE_HEIGHT_OBSTACLES, false); createReliefFactorButtons(themedCtx);
}
Context themedCtx = UiUtilities.getThemedContext(ctx, nightMode); private void createUseHeightButton(Context context) {
boolean checked = useHeightPref.getModeValue(appMode);
final String on = getString(R.string.shared_string_enable); useHeightButton = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
final String off = getString(R.string.shared_string_disable); .setCompoundButtonColorId(appModeColor)
final int activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
final int disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary);
if (savedInstanceState != null) {
selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY);
}
boolean checked = pref.getModeValue(getAppMode());
final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1];
preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setChecked(checked) .setChecked(checked)
.setTitle(checked ? on : off) .setTitle(checked ? on : off)
.setTitleColorId(checked ? activeColor : disabledColor) .setTitleColorId(checked ? activeColor : disabledColor)
.setCustomView(getCustomButtonView(app, getAppMode(), checked, nightMode)) .setCustomView(getCustomButtonView(app, appMode, checked, nightMode))
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
boolean newValue = !pref.getModeValue(getAppMode()); boolean newValue = !useHeightPref.getModeValue(appMode);
enableItems(newValue); Fragment target = getTargetFragment();
Fragment targetFragment = getTargetFragment(); if (target instanceof OnConfirmPreferenceChange) {
pref.setModeValue(getAppMode(), newValue); OnConfirmPreferenceChange confirmInterface = (OnConfirmPreferenceChange) target;
if (confirmInterface.onConfirmPreferenceChange(useHeightPref.getId(), newValue, ApplyQueryType.NONE)) {
updateUseHeightButton(useHeightButton, newValue);
preferenceBtn[0].setTitle(newValue ? on : off); if (target instanceof BaseSettingsFragment) {
preferenceBtn[0].setChecked(newValue); ((BaseSettingsFragment) target).updateSetting(useHeightPref.getId());
preferenceBtn[0].setTitleColorId(newValue ? activeColor : disabledColor); }
updateCustomButtonView(app, getAppMode(), v, newValue, nightMode); }
} else {
if (targetFragment instanceof OnPreferenceChanged) { useHeightPref.setModeValue(appMode, newValue);
((OnPreferenceChanged) targetFragment).onPreferenceChanged(pref.getId()); updateUseHeightButton(useHeightButton, newValue);
}
if (targetFragment instanceof BaseSettingsFragment) {
((BaseSettingsFragment) targetFragment).updateSetting(pref.getId());
} }
} }
}) }).create();
.create(); items.add(useHeightButton);
preferenceBtn[0].setCompoundButtonColorId(getAppMode().getIconColorInfo().getColor(nightMode)); }
items.add(new TitleItem(getString(R.string.routing_attr_height_obstacles_name)));
items.add(preferenceBtn[0]);
items.add(new DividerSpaceItem(getMyApplication(), contentPaddingSmall));
items.add(new LongDescriptionItem(getString(R.string.elevation_data)));
items.add(new DividerSpaceItem(getMyApplication(), contentPaddingSmall));
for (int i = 0; i < reliefFactorParameters.size(); i++) { private void updateUseHeightButton(BottomSheetItemWithCompoundButton button, boolean newValue) {
RoutingParameter parameter = reliefFactorParameters.get(i); enableDisableReliefButtons(newValue);
button.setTitle(newValue ? on : off);
button.setChecked(newValue);
button.setTitleColorId(newValue ? activeColor : disabledColor);
updateCustomButtonView(app, appMode, button.getView(), newValue, nightMode);
}
private void createReliefFactorButtons(Context context) {
for (int i = 0; i < parameters.size(); i++) {
RoutingParameter parameter = parameters.get(i);
final BottomSheetItemWithCompoundButton[] preferenceItem = new BottomSheetItemWithCompoundButton[1]; final BottomSheetItemWithCompoundButton[] preferenceItem = new BottomSheetItemWithCompoundButton[1];
preferenceItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() preferenceItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setChecked(i == selectedEntryIndex) .setChecked(i == selectedEntryIndex)
.setButtonTintList(AndroidUtils.createCheckedColorStateList(ctx, R.color.icon_color_default_light, getAppMode().getIconColorInfo().getColor(nightMode))) .setButtonTintList(createCheckedColorStateList(context, R.color.icon_color_default_light, appModeColor))
.setTitle(getRoutingParameterTitle(app, parameter)) .setTitle(getRoutingParameterTitle(app, parameter))
.setTag(i)
.setLayoutId(R.layout.bottom_sheet_item_with_radio_btn_left) .setLayoutId(R.layout.bottom_sheet_item_with_radio_btn_left)
.setTag(i)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
selectedEntryIndex = (int) preferenceItem[0].getTag(); selectedEntryIndex = (int) preferenceItem[0].getTag();
if (selectedEntryIndex >= 0) { if (selectedEntryIndex >= 0) {
RoutingParameter parameter = reliefFactorParameters.get(selectedEntryIndex); RoutingParameter parameter = parameters.get(selectedEntryIndex);
updateSelectedParameters(app, appMode, parameters, parameter.getId());
String selectedParameterId = parameter.getId();
for (RoutingParameter p : reliefFactorParameters) {
String parameterId = p.getId();
setRoutingParameterSelected(app.getSettings(), appMode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId));
}
recalculateRoute();
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof OnPreferenceChanged) {
((OnPreferenceChanged) targetFragment).onPreferenceChanged(pref.getId());
}
} }
updateItems(); updateReliefButtons();
} }
}) }).create();
.create();
reliefFactorButtons.add(preferenceItem[0]);
items.add(preferenceItem[0]); items.add(preferenceItem[0]);
reliefFactorButtons.add(preferenceItem[0]);
} }
} }
private void recalculateRoute() { @Override
RoutingHelper routingHelper = app.getRoutingHelper(); public void onSaveInstanceState(Bundle outState) {
if (getAppMode().equals(routingHelper.getAppMode()) super.onSaveInstanceState(outState);
&& (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())) { outState.putString(APP_MODE_KEY, appMode.getStringKey());
routingHelper.recalculateRouteDueToSettingsChange(); }
@Override
public void onResume() {
super.onResume();
updateReliefButtons();
enableDisableReliefButtons(useHeightButton.isChecked());
}
@Override
protected boolean isNightMode(@NonNull OsmandApplication app) {
if (usedOnMap) {
return app.getDaynightHelper().isNightModeForMapControlsForProfile(appMode);
} else {
return !app.getSettings().isLightContentForMode(appMode);
} }
} }
private String getRoutingParameterTitle(Context context, RoutingParameter parameter) { private List<RoutingParameter> getReliefParametersForMode(Map<String, RoutingParameter> parameters) {
return AndroidUtils.getRoutingStringPropertyName(context, parameter.getId(), parameter.getName()); List<RoutingParameter> reliefParameters = new ArrayList<>();
} for (RoutingParameter routingParameter : parameters.values()) {
if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) {
private void updateItems() { reliefParameters.add(routingParameter);
for (BaseBottomSheetItem item : reliefFactorButtons) {
if (item instanceof BottomSheetItemWithCompoundButton) {
boolean checked = item.getTag().equals(selectedEntryIndex);
((BottomSheetItemWithCompoundButton) item).setChecked(checked);
} }
} }
return reliefParameters;
} }
private void enableItems(boolean enable) { private void updateReliefButtons() {
for (BaseBottomSheetItem item : reliefFactorButtons) { for (BottomSheetItemWithCompoundButton item : reliefFactorButtons) {
if (item instanceof BottomSheetItemWithCompoundButton) { item.setChecked(item.getTag().equals(selectedEntryIndex));
item.getView().setEnabled(enable);
}
} }
} }
public static void showInstance(FragmentManager fm, List<RoutingParameter> reliefFactorParameters, private void enableDisableReliefButtons(boolean enable) {
ApplicationMode appMode, Fragment target, boolean usedOnMap) { for (BaseBottomSheetItem item : reliefFactorButtons) {
item.getView().setEnabled(enable);
}
}
public static void showInstance(FragmentManager fm, ApplicationMode appMode, Fragment target, boolean usedOnMap) {
try { try {
if (fm.findFragmentByTag(ElevationDateBottomSheet.TAG) == null) { if (!fm.isStateSaved() && fm.findFragmentByTag(ElevationDateBottomSheet.TAG) == null) {
ElevationDateBottomSheet fragment = new ElevationDateBottomSheet(); ElevationDateBottomSheet fragment = new ElevationDateBottomSheet();
fragment.setAppMode(appMode); fragment.appMode = appMode;
fragment.setUsedOnMap(usedOnMap); fragment.setUsedOnMap(usedOnMap);
fragment.reliefFactorParameters.addAll(reliefFactorParameters);
fragment.setTargetFragment(target, 0); fragment.setTargetFragment(target, 0);
fragment.show(fm, ScreenTimeoutBottomSheet.TAG); fragment.show(fm, ScreenTimeoutBottomSheet.TAG);
} }
@ -191,5 +230,4 @@ public class ElevationDateBottomSheet extends MenuBottomSheetDialogFragment {
LOG.error("showInstance", e); LOG.error("showInstance", e);
} }
} }
} }

View file

@ -26,7 +26,7 @@ public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet
public static final String TAG = SingleSelectPreferenceBottomSheet.class.getSimpleName(); public static final String TAG = SingleSelectPreferenceBottomSheet.class.getSimpleName();
private static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key"; public static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key";
private static final String USE_COLLAPSIBLE_DESCRIPTION = "use_collapsible_description"; private static final String USE_COLLAPSIBLE_DESCRIPTION = "use_collapsible_description";
private static final int COLLAPSED_DESCRIPTION_LINES = 4; private static final int COLLAPSED_DESCRIPTION_LINES = 4;

View file

@ -90,13 +90,13 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
booleanRoutingPrefListener = new StateChangedListener<Boolean>() { booleanRoutingPrefListener = new StateChangedListener<Boolean>() {
@Override @Override
public void stateChanged(Boolean change) { public void stateChanged(Boolean change) {
recalculateRoute(); recalculateRoute(app, getSelectedAppMode());
} }
}; };
customRoutingPrefListener = new StateChangedListener<String>() { customRoutingPrefListener = new StateChangedListener<String>() {
@Override @Override
public void stateChanged(String change) { public void stateChanged(String change) {
recalculateRoute(); recalculateRoute(app, getSelectedAppMode());
} }
}; };
} }
@ -391,7 +391,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
FragmentManager fragmentManager = getFragmentManager(); FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) { if (fragmentManager != null) {
ApplicationMode appMode = getSelectedAppMode(); ApplicationMode appMode = getSelectedAppMode();
ElevationDateBottomSheet.showInstance(fragmentManager, reliefFactorParameters, appMode, this, false); ElevationDateBottomSheet.showInstance(fragmentManager, appMode, this, false);
} }
} else { } else {
super.onDisplayPreferenceDialog(preference); super.onDisplayPreferenceDialog(preference);
@ -534,14 +534,8 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
@Override @Override
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) { public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) { if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) {
ApplicationMode appMode = getSelectedAppMode();
String selectedParameterId = (String) newValue;
List<RoutingParameter> routingParameters = DRIVING_STYLE.equals(prefId) ? drivingStyleParameters : reliefFactorParameters; List<RoutingParameter> routingParameters = DRIVING_STYLE.equals(prefId) ? drivingStyleParameters : reliefFactorParameters;
for (RoutingParameter p : routingParameters) { updateSelectedParameters(app, getSelectedAppMode(), routingParameters, (String) newValue);
String parameterId = p.getId();
setRoutingParameterSelected(settings, appMode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId));
}
recalculateRoute();
} else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) { } else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) {
applyPreference(ROUTING_SHORT_WAY, applyToAllProfiles, newValue); applyPreference(ROUTING_SHORT_WAY, applyToAllProfiles, newValue);
applyPreference(settings.FAST_ROUTE_MODE.getId(), applyToAllProfiles, !(Boolean) newValue); applyPreference(settings.FAST_ROUTE_MODE.getId(), applyToAllProfiles, !(Boolean) newValue);
@ -568,7 +562,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
@Override @Override
public void onPreferenceChanged(String prefId) { public void onPreferenceChanged(String prefId) {
if (AVOID_ROUTING_PARAMETER_PREFIX.equals(prefId) || PREFER_ROUTING_PARAMETER_PREFIX.equals(prefId)) { if (AVOID_ROUTING_PARAMETER_PREFIX.equals(prefId) || PREFER_ROUTING_PARAMETER_PREFIX.equals(prefId)) {
recalculateRoute(); recalculateRoute(app, getSelectedAppMode());
} }
} }
@ -632,9 +626,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
return multiSelectPref; return multiSelectPref;
} }
private void recalculateRoute() { private static void recalculateRoute(OsmandApplication app, ApplicationMode mode) {
RoutingHelper routingHelper = app.getRoutingHelper(); RoutingHelper routingHelper = app.getRoutingHelper();
if (getSelectedAppMode().equals(routingHelper.getAppMode()) if (mode.equals(routingHelper.getAppMode())
&& (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())) { && (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())) {
routingHelper.recalculateRouteDueToSettingsChange(); routingHelper.recalculateRouteDueToSettingsChange();
} }
@ -648,11 +642,11 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
otherRoutingParameters.clear(); otherRoutingParameters.clear();
} }
private String getRoutingParameterTitle(Context context, RoutingParameter parameter) { public static String getRoutingParameterTitle(Context context, RoutingParameter parameter) {
return AndroidUtils.getRoutingStringPropertyName(context, parameter.getId(), parameter.getName()); return AndroidUtils.getRoutingStringPropertyName(context, parameter.getId(), parameter.getName());
} }
private boolean isRoutingParameterSelected(OsmandSettings settings, ApplicationMode mode, RoutingParameter parameter) { public static boolean isRoutingParameterSelected(OsmandSettings settings, ApplicationMode mode, RoutingParameter parameter) {
CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean()); CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
if (mode != null) { if (mode != null) {
return property.getModeValue(mode); return property.getModeValue(mode);
@ -661,8 +655,17 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
} }
} }
public static void setRoutingParameterSelected(OsmandSettings settings, ApplicationMode mode, public static void updateSelectedParameters(OsmandApplication app, ApplicationMode mode,
String parameterId, boolean defaultBoolean, boolean isChecked) { List<RoutingParameter> parameters, String selectedParameterId) {
for (RoutingParameter p : parameters) {
String parameterId = p.getId();
setRoutingParameterSelected(app.getSettings(), mode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId));
}
recalculateRoute(app, mode);
}
private static void setRoutingParameterSelected(OsmandSettings settings, ApplicationMode mode,
String parameterId, boolean defaultBoolean, boolean isChecked) {
CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(parameterId, defaultBoolean); CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(parameterId, defaultBoolean);
if (mode != null) { if (mode != null) {
property.setModeValue(mode, isChecked); property.setModeValue(mode, isChecked);