Invert setting value in preference bottom sheet

This commit is contained in:
cepprice 2021-02-25 20:17:55 +05:00
parent 8ff6eff178
commit 33c5c562d9

View file

@ -66,7 +66,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
? getString(R.string.shared_string_disabled) : summaryOff.toString();
final int activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
final int disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary);
boolean checked = pref.getModeValue(getAppMode());
boolean checked = isPreferenceChecked(pref, app);
final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1];
preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
@ -77,7 +77,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean newValue = !pref.getModeValue(getAppMode());
boolean newValue = !isPreferenceChecked(pref, app);
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof OnConfirmPreferenceChange) {
ApplyQueryType applyQueryType = getApplyQueryType();
@ -156,6 +156,13 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
return (SwitchPreferenceEx) getPreference();
}
private boolean isPreferenceChecked(BooleanPreference preference, OsmandApplication app) {
boolean checked = preference.getModeValue(getAppMode());
boolean shouldInvertSetting = app.getSettings().DISABLE_COMPLEX_ROUTING.getId()
.equals(preference.getId());
return checked != shouldInvertSetting;
}
public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target, boolean usedOnMap,
@Nullable ApplicationMode appMode, ApplyQueryType applyQueryType,
boolean profileDependent) {