Show SnackBar when preference change (fixes p.2)

This commit is contained in:
Nazar-Kutz 2020-04-09 17:33:52 +03:00
parent 5446ad43f8
commit 6fd89d17e6
14 changed files with 141 additions and 101 deletions

View file

@ -15,12 +15,15 @@ import android.os.Build;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
@ -37,6 +40,7 @@ import androidx.core.view.ViewCompat;
import androidx.core.widget.TintableCompoundButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.snackbar.SnackbarContentLayout;
import net.osmand.AndroidUtils;
import net.osmand.Location;
@ -390,6 +394,28 @@ public class UiUtilities {
view.setBackgroundColor(ContextCompat.getColor(ctx, backgroundColor));
}
public static void setupSnackbarVerticalLayout(Snackbar snackbar) {
View view = snackbar.getView();
Context ctx = view.getContext();
TextView messageView = (TextView) view.findViewById(com.google.android.material.R.id.snackbar_text);
TextView actionView = (TextView) view.findViewById(com.google.android.material.R.id.snackbar_action);
ViewParent parent = actionView.getParent();
if (parent instanceof SnackbarContentLayout) {
((SnackbarContentLayout) parent).removeView(actionView);
((SnackbarContentLayout) parent).removeView(messageView);
LinearLayout container = new LinearLayout(ctx);
container.setOrientation(LinearLayout.VERTICAL);
container.addView(messageView);
container.addView(actionView);
((SnackbarContentLayout) parent).addView(container);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
actionView.setGravity(Gravity.CENTER_VERTICAL | Gravity.END);
container.setLayoutParams(params);
}
}
public static void rotateImageByLayoutDirection(ImageView image, int layoutDirection) {
if (image == null) {
return;

View file

@ -83,7 +83,7 @@ import java.io.Serializable;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener,
OnPreferenceClickListener, AppModeChangedListener, OnApplyPreference {
OnPreferenceClickListener, AppModeChangedListener, OnConfirmPreferenceChange {
private static final Log LOG = PlatformUtil.getLog(BaseSettingsFragment.class);
@ -314,26 +314,28 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return onApplyPreference(preference.getKey(), newValue, getApplyQueryType());
return onConfirmPreferenceChange(preference.getKey(), newValue, getApplyQueryType());
}
@Override
public boolean onApplyPreference(String prefId, Object newValue, ApplyQueryType applyQueryType) {
public boolean onConfirmPreferenceChange(String prefId, Object newValue, ApplyQueryType applyQueryType) {
if (applyQueryType != null && newValue instanceof Serializable) {
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
if (pref instanceof CommonPreference) {
if (applyQueryType == ApplyQueryType.SNACK_BAR) {
applySettingWithSnackBar(prefId, (Serializable) newValue);
applyPreferenceWithSnackBar(prefId, (Serializable) newValue);
return true;
} else if (applyQueryType == ApplyQueryType.BOTTOM_SHEET) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
(Serializable) newValue, this, false, getSelectedAppMode());
}
return false;
} else if (applyQueryType == ApplyQueryType.NONE) {
onSettingApplied(prefId, newValue, false);
onApplyPreferenceChange(prefId, false, newValue);
return true;
}
return true;
}
}
return true;
@ -363,7 +365,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
if (preference instanceof ListPreferenceEx) {
SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode, isProfileDependent(), false);
} else if (preference instanceof SwitchPreferenceEx) {
BooleanPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode, isProfileDependent());
BooleanPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode, getApplyQueryType(), isProfileDependent());
} else if (preference instanceof EditTextPreference) {
EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
} else if (preference instanceof MultiSelectBooleanPreference) {
@ -606,7 +608,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
public void onSettingApplied(String prefId, boolean appliedToAllProfiles) {
}
public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) {
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
if (appliedToAllProfiles) {
app.getSettings().setPreferenceForAllModes(prefId, newValue);
} else {
@ -904,8 +906,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
}
}
protected void applySettingWithSnackBar(final String prefId, final Serializable newValue) {
onSettingApplied(prefId, newValue, false);
protected void applyPreferenceWithSnackBar(final String prefId, final Serializable newValue) {
onApplyPreferenceChange(prefId, false, newValue);
updateSetting(prefId);
View containerView = getView();
if (containerView != null) {
@ -916,9 +918,10 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
.setAction(R.string.apply_to_all_profiles, new View.OnClickListener() {
@Override
public void onClick(View view) {
onSettingApplied(prefId, newValue, true);
onApplyPreferenceChange(prefId, true, newValue);
}
});
UiUtilities.setupSnackbarVerticalLayout(snackbar);
snackbar.show();
}
}

View file

@ -17,7 +17,6 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatCheckedTextView;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.SwitchPreferenceCompat;
@ -25,16 +24,13 @@ import androidx.preference.SwitchPreferenceCompat;
import net.osmand.data.PointDescription;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -355,7 +351,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefId = preference.getKey();
if (settings.ROTATE_MAP.getId().equals(prefId)) {
onApplyPreference(prefId, newValue, ApplyQueryType.SNACK_BAR);
onConfirmPreferenceChange(prefId, newValue, ApplyQueryType.SNACK_BAR);
return false;
}
return super.onPreferenceChange(preference, newValue);

View file

@ -2,7 +2,6 @@ package net.osmand.plus.settings;
import androidx.preference.Preference;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.AutoZoomMap;
import net.osmand.plus.R;
@ -102,38 +101,27 @@ public class MapDuringNavigationFragment extends BaseSettingsFragment {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference.getKey().equals(settings.AUTO_ZOOM_MAP.getId())) {
onApplyPreference(settings.AUTO_ZOOM_MAP.getId(), newValue, ApplyQueryType.SNACK_BAR);
onConfirmPreferenceChange(settings.AUTO_ZOOM_MAP.getId(), newValue, ApplyQueryType.SNACK_BAR);
return true;
}
return super.onPreferenceChange(preference, newValue);
}
@Override
public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) {
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
if (settings.AUTO_ZOOM_MAP.getId().equals(prefId)) {
if (newValue instanceof Integer) {
ApplicationMode selectedMode = getSelectedAppMode();
int position = (int) newValue;
if (appliedToAllProfiles) {
if (position == 0) {
settings.setPreferenceForAllModes(settings.AUTO_ZOOM_MAP.getId(), false);
} else {
settings.setPreferenceForAllModes(settings.AUTO_ZOOM_MAP.getId(), true);
settings.setPreferenceForAllModes(settings.AUTO_ZOOM_MAP_SCALE.getId(),
OsmandSettings.AutoZoomMap.values()[position - 1]);
}
if (position == 0) {
super.onApplyPreferenceChange(settings.AUTO_ZOOM_MAP.getId(), appliedToAllProfiles, false);
} else {
if (position == 0) {
settings.AUTO_ZOOM_MAP.setModeValue(selectedMode, false);
} else {
settings.AUTO_ZOOM_MAP.setModeValue(selectedMode, true);
settings.AUTO_ZOOM_MAP_SCALE.setModeValue(selectedMode,
OsmandSettings.AutoZoomMap.values()[position - 1]);
}
super.onApplyPreferenceChange(settings.AUTO_ZOOM_MAP.getId(), appliedToAllProfiles, true);
super.onApplyPreferenceChange(settings.AUTO_ZOOM_MAP_SCALE.getId(),
appliedToAllProfiles, OsmandSettings.AutoZoomMap.values()[position - 1]);
}
return;
}
} else {
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
}
super.onSettingApplied(prefId, newValue, appliedToAllProfiles);
}
}

View file

@ -21,7 +21,6 @@ import net.osmand.router.GeneralRouter;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.Algorithms;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -93,13 +92,13 @@ public class NavigationFragment extends BaseSettingsFragment {
}
@Override
public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) {
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
if (settings.VOICE_MUTE.getId().equals(prefId) && newValue instanceof Boolean) {
super.onSettingApplied(prefId, !(Boolean) newValue, appliedToAllProfiles);
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, !(Boolean) newValue);
updateMenu();
return;
} else {
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
}
super.onSettingApplied(prefId, newValue, appliedToAllProfiles);
}
@Override

View file

@ -1,7 +0,0 @@
package net.osmand.plus.settings;
public interface OnApplyPreference {
boolean onApplyPreference(String prefId, Object newValue, ApplyQueryType applyQueryType);
}

View file

@ -0,0 +1,7 @@
package net.osmand.plus.settings;
public interface OnConfirmPreferenceChange {
boolean onConfirmPreferenceChange(String prefId, Object newValue, ApplyQueryType applyQueryType);
}

View file

@ -411,7 +411,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
}
@Override
public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) {
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) {
ApplicationMode appMode = getSelectedAppMode();
String selectedParameterId = (String) newValue;
@ -421,14 +421,12 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
SettingsNavigationActivity.setRoutingParameterSelected(settings, appMode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId));
}
recalculateRoute();
return;
} else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) {
if (appliedToAllProfiles) {
settings.setPreferenceForAllModes(settings.FAST_ROUTE_MODE.getId(), !(Boolean) newValue);
} else {
settings.setPreference(settings.FAST_ROUTE_MODE.getId(), !(Boolean) newValue, getSelectedAppMode());
}
return;
} else if (ROUTING_RECALC_DISTANCE.equals(prefId)) {
boolean enabled = false;
float valueToSave = DISABLE_MODE;
@ -439,25 +437,18 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
valueToSave = (float) newValue;
enabled = valueToSave != DISABLE_MODE;
}
if (appliedToAllProfiles) {
settings.setPreferenceForAllModes(prefId, valueToSave);
settings.setPreferenceForAllModes(settings.DISABLE_OFFROUTE_RECALC.getId(), !enabled);
} else {
settings.setPreference(prefId, valueToSave, getSelectedAppMode());
settings.setPreference(settings.DISABLE_OFFROUTE_RECALC.getId(), !enabled, getSelectedAppMode());
}
super.onApplyPreferenceChange(ROUTING_RECALC_DISTANCE, appliedToAllProfiles, valueToSave);
super.onApplyPreferenceChange(settings.DISABLE_OFFROUTE_RECALC.getId(), appliedToAllProfiles, !enabled);
updateRouteRecalcDistancePref();
return;
} else {
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
}
super.onSettingApplied(prefId, newValue, appliedToAllProfiles);
}
@Override
public void onPreferenceChanged(String prefId) {
if (AVOID_ROUTING_PARAMETER_PREFIX.equals(prefId) || PREFER_ROUTING_PARAMETER_PREFIX.equals(prefId)) {
recalculateRoute();
} else if (ROUTING_RECALC_DISTANCE.equals(prefId)) {
updateRouteRecalcDistancePref();
}
}

View file

@ -55,7 +55,8 @@ public class ScreenAlertsFragment extends BaseSettingsFragment {
public void onClick(View view) {
ApplicationMode selectedMode = getSelectedAppMode();
boolean checked = !settings.SHOW_ROUTING_ALARMS.getModeValue(selectedMode);
onApplyPreference(settings.SHOW_ROUTING_ALARMS.getId(), checked, ApplyQueryType.SNACK_BAR);
onConfirmPreferenceChange(
settings.SHOW_ROUTING_ALARMS.getId(), checked, ApplyQueryType.SNACK_BAR);
updateToolbarSwitch();
enableDisablePreferences(checked);
}

View file

@ -43,7 +43,8 @@ public class TurnScreenOnFragment extends BaseSettingsFragment {
public void onClick(View view) {
ApplicationMode selectedMode = getSelectedAppMode();
boolean checked = !settings.TURN_SCREEN_ON_ENABLED.getModeValue(selectedMode);
onApplyPreference(settings.TURN_SCREEN_ON_ENABLED.getId(), checked, ApplyQueryType.SNACK_BAR);
onConfirmPreferenceChange(
settings.TURN_SCREEN_ON_ENABLED.getId(), checked, ApplyQueryType.SNACK_BAR);
updateToolbarSwitch();
enableDisablePreferences(checked);
}

View file

@ -50,7 +50,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
public void onClick(View view) {
ApplicationMode selectedMode = getSelectedAppMode();
boolean checked = !settings.VOICE_MUTE.getModeValue(selectedMode);
onApplyPreference(settings.VOICE_MUTE.getId(), checked, ApplyQueryType.SNACK_BAR);
onConfirmPreferenceChange(
settings.VOICE_MUTE.getId(), checked, ApplyQueryType.SNACK_BAR);
updateToolbarSwitch();
enableDisablePreferences(!checked);
updateMenu();
@ -219,7 +220,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
onApplyPreference(settings.SPEAK_SPEED_CAMERA.getId(), true, ApplyQueryType.SNACK_BAR);
onConfirmPreferenceChange(
settings.SPEAK_SPEED_CAMERA.getId(), true, ApplyQueryType.SNACK_BAR);
SwitchPreferenceCompat speakSpeedCamera = (SwitchPreferenceCompat) findPreference(settings.SPEAK_SPEED_CAMERA.getId());
if (speakSpeedCamera != null) {
speakSpeedCamera.setChecked(true);
@ -267,13 +269,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
startActivity(intent);
return false;
} else if (newValue instanceof String) {
if (VOICE_PROVIDER_NOT_USE.equals(newValue)) {
onApplyPreference(settings.VOICE_MUTE.getId(), true, ApplyQueryType.SNACK_BAR);
updateToolbar();
// setupPreferences(); //TODO doesn't need anymore
}
onApplyPreference(settings.VOICE_PROVIDER.getId(), newValue, ApplyQueryType.SNACK_BAR);
app.initVoiceCommandPlayer(getActivity(), selectedMode, false, null, true, false, false);
onConfirmPreferenceChange(settings.VOICE_PROVIDER.getId(), newValue, ApplyQueryType.SNACK_BAR);
}
return true;
}
@ -282,10 +278,29 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
confirmSpeedCamerasDlg();
return false;
} else {
return onApplyPreference(settings.SPEAK_SPEED_CAMERA.getId(), false, ApplyQueryType.SNACK_BAR);
return onConfirmPreferenceChange(
settings.SPEAK_SPEED_CAMERA.getId(), false, ApplyQueryType.SNACK_BAR);
}
}
if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) {
return onConfirmPreferenceChange(
settings.AUDIO_MANAGER_STREAM.getId(), newValue, ApplyQueryType.SNACK_BAR);
}
return super.onPreferenceChange(preference, newValue);
}
@Override
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
if (prefId.equals(settings.VOICE_PROVIDER.getId()) && newValue instanceof String) {
if (VOICE_PROVIDER_NOT_USE.equals(newValue)) {
super.onApplyPreferenceChange(settings.VOICE_MUTE.getId(), appliedToAllProfiles, true);
updateToolbar();
}
super.onApplyPreferenceChange(settings.VOICE_PROVIDER.getId(), appliedToAllProfiles, newValue);
app.initVoiceCommandPlayer(getActivity(), getSelectedAppMode(),
false, null, true, false, appliedToAllProfiles);
} else if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) {
// Sync DEFAULT value with CAR value, as we have other way to set it for now
if (getSelectedAppMode().equals(ApplicationMode.CAR) && newValue instanceof Integer) {
@ -294,10 +309,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
settings.AUDIO_MANAGER_STREAM.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_MANAGER_STREAM.getModeValue(ApplicationMode.CAR));
}
settings.AUDIO_USAGE.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_USAGE.getModeValue(ApplicationMode.CAR));
return true;
} else {
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
}
return super.onPreferenceChange(preference, newValue);
}
}

View file

@ -11,6 +11,7 @@ import androidx.preference.Preference;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.settings.ApplyQueryType;
import java.util.List;
@ -18,12 +19,14 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
public static final String PREFERENCE_ID = "preference_id";
private static final String APP_MODE_KEY = "app_mode_key";
private static final String APPLY_QUERY_TYPE = "apply_query_type";
private static final String PROFILE_DEPENDENT = "profile_dependent";
private String prefId;
private Preference preference;
private ApplicationMode appMode;
private boolean profileDependent;
private ApplyQueryType applyQueryType;
public void setAppMode(ApplicationMode appMode) {
this.appMode = appMode;
@ -38,6 +41,7 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
applyQueryType = ApplyQueryType.valueOf(savedInstanceState.getString(APPLY_QUERY_TYPE));
profileDependent = savedInstanceState.getBoolean(PROFILE_DEPENDENT, false);
}
}
@ -49,6 +53,9 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
if (appMode != null) {
outState.putString(APP_MODE_KEY, appMode.getStringKey());
}
if (applyQueryType != null) {
outState.putString(APPLY_QUERY_TYPE, applyQueryType.name());
}
}
@Override
@ -107,4 +114,12 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
public boolean isProfileDependent() {
return profileDependent;
}
public void setApplyQueryType(ApplyQueryType applyQueryType) {
this.applyQueryType = applyQueryType;
}
public ApplyQueryType getApplyQueryType() {
return applyQueryType != null ? applyQueryType : ApplyQueryType.NONE;
}
}

View file

@ -24,6 +24,8 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.ApplyQueryType;
import net.osmand.plus.settings.OnConfirmPreferenceChange;
import net.osmand.plus.settings.OnPreferenceChanged;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
@ -74,16 +76,25 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
@Override
public void onClick(View v) {
boolean newValue = !pref.getModeValue(getAppMode());
if (switchPreference.callChangeListener(newValue)) {
switchPreference.setChecked(newValue);
preferenceBtn[0].setTitle(newValue ? on : off);
preferenceBtn[0].setChecked(newValue);
preferenceBtn[0].setTitleColorId(newValue ? activeColor : disabledColor);
updateCustomButtonView(v, newValue);
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof OnConfirmPreferenceChange) {
ApplyQueryType applyQueryType = getApplyQueryType();
if (applyQueryType == ApplyQueryType.SNACK_BAR) {
applyQueryType = ApplyQueryType.NONE;
}
OnConfirmPreferenceChange confirmationInterface =
(OnConfirmPreferenceChange) targetFragment;
if (confirmationInterface.onConfirmPreferenceChange(
switchPreference.getKey(), newValue, applyQueryType)) {
switchPreference.setChecked(newValue);
preferenceBtn[0].setTitle(newValue ? on : off);
preferenceBtn[0].setChecked(newValue);
preferenceBtn[0].setTitleColorId(newValue ? activeColor : disabledColor);
updateCustomButtonView(v, newValue);
Fragment target = getTargetFragment();
if (target instanceof OnPreferenceChanged) {
((OnPreferenceChanged) target).onPreferenceChanged(switchPreference.getKey());
if (targetFragment instanceof OnPreferenceChanged) {
((OnPreferenceChanged) targetFragment).onPreferenceChanged(switchPreference.getKey());
}
}
}
}
@ -145,7 +156,8 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
}
public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target, boolean usedOnMap,
@Nullable ApplicationMode appMode, boolean profileDependent) {
@Nullable ApplicationMode appMode, ApplyQueryType applyQueryType,
boolean profileDependent) {
try {
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
Bundle args = new Bundle();
@ -155,6 +167,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap);
fragment.setAppMode(appMode);
fragment.setApplyQueryType(applyQueryType);
fragment.setTargetFragment(target, 0);
fragment.setProfileDependent(profileDependent);
fragment.show(fm, BooleanPreferenceBottomSheet.TAG);

View file

@ -27,8 +27,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitmeListDividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.ApplyQueryType;
import net.osmand.plus.settings.OnApplyPreference;
import net.osmand.plus.settings.OnPreferenceChanged;
import net.osmand.plus.settings.OnConfirmPreferenceChange;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import static net.osmand.plus.settings.RouteParametersFragment.DEFAULT_MODE;
@ -121,11 +120,8 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
updateCustomButtonView(v, enabled);
Fragment target = getTargetFragment();
float newValue = enabled ? DEFAULT_MODE : DISABLE_MODE;
if (target instanceof OnApplyPreference) {
((OnApplyPreference) target).onApplyPreference(switchPref.getKey(), newValue, ApplyQueryType.NONE);
}
if (target instanceof OnPreferenceChanged) {
((OnPreferenceChanged) target).onPreferenceChanged(switchPref.getKey());
if (target instanceof OnConfirmPreferenceChange) {
((OnConfirmPreferenceChange) target).onConfirmPreferenceChange(switchPref.getKey(), newValue, ApplyQueryType.NONE);
}
}
})
@ -157,11 +153,9 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
protected void onRightBottomButtonClick() {
if (enabled && sliderPositionChanged) {
Fragment target = getTargetFragment();
if (target instanceof OnApplyPreference) {
((OnApplyPreference) target).onApplyPreference(preference.getId(), currentValue, ApplyQueryType.SNACK_BAR);
}
if (target instanceof OnPreferenceChanged) {
((OnPreferenceChanged) target).onPreferenceChanged(preference.getId());
if (target instanceof OnConfirmPreferenceChange) {
((OnConfirmPreferenceChange) target).onConfirmPreferenceChange(
preference.getId(), currentValue, ApplyQueryType.SNACK_BAR);
}
}
dismiss();