This commit is contained in:
Chumva 2019-11-08 18:05:47 +02:00
parent 7743efe4c9
commit 2593ffea4e
7 changed files with 158 additions and 24 deletions

View file

@ -45,6 +45,7 @@ import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayer;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.GeneralRouterProfile; import net.osmand.router.GeneralRouter.GeneralRouterProfile;
@ -788,6 +789,10 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
settings.MIN_SPEED.set(minValue[0] / ratio[0]); settings.MIN_SPEED.set(minValue[0] / ratio[0]);
settings.MAX_SPEED.set(maxValue[0] / ratio[0]); settings.MAX_SPEED.set(maxValue[0] / ratio[0]);
} }
RoutingHelper routingHelper = app.getRoutingHelper();
if (mode.equals(routingHelper.getAppMode()) && (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())) {
routingHelper.recalculateRouteDueToSettingsChange();
}
} }
}); });
builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setNegativeButton(R.string.shared_string_cancel, null);
@ -799,6 +804,10 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
settings.MIN_SPEED.set(0f); settings.MIN_SPEED.set(0f);
settings.MAX_SPEED.set(0f); settings.MAX_SPEED.set(0f);
} }
RoutingHelper routingHelper = app.getRoutingHelper();
if (mode.equals(routingHelper.getAppMode()) && (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())) {
routingHelper.recalculateRouteDueToSettingsChange();
}
} }
}); });

View file

@ -2,12 +2,14 @@ package net.osmand.plus.settings;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder; import android.support.v7.preference.PreferenceViewHolder;
import android.widget.ImageView; import android.widget.ImageView;
import net.osmand.StateChangedListener;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -16,10 +18,13 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsNavigationActivity; import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference; import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.GeneralRouter.RoutingParameterType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,7 +36,7 @@ import java.util.Set;
import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter; import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter;
import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE; import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE;
public class RouteParametersFragment extends BaseSettingsFragment { public class RouteParametersFragment extends BaseSettingsFragment implements OnPreferenceChanged {
public static final String TAG = RouteParametersFragment.class.getSimpleName(); public static final String TAG = RouteParametersFragment.class.getSimpleName();
@ -41,12 +46,32 @@ public class RouteParametersFragment extends BaseSettingsFragment {
private static final String ROUTE_PARAMETERS_IMAGE = "route_parameters_image"; private static final String ROUTE_PARAMETERS_IMAGE = "route_parameters_image";
private static final String RELIEF_SMOOTHNESS_FACTOR = "relief_smoothness_factor"; private static final String RELIEF_SMOOTHNESS_FACTOR = "relief_smoothness_factor";
private List<GeneralRouter.RoutingParameter> avoidParameters = new ArrayList<GeneralRouter.RoutingParameter>(); private List<RoutingParameter> avoidParameters = new ArrayList<RoutingParameter>();
private List<GeneralRouter.RoutingParameter> preferParameters = new ArrayList<GeneralRouter.RoutingParameter>(); private List<RoutingParameter> preferParameters = new ArrayList<RoutingParameter>();
private List<GeneralRouter.RoutingParameter> drivingStyleParameters = new ArrayList<GeneralRouter.RoutingParameter>(); private List<RoutingParameter> drivingStyleParameters = new ArrayList<RoutingParameter>();
private List<GeneralRouter.RoutingParameter> reliefFactorParameters = new ArrayList<GeneralRouter.RoutingParameter>(); private List<RoutingParameter> reliefFactorParameters = new ArrayList<RoutingParameter>();
private List<GeneralRouter.RoutingParameter> otherRoutingParameters = new ArrayList<GeneralRouter.RoutingParameter>(); private List<RoutingParameter> otherRoutingParameters = new ArrayList<RoutingParameter>();
private StateChangedListener<Boolean> booleanRoutingPrefListener;
private StateChangedListener<String> customRoutingPrefListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
booleanRoutingPrefListener = new StateChangedListener<Boolean>() {
@Override
public void stateChanged(Boolean change) {
recalculateRoute();
}
};
customRoutingPrefListener = new StateChangedListener<String>() {
@Override
public void stateChanged(String change) {
recalculateRoute();
}
};
}
@Override @Override
protected void setupPreferences() { protected void setupPreferences() {
@ -118,13 +143,13 @@ public class RouteParametersFragment extends BaseSettingsFragment {
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am); GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am);
clearParameters(); clearParameters();
if (router != null) { if (router != null) {
Map<String, GeneralRouter.RoutingParameter> parameters = router.getParameters(); Map<String, RoutingParameter> parameters = router.getParameters();
if (!am.isDerivedRoutingFrom(ApplicationMode.CAR)) { if (!am.isDerivedRoutingFrom(ApplicationMode.CAR)) {
screen.addPreference(fastRoute); screen.addPreference(fastRoute);
} }
for (Map.Entry<String, GeneralRouter.RoutingParameter> e : parameters.entrySet()) { for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
String param = e.getKey(); String param = e.getKey();
GeneralRouter.RoutingParameter routingParameter = e.getValue(); RoutingParameter routingParameter = e.getValue();
if (param.startsWith(AVOID_ROUTING_PARAMETER_PREFIX)) { if (param.startsWith(AVOID_ROUTING_PARAMETER_PREFIX)) {
avoidParameters.add(routingParameter); avoidParameters.add(routingParameter);
} else if (param.startsWith(PREFER_ROUTING_PARAMETER_PREFIX)) { } else if (param.startsWith(PREFER_ROUTING_PARAMETER_PREFIX)) {
@ -162,11 +187,11 @@ public class RouteParametersFragment extends BaseSettingsFragment {
screen.addPreference(reliefFactorRouting); screen.addPreference(reliefFactorRouting);
} }
for (GeneralRouter.RoutingParameter p : otherRoutingParameters) { for (RoutingParameter p : otherRoutingParameters) {
String title = SettingsBaseActivity.getRoutingStringPropertyName(app, p.getId(), p.getName()); String title = SettingsBaseActivity.getRoutingStringPropertyName(app, p.getId(), p.getName());
String description = SettingsBaseActivity.getRoutingStringPropertyDescription(app, p.getId(), p.getDescription()); String description = SettingsBaseActivity.getRoutingStringPropertyDescription(app, p.getId(), p.getDescription());
if (p.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) { if (p.getType() == RoutingParameterType.BOOLEAN) {
OsmandSettings.OsmandPreference pref = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()); OsmandSettings.OsmandPreference pref = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
SwitchPreferenceEx switchPreferenceEx = (SwitchPreferenceEx) createSwitchPreferenceEx(pref.getId(), title, description, R.layout.preference_with_descr_dialog_and_switch); SwitchPreferenceEx switchPreferenceEx = (SwitchPreferenceEx) createSwitchPreferenceEx(pref.getId(), title, description, R.layout.preference_with_descr_dialog_and_switch);
@ -184,7 +209,7 @@ public class RouteParametersFragment extends BaseSettingsFragment {
for (Object o : vls) { for (Object o : vls) {
svlss[i++] = o.toString(); svlss[i++] = o.toString();
} }
OsmandSettings.OsmandPreference pref = settings.getCustomRoutingProperty(p.getId(), p.getType() == GeneralRouter.RoutingParameterType.NUMERIC ? "0.0" : "-"); OsmandSettings.OsmandPreference pref = settings.getCustomRoutingProperty(p.getId(), p.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
ListPreferenceEx listPreferenceEx = (ListPreferenceEx) createListPreferenceEx(pref.getId(), p.getPossibleValueDescriptions(), svlss, title, R.layout.preference_with_descr); ListPreferenceEx listPreferenceEx = (ListPreferenceEx) createListPreferenceEx(pref.getId(), p.getPossibleValueDescriptions(), svlss, title, R.layout.preference_with_descr);
listPreferenceEx.setDescription(description); listPreferenceEx.setDescription(description);
@ -198,24 +223,82 @@ public class RouteParametersFragment extends BaseSettingsFragment {
} }
} }
@Override
public void onResume() {
super.onResume();
addRoutingPrefListeners();
}
@Override
public void onPause() {
super.onPause();
removeRoutingPrefListeners();
}
@Override
public void onAppModeChanged() {
removeRoutingPrefListeners();
super.onAppModeChanged();
addRoutingPrefListeners();
}
private void addRoutingPrefListeners() {
settings.FAST_ROUTE_MODE.addListener(booleanRoutingPrefListener);
settings.ENABLE_TIME_CONDITIONAL_ROUTING.addListener(booleanRoutingPrefListener);
for (RoutingParameter parameter : otherRoutingParameters) {
if (parameter.getType() == RoutingParameterType.BOOLEAN) {
OsmandSettings.CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
pref.addListener(booleanRoutingPrefListener);
} else {
OsmandSettings.CommonPreference<String> pref = settings.getCustomRoutingProperty(parameter.getId(), parameter.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
pref.addListener(customRoutingPrefListener);
}
}
}
private void removeRoutingPrefListeners() {
settings.FAST_ROUTE_MODE.removeListener(booleanRoutingPrefListener);
settings.ENABLE_TIME_CONDITIONAL_ROUTING.removeListener(booleanRoutingPrefListener);
for (RoutingParameter parameter : otherRoutingParameters) {
if (parameter.getType() == RoutingParameterType.BOOLEAN) {
OsmandSettings.CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
pref.removeListener(booleanRoutingPrefListener);
} else {
OsmandSettings.CommonPreference<String> pref = settings.getCustomRoutingProperty(parameter.getId(), parameter.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
pref.removeListener(customRoutingPrefListener);
}
}
}
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey(); String key = preference.getKey();
if ((RELIEF_SMOOTHNESS_FACTOR.equals(key) || DRIVING_STYLE.equals(key)) && newValue instanceof String) { if ((RELIEF_SMOOTHNESS_FACTOR.equals(key) || DRIVING_STYLE.equals(key)) && newValue instanceof String) {
ApplicationMode appMode = getSelectedAppMode();
String selectedParameterId = (String) newValue; String selectedParameterId = (String) newValue;
List<GeneralRouter.RoutingParameter> routingParameters = DRIVING_STYLE.equals(key) ? drivingStyleParameters : reliefFactorParameters; List<RoutingParameter> routingParameters = DRIVING_STYLE.equals(key) ? drivingStyleParameters : reliefFactorParameters;
for (GeneralRouter.RoutingParameter parameter : routingParameters) { for (RoutingParameter p : routingParameters) {
String parameterId = parameter.getId(); String parameterId = p.getId();
SettingsNavigationActivity.setRoutingParameterSelected(settings, getSelectedAppMode(), parameterId, parameter.getDefaultBoolean(), parameterId.equals(selectedParameterId)); SettingsNavigationActivity.setRoutingParameterSelected(settings, appMode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId));
} }
recalculateRoute();
return true; return true;
} }
return super.onPreferenceChange(preference, newValue); return super.onPreferenceChange(preference, newValue);
} }
private ListPreferenceEx createRoutingBooleanListPreference(String groupKey, List<GeneralRouter.RoutingParameter> routingParameters) { @Override
public void onPreferenceChanged(String prefId) {
if (AVOID_ROUTING_PARAMETER_PREFIX.equals(prefId) || PREFER_ROUTING_PARAMETER_PREFIX.equals(prefId)) {
recalculateRoute();
}
}
private ListPreferenceEx createRoutingBooleanListPreference(String groupKey, List<RoutingParameter> routingParameters) {
String defaultTitle = Algorithms.capitalizeFirstLetterAndLowercase(groupKey.replace('_', ' ')); String defaultTitle = Algorithms.capitalizeFirstLetterAndLowercase(groupKey.replace('_', ' '));
String title = SettingsBaseActivity.getRoutingStringPropertyName(app, groupKey, defaultTitle); String title = SettingsBaseActivity.getRoutingStringPropertyName(app, groupKey, defaultTitle);
ApplicationMode am = settings.getApplicationMode(); ApplicationMode am = settings.getApplicationMode();
@ -225,7 +308,7 @@ public class RouteParametersFragment extends BaseSettingsFragment {
String selectedParameterId = null; String selectedParameterId = null;
for (int i = 0; i < routingParameters.size(); i++) { for (int i = 0; i < routingParameters.size(); i++) {
GeneralRouter.RoutingParameter parameter = routingParameters.get(i); RoutingParameter parameter = routingParameters.get(i);
entryValues[i] = parameter.getId(); entryValues[i] = parameter.getId();
entries[i] = SettingsNavigationActivity.getRoutinParameterTitle(app, parameter); entries[i] = SettingsNavigationActivity.getRoutinParameterTitle(app, parameter);
if (SettingsNavigationActivity.isRoutingParameterSelected(settings, am, parameter)) { if (SettingsNavigationActivity.isRoutingParameterSelected(settings, am, parameter)) {
@ -241,7 +324,7 @@ public class RouteParametersFragment extends BaseSettingsFragment {
return routingListPref; return routingListPref;
} }
private MultiSelectBooleanPreference createRoutingBooleanMultiSelectPref(String groupKey, String title, String descr, List<GeneralRouter.RoutingParameter> routingParameters) { private MultiSelectBooleanPreference createRoutingBooleanMultiSelectPref(String groupKey, String title, String descr, List<RoutingParameter> routingParameters) {
MultiSelectBooleanPreference multiSelectPref = new MultiSelectBooleanPreference(app); MultiSelectBooleanPreference multiSelectPref = new MultiSelectBooleanPreference(app);
multiSelectPref.setKey(groupKey); multiSelectPref.setKey(groupKey);
multiSelectPref.setTitle(title); multiSelectPref.setTitle(title);
@ -255,7 +338,7 @@ public class RouteParametersFragment extends BaseSettingsFragment {
Set<String> enabledPrefsIds = new HashSet<>(); Set<String> enabledPrefsIds = new HashSet<>();
for (int i = 0; i < routingParameters.size(); i++) { for (int i = 0; i < routingParameters.size(); i++) {
GeneralRouter.RoutingParameter p = routingParameters.get(i); RoutingParameter p = routingParameters.get(i);
BooleanPreference booleanRoutingPref = (BooleanPreference) settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()); BooleanPreference booleanRoutingPref = (BooleanPreference) settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
entries[i] = SettingsBaseActivity.getRoutingStringPropertyName(app, p.getId(), p.getName()); entries[i] = SettingsBaseActivity.getRoutingStringPropertyName(app, p.getId(), p.getName());
@ -273,6 +356,14 @@ public class RouteParametersFragment extends BaseSettingsFragment {
return multiSelectPref; return multiSelectPref;
} }
private void recalculateRoute() {
RoutingHelper routingHelper = app.getRoutingHelper();
if (getSelectedAppMode().equals(routingHelper.getAppMode())
&& (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())) {
routingHelper.recalculateRouteDueToSettingsChange();
}
}
private void clearParameters() { private void clearParameters() {
avoidParameters.clear(); avoidParameters.clear();
preferParameters.clear(); preferParameters.clear();

View file

@ -9,6 +9,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
@ -17,7 +18,7 @@ import java.util.Map;
import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter; import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter;
import static net.osmand.plus.activities.SettingsNavigationActivity.showSeekbarSettingsDialog; import static net.osmand.plus.activities.SettingsNavigationActivity.showSeekbarSettingsDialog;
public class VehicleParametersFragment extends BaseSettingsFragment { public class VehicleParametersFragment extends BaseSettingsFragment implements OnPreferenceChanged {
public static final String TAG = VehicleParametersFragment.class.getSimpleName(); public static final String TAG = VehicleParametersFragment.class.getSimpleName();
@ -107,6 +108,19 @@ public class VehicleParametersFragment extends BaseSettingsFragment {
return super.onPreferenceClick(preference); return super.onPreferenceClick(preference);
} }
@Override
public void onPreferenceChanged(String prefId) {
recalculateRoute();
}
private void recalculateRoute() {
RoutingHelper routingHelper = app.getRoutingHelper();
if (getSelectedAppMode().equals(routingHelper.getAppMode())
&& (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())) {
routingHelper.recalculateRouteDueToSettingsChange();
}
}
private Drawable getPreferenceIcon(String prefId) { private Drawable getPreferenceIcon(String prefId) {
switch (prefId) { switch (prefId) {
case GeneralRouter.DEFAULT_SPEED: case GeneralRouter.DEFAULT_SPEED:

View file

@ -22,6 +22,7 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.OnPreferenceChanged;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -68,6 +69,11 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
switchPreference.setChecked(newValue); switchPreference.setChecked(newValue);
preferenceBtn[0].setTitle(newValue ? on : off); preferenceBtn[0].setTitle(newValue ? on : off);
preferenceBtn[0].setChecked(newValue); preferenceBtn[0].setChecked(newValue);
Fragment target = getTargetFragment();
if (target instanceof OnPreferenceChanged) {
((OnPreferenceChanged) target).onPreferenceChanged(switchPreference.getKey());
}
} }
} }
}) })

View file

@ -11,6 +11,7 @@ import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
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.settings.OnPreferenceChanged;
import net.osmand.plus.settings.preferences.EditTextPreferenceEx; import net.osmand.plus.settings.preferences.EditTextPreferenceEx;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -71,6 +72,11 @@ public class EditTextPreferenceBottomSheet extends BasePreferenceBottomSheet {
String value = editText.getText().toString(); String value = editText.getText().toString();
if (editTextPreference.callChangeListener(value)) { if (editTextPreference.callChangeListener(value)) {
editTextPreference.setText(value); editTextPreference.setText(value);
Fragment target = getTargetFragment();
if (target instanceof OnPreferenceChanged) {
((OnPreferenceChanged) target).onPreferenceChanged(editTextPreference.getKey());
}
} }
} }

View file

@ -13,6 +13,7 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
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.settings.OnPreferenceChanged;
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference; import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -119,6 +120,11 @@ public class MultiSelectPreferencesBottomSheet extends BasePreferenceBottomSheet
final Set<String> values = enabledPrefs; final Set<String> values = enabledPrefs;
if (multiSelectBooleanPreference.callChangeListener(values)) { if (multiSelectBooleanPreference.callChangeListener(values)) {
multiSelectBooleanPreference.setValues(values); multiSelectBooleanPreference.setValues(values);
Fragment target = getTargetFragment();
if (target instanceof OnPreferenceChanged) {
((OnPreferenceChanged) target).onPreferenceChanged(multiSelectBooleanPreference.getKey());
}
} }
} }
prefChanged = false; prefChanged = false;

View file

@ -43,10 +43,12 @@ public class MultiSelectBooleanPreference extends MultiSelectListPreference {
} }
public void setValues(Set<String> values) { public void setValues(Set<String> values) {
getValues().clear(); if (!getValues().equals(values)) {
getValues().addAll(values); getValues().clear();
getValues().addAll(values);
persistBooleanPrefs(); persistBooleanPrefs();
}
} }
public String getDescription() { public String getDescription() {