From 5446ad43f8e26e9c2d0f261f83f5e61a303f5171 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Mon, 6 Apr 2020 17:05:31 +0300 Subject: [PATCH] Show SnackBar when preference change (fixes) --- .../osmand/plus/settings/ApplyQueryType.java | 5 ++ .../plus/settings/BaseSettingsFragment.java | 81 ++++++++++--------- .../GeneralProfileSettingsFragment.java | 4 +- .../settings/MapDuringNavigationFragment.java | 42 +++++++--- .../plus/settings/NavigationFragment.java | 11 ++- .../plus/settings/OnApplyPreference.java | 7 ++ .../settings/RouteParametersFragment.java | 46 +++++++---- .../plus/settings/ScreenAlertsFragment.java | 3 +- .../plus/settings/TurnScreenOnFragment.java | 3 +- .../plus/settings/VoiceAnnouncesFragment.java | 13 ++- ...ecalculateRouteInDeviationBottomSheet.java | 42 +++++----- 11 files changed, 157 insertions(+), 100 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/settings/ApplyQueryType.java create mode 100644 OsmAnd/src/net/osmand/plus/settings/OnApplyPreference.java diff --git a/OsmAnd/src/net/osmand/plus/settings/ApplyQueryType.java b/OsmAnd/src/net/osmand/plus/settings/ApplyQueryType.java new file mode 100644 index 0000000000..8100f0b0ce --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/ApplyQueryType.java @@ -0,0 +1,5 @@ +package net.osmand.plus.settings; + +public enum ApplyQueryType { + NONE, SNACK_BAR, BOTTOM_SHEET +} diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java index 07062d1326..de0bc9d390 100644 --- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java @@ -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 { + OnPreferenceClickListener, AppModeChangedListener, OnApplyPreference { private static final Log LOG = PlatformUtil.getLog(BaseSettingsFragment.class); @@ -113,44 +113,40 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl GLOBAL_SETTINGS(GlobalSettingsFragment.class.getName(), false, null, R.xml.global_settings, R.layout.global_preference_toolbar), CONFIGURE_PROFILE(ConfigureProfileFragment.class.getName(), true, null, R.xml.configure_profile, R.layout.profile_preference_toolbar_with_switch), PROXY_SETTINGS(ProxySettingsFragment.class.getName(), false, null, R.xml.proxy_preferences, R.layout.global_preferences_toolbar_with_switch), - GENERAL_PROFILE(GeneralProfileSettingsFragment.class.getName(), true, MessageType.BOTTOM_SHEET, R.xml.general_profile_settings, R.layout.profile_preference_toolbar), - NAVIGATION(NavigationFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar), - COORDINATES_FORMAT(CoordinatesFormatFragment.class.getName(), true, MessageType.BOTTOM_SHEET, R.xml.coordinates_format, R.layout.profile_preference_toolbar), - ROUTE_PARAMETERS(RouteParametersFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.route_parameters, R.layout.profile_preference_toolbar), - SCREEN_ALERTS(ScreenAlertsFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.screen_alerts, R.layout.profile_preference_toolbar_with_switch), - VOICE_ANNOUNCES(VoiceAnnouncesFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.voice_announces, R.layout.profile_preference_toolbar_with_switch), - VEHICLE_PARAMETERS(VehicleParametersFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.vehicle_parameters, R.layout.profile_preference_toolbar), - MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.map_during_navigation, R.layout.profile_preference_toolbar), - TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch), + GENERAL_PROFILE(GeneralProfileSettingsFragment.class.getName(), true, ApplyQueryType.BOTTOM_SHEET, R.xml.general_profile_settings, R.layout.profile_preference_toolbar), + NAVIGATION(NavigationFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar), + COORDINATES_FORMAT(CoordinatesFormatFragment.class.getName(), true, ApplyQueryType.BOTTOM_SHEET, R.xml.coordinates_format, R.layout.profile_preference_toolbar), + ROUTE_PARAMETERS(RouteParametersFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.route_parameters, R.layout.profile_preference_toolbar), + SCREEN_ALERTS(ScreenAlertsFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.screen_alerts, R.layout.profile_preference_toolbar_with_switch), + VOICE_ANNOUNCES(VoiceAnnouncesFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.voice_announces, R.layout.profile_preference_toolbar_with_switch), + VEHICLE_PARAMETERS(VehicleParametersFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.vehicle_parameters, R.layout.profile_preference_toolbar), + MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.map_during_navigation, R.layout.profile_preference_toolbar), + TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch), DATA_STORAGE(DataStorageFragment.class.getName(), false, null, R.xml.data_storage, R.layout.global_preference_toolbar), DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, null, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch), PROFILE_APPEARANCE(ProfileAppearanceFragment.TAG, true, null, R.xml.profile_appearance, R.layout.profile_preference_toolbar), OPEN_STREET_MAP_EDITING(OsmEditingFragment.class.getName(), false, null, R.xml.osm_editing, R.layout.global_preference_toolbar), - MULTIMEDIA_NOTES(MultimediaNotesFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.multimedia_notes, R.layout.profile_preference_toolbar), - MONITORING_SETTINGS(MonitoringSettingsFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.monitoring_settings, R.layout.profile_preference_toolbar), + MULTIMEDIA_NOTES(MultimediaNotesFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.multimedia_notes, R.layout.profile_preference_toolbar), + MONITORING_SETTINGS(MonitoringSettingsFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.monitoring_settings, R.layout.profile_preference_toolbar), LIVE_MONITORING(LiveMonitoringFragment.class.getName(), false, null, R.xml.live_monitoring, R.layout.global_preferences_toolbar_with_switch), - ACCESSIBILITY_SETTINGS(AccessibilitySettingsFragment.class.getName(), true, MessageType.SNACK_BAR, R.xml.accessibility_settings, R.layout.profile_preference_toolbar), + ACCESSIBILITY_SETTINGS(AccessibilitySettingsFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.accessibility_settings, R.layout.profile_preference_toolbar), DEVELOPMENT_SETTINGS(DevelopmentSettingsFragment.class.getName(), false, null, R.xml.development_settings, R.layout.global_preference_toolbar); public final String fragmentName; public final boolean profileDependent; - public final MessageType onChangeMessageType; + public final ApplyQueryType applyQueryType; public final int preferencesResId; public final int toolbarResId; - SettingsScreenType(String fragmentName, boolean profileDependent, MessageType onChangeMessageType, int preferencesResId, int toolbarResId) { + SettingsScreenType(String fragmentName, boolean profileDependent, ApplyQueryType applyQueryType, int preferencesResId, int toolbarResId) { this.fragmentName = fragmentName; this.profileDependent = profileDependent; - this.onChangeMessageType = onChangeMessageType; + this.applyQueryType = applyQueryType; this.preferencesResId = preferencesResId; this.toolbarResId = toolbarResId; } } - private enum MessageType { - SNACK_BAR, BOTTOM_SHEET - } - @Override public void onCreate(Bundle savedInstanceState) { app = requireMyApplication(); @@ -318,21 +314,26 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - MessageType messageType = getMessageType(); - if (messageType != null) { - String prefId = preference.getKey(); + return onApplyPreference(preference.getKey(), newValue, getApplyQueryType()); + } + + @Override + public boolean onApplyPreference(String prefId, Object newValue, ApplyQueryType applyQueryType) { + if (applyQueryType != null && newValue instanceof Serializable) { OsmandSettings.OsmandPreference pref = settings.getPreference(prefId); - if (pref instanceof CommonPreference && !((CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) { - FragmentManager fragmentManager = getFragmentManager(); - if (newValue instanceof Serializable) { - if (messageType == MessageType.SNACK_BAR) { - applyChangeAndSuggestApplyToAllProfiles(prefId, (Serializable) newValue); - } else if (messageType == MessageType.BOTTOM_SHEET && fragmentManager != null) { + if (pref instanceof CommonPreference) { + if (applyQueryType == ApplyQueryType.SNACK_BAR) { + applySettingWithSnackBar(prefId, (Serializable) newValue); + } else if (applyQueryType == ApplyQueryType.BOTTOM_SHEET) { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId, (Serializable) newValue, this, false, getSelectedAppMode()); } + } else if (applyQueryType == ApplyQueryType.NONE) { + onSettingApplied(prefId, newValue, false); } - return false; + return true; } } return true; @@ -347,8 +348,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl return currentScreenType != null && currentScreenType.profileDependent; } - public MessageType getMessageType() { - return currentScreenType != null ? currentScreenType.onChangeMessageType : null; + public ApplyQueryType getApplyQueryType() { + return currentScreenType != null ? currentScreenType.applyQueryType : null; } @Override @@ -605,6 +606,14 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl public void onSettingApplied(String prefId, boolean appliedToAllProfiles) { } + public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) { + if (appliedToAllProfiles) { + app.getSettings().setPreferenceForAllModes(prefId, newValue); + } else { + app.getSettings().setPreference(prefId, newValue, getSelectedAppMode()); + } + } + public void updateAllSettings() { PreferenceScreen screen = getPreferenceScreen(); if (screen != null) { @@ -895,9 +904,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } } - protected void applyChangeAndSuggestApplyToAllProfiles(final String prefId, final Serializable newValue) { - app.getSettings().setPreference(prefId, newValue, getSelectedAppMode()); - onSettingApplied(prefId, false); + protected void applySettingWithSnackBar(final String prefId, final Serializable newValue) { + onSettingApplied(prefId, newValue, false); updateSetting(prefId); View containerView = getView(); if (containerView != null) { @@ -908,8 +916,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl .setAction(R.string.apply_to_all_profiles, new View.OnClickListener() { @Override public void onClick(View view) { - app.getSettings().setPreferenceForAllModes(prefId, newValue); - onSettingApplied(prefId, true); + onSettingApplied(prefId, newValue, true); } }); snackbar.show(); diff --git a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java index 29e0736a56..17c72554a2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java @@ -354,8 +354,8 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String prefId = preference.getKey(); - if (prefId.equals(settings.ROTATE_MAP.getId()) && newValue instanceof Serializable) { - applyChangeAndSuggestApplyToAllProfiles(prefId, (Serializable) newValue); + if (settings.ROTATE_MAP.getId().equals(prefId)) { + onApplyPreference(prefId, newValue, ApplyQueryType.SNACK_BAR); return false; } return super.onPreferenceChange(preference, newValue); diff --git a/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java index 848229be3e..71cd3a577f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java @@ -102,18 +102,38 @@ public class MapDuringNavigationFragment extends BaseSettingsFragment { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals(settings.AUTO_ZOOM_MAP.getId())) { - if (newValue instanceof Integer) { - ApplicationMode selectedMode = getSelectedAppMode(); - int position = (int) newValue; - 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]); - } - return true; - } + onApplyPreference(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) { + 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]); + } + } 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]); + } + } + return; + } + } + super.onSettingApplied(prefId, newValue, appliedToAllProfiles); + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java index 6ab55132c1..8826e78ea2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java @@ -93,14 +93,13 @@ public class NavigationFragment extends BaseSettingsFragment { } @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - String key = preference.getKey(); - if (settings.VOICE_MUTE.getId().equals(key) && newValue instanceof Boolean) { - settings.VOICE_MUTE.setModeValue(getSelectedAppMode(), !(Boolean) newValue); + public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) { + if (settings.VOICE_MUTE.getId().equals(prefId) && newValue instanceof Boolean) { + super.onSettingApplied(prefId, !(Boolean) newValue, appliedToAllProfiles); updateMenu(); - return true; + return; } - return super.onPreferenceChange(preference, newValue); + super.onSettingApplied(prefId, newValue, appliedToAllProfiles); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/OnApplyPreference.java b/OsmAnd/src/net/osmand/plus/settings/OnApplyPreference.java new file mode 100644 index 0000000000..d8e36c0d2d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/OnApplyPreference.java @@ -0,0 +1,7 @@ +package net.osmand.plus.settings; + +public interface OnApplyPreference { + + boolean onApplyPreference(String prefId, Object newValue, ApplyQueryType applyQueryType); + +} diff --git a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java index ba0114f046..d346c6a4c2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java @@ -57,6 +57,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP private static final String ROUTE_PARAMETERS_INFO = "route_parameters_info"; private static final String ROUTE_PARAMETERS_IMAGE = "route_parameters_image"; private static final String RELIEF_SMOOTHNESS_FACTOR = "relief_smoothness_factor"; + private static final String ROUTING_SHORT_WAY = "prouting_short_way"; private static final String ROUTING_RECALC_DISTANCE= "routing_recalc_distance"; public static final float DISABLE_MODE = -1.0f; @@ -410,30 +411,45 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP } @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - String key = preference.getKey(); - - if ((RELIEF_SMOOTHNESS_FACTOR.equals(key) || DRIVING_STYLE.equals(key)) && newValue instanceof String) { + public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) { + if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) { ApplicationMode appMode = getSelectedAppMode(); String selectedParameterId = (String) newValue; - List routingParameters = DRIVING_STYLE.equals(key) ? drivingStyleParameters : reliefFactorParameters; + List routingParameters = DRIVING_STYLE.equals(prefId) ? drivingStyleParameters : reliefFactorParameters; for (RoutingParameter p : routingParameters) { String parameterId = p.getId(); SettingsNavigationActivity.setRoutingParameterSelected(settings, appMode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId)); } recalculateRoute(); - return true; - } else if ("prouting_short_way".equals(key) && newValue instanceof Boolean) { - return app.getSettings().FAST_ROUTE_MODE.setModeValue(getSelectedAppMode(), !(Boolean) newValue); - } else if (ROUTING_RECALC_DISTANCE.equals(key) && newValue instanceof Boolean) { - boolean enabled = (Boolean) newValue; - settings.ROUTE_RECALCULATION_DISTANCE.setModeValue(getSelectedAppMode(), - enabled ? DEFAULT_MODE : DISABLE_MODE); - settings.DISABLE_OFFROUTE_RECALC.setModeValue(getSelectedAppMode(), !enabled); + 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; + if (newValue instanceof Boolean) { + enabled = (boolean) newValue; + valueToSave = enabled ? DEFAULT_MODE : DISABLE_MODE; + } else if (newValue instanceof Float) { + 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()); + } updateRouteRecalcDistancePref(); + return; } - - return super.onPreferenceChange(preference, newValue); + super.onSettingApplied(prefId, newValue, appliedToAllProfiles); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java index ac693e8f44..c2d4a35d02 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java @@ -55,8 +55,7 @@ public class ScreenAlertsFragment extends BaseSettingsFragment { public void onClick(View view) { ApplicationMode selectedMode = getSelectedAppMode(); boolean checked = !settings.SHOW_ROUTING_ALARMS.getModeValue(selectedMode); - settings.SHOW_ROUTING_ALARMS.setModeValue(selectedMode, checked); - applyChangeAndSuggestApplyToAllProfiles(settings.SHOW_ROUTING_ALARMS.getId(), checked); + onApplyPreference(settings.SHOW_ROUTING_ALARMS.getId(), checked, ApplyQueryType.SNACK_BAR); updateToolbarSwitch(); enableDisablePreferences(checked); } diff --git a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java index f402402f87..884d7bbdd0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java @@ -43,8 +43,7 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { public void onClick(View view) { ApplicationMode selectedMode = getSelectedAppMode(); boolean checked = !settings.TURN_SCREEN_ON_ENABLED.getModeValue(selectedMode); - settings.TURN_SCREEN_ON_ENABLED.setModeValue(selectedMode, checked); - applyChangeAndSuggestApplyToAllProfiles(settings.TURN_SCREEN_ON_ENABLED.getId(), checked); + onApplyPreference(settings.TURN_SCREEN_ON_ENABLED.getId(), checked, ApplyQueryType.SNACK_BAR); updateToolbarSwitch(); enableDisablePreferences(checked); } diff --git a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java index e87f8e73c1..4a8b1eb323 100644 --- a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java @@ -50,8 +50,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { public void onClick(View view) { ApplicationMode selectedMode = getSelectedAppMode(); boolean checked = !settings.VOICE_MUTE.getModeValue(selectedMode); - settings.VOICE_MUTE.setModeValue(selectedMode, checked); - applyChangeAndSuggestApplyToAllProfiles(settings.VOICE_MUTE.getId(), checked); + onApplyPreference(settings.VOICE_MUTE.getId(), checked, ApplyQueryType.SNACK_BAR); updateToolbarSwitch(); enableDisablePreferences(!checked); updateMenu(); @@ -220,7 +219,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { @Override public void onClick(DialogInterface dialog, int which) { - settings.SPEAK_SPEED_CAMERA.setModeValue(getSelectedAppMode(), true); + onApplyPreference(settings.SPEAK_SPEED_CAMERA.getId(), true, ApplyQueryType.SNACK_BAR); SwitchPreferenceCompat speakSpeedCamera = (SwitchPreferenceCompat) findPreference(settings.SPEAK_SPEED_CAMERA.getId()); if (speakSpeedCamera != null) { speakSpeedCamera.setChecked(true); @@ -269,11 +268,11 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { return false; } else if (newValue instanceof String) { if (VOICE_PROVIDER_NOT_USE.equals(newValue)) { - settings.VOICE_MUTE.setModeValue(selectedMode, true); + onApplyPreference(settings.VOICE_MUTE.getId(), true, ApplyQueryType.SNACK_BAR); updateToolbar(); - setupPreferences(); +// setupPreferences(); //TODO doesn't need anymore } - settings.VOICE_PROVIDER.setModeValue(selectedMode, (String) newValue); + onApplyPreference(settings.VOICE_PROVIDER.getId(), newValue, ApplyQueryType.SNACK_BAR); app.initVoiceCommandPlayer(getActivity(), selectedMode, false, null, true, false, false); } return true; @@ -283,7 +282,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { confirmSpeedCamerasDlg(); return false; } else { - return true; + return onApplyPreference(settings.SPEAK_SPEED_CAMERA.getId(), false, ApplyQueryType.SNACK_BAR); } } if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) { diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/RecalculateRouteInDeviationBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/RecalculateRouteInDeviationBottomSheet.java index 3bc0afc256..d7be43df22 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/RecalculateRouteInDeviationBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/RecalculateRouteInDeviationBottomSheet.java @@ -26,6 +26,8 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; 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.preferences.SwitchPreferenceEx; @@ -109,19 +111,21 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot @Override public void onClick(View v) { enabled = !enabled; - if (switchPref.callChangeListener(enabled)) { - sliderPositionChanged = false; - switchPref.setChecked(enabled); - preferenceBtn[0].setTitle(enabled ? on : off); - preferenceBtn[0].setTitleColorId(enabled ? activeColor : disabledColor); - preferenceBtn[0].setChecked(enabled); - getDefaultValue(); - updateSliderView(); - updateCustomButtonView(v, enabled); - Fragment target = getTargetFragment(); - if (target instanceof OnPreferenceChanged) { - ((OnPreferenceChanged) target).onPreferenceChanged(switchPref.getKey()); - } + sliderPositionChanged = false; + switchPref.setChecked(enabled); + preferenceBtn[0].setTitle(enabled ? on : off); + preferenceBtn[0].setTitleColorId(enabled ? activeColor : disabledColor); + preferenceBtn[0].setChecked(enabled); + getDefaultValue(); + updateSliderView(); + 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()); } } }) @@ -152,11 +156,13 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot @Override protected void onRightBottomButtonClick() { if (enabled && sliderPositionChanged) { - preference.setModeValue(getAppMode(), currentValue); - } - Fragment target = getTargetFragment(); - if (target instanceof OnPreferenceChanged) { - ((OnPreferenceChanged) target).onPreferenceChanged(preference.getId()); + 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()); + } } dismiss(); }