Merge pull request #8770 from osmandapp/PreferenceChangeSnackBar
Show SnackBar when preference change (fixes)
This commit is contained in:
commit
08f624161c
17 changed files with 284 additions and 195 deletions
|
@ -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;
|
||||
|
|
|
@ -21,7 +21,6 @@ import net.osmand.plus.myplaces.FavoritesActivity;
|
|||
import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet;
|
||||
import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet.CopyAppModePrefsListener;
|
||||
import net.osmand.plus.settings.BaseSettingsFragment;
|
||||
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
|
||||
import net.osmand.plus.settings.bottomsheets.ResetProfilePrefsBottomSheet;
|
||||
import net.osmand.plus.settings.bottomsheets.ResetProfilePrefsBottomSheet.ResetAppModePrefsListener;
|
||||
import net.osmand.plus.settings.bottomsheets.SingleSelectPreferenceBottomSheet;
|
||||
|
@ -29,7 +28,6 @@ import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
|||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
|
@ -288,25 +286,19 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String prefId = preference.getKey();
|
||||
|
||||
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
|
||||
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||
if (SAVE_GLOBAL_TRACK_INTERVAL.equals(prefId)) {
|
||||
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
|
||||
if (newValue instanceof Boolean) {
|
||||
prefId = settings.SAVE_GLOBAL_TRACK_REMEMBER.getId();
|
||||
newValue = Boolean.FALSE;
|
||||
}
|
||||
if (pref instanceof OsmandSettings.CommonPreference && !((OsmandSettings.CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (fragmentManager != null && newValue instanceof Serializable) {
|
||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
|
||||
(Serializable) newValue, this, false, getSelectedAppMode());
|
||||
}
|
||||
return false;
|
||||
applyPreference(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), applyToAllProfiles, false);
|
||||
} else if (pref instanceof OsmandSettings.CommonPreference
|
||||
&& !((OsmandSettings.CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
|
||||
applyPreference(SAVE_GLOBAL_TRACK_INTERVAL, applyToAllProfiles, newValue);
|
||||
applyPreference(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), applyToAllProfiles, true);
|
||||
}
|
||||
} else {
|
||||
super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue);
|
||||
}
|
||||
return super.onPreferenceChange(preference, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -343,16 +335,4 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment
|
|||
updateAllSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSettingApplied(String prefId, boolean appliedToAllProfiles) {
|
||||
if (settings.SAVE_GLOBAL_TRACK_INTERVAL.getId().equals(prefId)) {
|
||||
if (appliedToAllProfiles) {
|
||||
app.getSettings().setPreferenceForAllModes(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), true);
|
||||
} else {
|
||||
app.getSettings().setPreference(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), true, getSelectedAppMode());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
5
OsmAnd/src/net/osmand/plus/settings/ApplyQueryType.java
Normal file
5
OsmAnd/src/net/osmand/plus/settings/ApplyQueryType.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
public enum ApplyQueryType {
|
||||
NONE, SNACK_BAR, BOTTOM_SHEET
|
||||
}
|
|
@ -47,6 +47,7 @@ import androidx.preference.TwoStatePreference;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
|
@ -79,11 +80,12 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
|||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
|
||||
|
||||
public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener,
|
||||
OnPreferenceClickListener, AppModeChangedListener {
|
||||
OnPreferenceClickListener, AppModeChangedListener, OnConfirmPreferenceChange {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(BaseSettingsFragment.class);
|
||||
|
||||
|
@ -113,44 +115,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),
|
||||
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),
|
||||
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, ApplyQueryType.SNACK_BAR, R.xml.live_monitoring, R.layout.global_preferences_toolbar_with_switch),
|
||||
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 +316,25 @@ 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();
|
||||
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
|
||||
if (pref instanceof CommonPreference && !((CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
|
||||
return onConfirmPreferenceChange(preference.getKey(), newValue, getApplyQueryType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean onConfirmPreferenceChange(String prefId, Object newValue, ApplyQueryType applyQueryType) {
|
||||
if (applyQueryType != null && newValue instanceof Serializable) {
|
||||
if (applyQueryType == ApplyQueryType.SNACK_BAR) {
|
||||
applyPreferenceWithSnackBar(prefId, (Serializable) newValue);
|
||||
return true;
|
||||
} else if (applyQueryType == ApplyQueryType.BOTTOM_SHEET) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (newValue instanceof Serializable) {
|
||||
if (messageType == MessageType.SNACK_BAR) {
|
||||
applyChangeAndSuggestApplyToAllProfiles(prefId, (Serializable) newValue);
|
||||
} else if (messageType == MessageType.BOTTOM_SHEET && fragmentManager != null) {
|
||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
|
||||
(Serializable) newValue, this, false, getSelectedAppMode());
|
||||
}
|
||||
if (fragmentManager != null) {
|
||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
|
||||
(Serializable) newValue, this, false, getSelectedAppMode());
|
||||
}
|
||||
return false;
|
||||
} else if (applyQueryType == ApplyQueryType.NONE) {
|
||||
onApplyPreferenceChange(prefId, false, newValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -347,8 +349,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
|
||||
|
@ -362,7 +364,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) {
|
||||
|
@ -602,7 +604,34 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
updateAllSettings();
|
||||
}
|
||||
|
||||
public void onSettingApplied(String prefId, boolean appliedToAllProfiles) {
|
||||
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||
if (settings.getPreference(prefId) instanceof CommonPreference) {
|
||||
applyPreference(prefId, applyToAllProfiles, newValue);
|
||||
} else {
|
||||
Preference pref = findPreference(prefId);
|
||||
if (pref != null) {
|
||||
applyPreference(pref, applyToAllProfiles, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final void applyPreference(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||
if (applyToAllProfiles) {
|
||||
app.getSettings().setPreferenceForAllModes(prefId, newValue);
|
||||
} else {
|
||||
app.getSettings().setPreference(prefId, newValue, getSelectedAppMode());
|
||||
}
|
||||
}
|
||||
|
||||
protected final void applyPreference(Preference pref, boolean applyToAllProfiles, Object newValue) {
|
||||
if (pref instanceof MultiSelectBooleanPreference) {
|
||||
MultiSelectBooleanPreference msp = (MultiSelectBooleanPreference) pref;
|
||||
Set<String> values = (Set<String>) newValue;
|
||||
String[] ids = msp.getPrefsIds();
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
applyPreference(ids[i], applyToAllProfiles, values.contains(ids[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAllSettings() {
|
||||
|
@ -895,9 +924,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 applyPreferenceWithSnackBar(final String prefId, final Serializable newValue) {
|
||||
onApplyPreferenceChange(prefId, false, newValue);
|
||||
updateSetting(prefId);
|
||||
View containerView = getView();
|
||||
if (containerView != null) {
|
||||
|
@ -908,10 +936,13 @@ 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);
|
||||
onApplyPreferenceChange(prefId, true, newValue);
|
||||
}
|
||||
});
|
||||
UiUtilities.setupSnackbarVerticalLayout(snackbar);
|
||||
try {
|
||||
snackbar.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE);
|
||||
} catch (Throwable e) { }
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -323,18 +319,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
|
|||
b.setAdapter(singleChoiceAdapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ApplicationMode selectedMode = getSelectedAppMode();
|
||||
if (drs.get(which) == null) {
|
||||
settings.DRIVING_REGION_AUTOMATIC.setModeValue(selectedMode, true);
|
||||
MapViewTrackingUtilities mapViewTrackingUtilities = getMyApplication().getMapViewTrackingUtilities();
|
||||
if (mapViewTrackingUtilities != null) {
|
||||
mapViewTrackingUtilities.resetDrivingRegionUpdate();
|
||||
}
|
||||
} else {
|
||||
settings.DRIVING_REGION_AUTOMATIC.setModeValue(selectedMode, false);
|
||||
settings.DRIVING_REGION.setModeValue(selectedMode, drs.get(which));
|
||||
}
|
||||
updateAllSettings();
|
||||
onConfirmPreferenceChange(settings.DRIVING_REGION.getId(), drs.get(which), ApplyQueryType.BOTTOM_SHEET);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -342,6 +327,32 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
|
|||
b.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||
if (settings.DRIVING_REGION.getId().equals(prefId)) {
|
||||
ApplicationMode selectedMode = getSelectedAppMode();
|
||||
if (newValue == null) {
|
||||
applyPreference(settings.DRIVING_REGION_AUTOMATIC.getId(), applyToAllProfiles, true);
|
||||
MapViewTrackingUtilities mapViewTrackingUtilities = requireMyApplication().getMapViewTrackingUtilities();
|
||||
if (mapViewTrackingUtilities != null) {
|
||||
mapViewTrackingUtilities.resetDrivingRegionUpdate();
|
||||
}
|
||||
} else if (newValue instanceof OsmandSettings.DrivingRegion) {
|
||||
applyPreference(settings.DRIVING_REGION_AUTOMATIC.getId(), applyToAllProfiles, false);
|
||||
if (applyToAllProfiles) {
|
||||
for (ApplicationMode appMode : ApplicationMode.allPossibleValues()) {
|
||||
settings.DRIVING_REGION.setModeValue(appMode, (OsmandSettings.DrivingRegion) newValue);
|
||||
}
|
||||
} else {
|
||||
settings.DRIVING_REGION.setModeValue(selectedMode, (OsmandSettings.DrivingRegion) newValue);
|
||||
}
|
||||
}
|
||||
updateAllSettings();
|
||||
} else {
|
||||
applyPreference(prefId, applyToAllProfiles, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference.getKey().equals(settings.DRIVING_REGION.getId())) {
|
||||
|
@ -354,8 +365,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)) {
|
||||
onConfirmPreferenceChange(prefId, newValue, ApplyQueryType.SNACK_BAR);
|
||||
return false;
|
||||
}
|
||||
return super.onPreferenceChange(preference, newValue);
|
||||
|
|
|
@ -49,7 +49,7 @@ public class LiveMonitoringFragment extends BaseSettingsFragment {
|
|||
public void onClick(View view) {
|
||||
ApplicationMode appMode = getSelectedAppMode();
|
||||
boolean checked = !settings.LIVE_MONITORING.getModeValue(appMode);
|
||||
settings.LIVE_MONITORING.setModeValue(appMode, checked);
|
||||
onConfirmPreferenceChange(settings.LIVE_MONITORING.getId(), checked, ApplyQueryType.SNACK_BAR);
|
||||
updateToolbarSwitch();
|
||||
enableDisablePreferences(checked);
|
||||
}
|
||||
|
@ -142,21 +142,4 @@ public class LiveMonitoringFragment extends BaseSettingsFragment {
|
|||
liveMonitoringBuffer.setIcon(getPersistentPrefIcon(R.drawable.ic_action_time_span));
|
||||
liveMonitoringBuffer.setDescription(R.string.live_monitoring_max_interval_to_send_desrc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String prefId = preference.getKey();
|
||||
|
||||
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
|
||||
if (pref instanceof OsmandSettings.CommonPreference && !((OsmandSettings.CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (fragmentManager != null && newValue instanceof Serializable) {
|
||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
|
||||
(Serializable) newValue, this, false, getSelectedAppMode());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -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,18 +101,27 @@ 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;
|
||||
}
|
||||
onConfirmPreferenceChange(settings.AUTO_ZOOM_MAP.getId(), newValue, ApplyQueryType.SNACK_BAR);
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceChange(preference, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||
if (settings.AUTO_ZOOM_MAP.getId().equals(prefId)) {
|
||||
if (newValue instanceof Integer) {
|
||||
int position = (int) newValue;
|
||||
if (position == 0) {
|
||||
applyPreference(settings.AUTO_ZOOM_MAP.getId(), applyToAllProfiles, false);
|
||||
} else {
|
||||
applyPreference(settings.AUTO_ZOOM_MAP.getId(), applyToAllProfiles, true);
|
||||
applyPreference(settings.AUTO_ZOOM_MAP_SCALE.getId(),
|
||||
applyToAllProfiles, OsmandSettings.AutoZoomMap.values()[position - 1]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,14 +92,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 onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||
if (settings.VOICE_MUTE.getId().equals(prefId) && newValue instanceof Boolean) {
|
||||
applyPreference(prefId, applyToAllProfiles, !(Boolean) newValue);
|
||||
updateMenu();
|
||||
return true;
|
||||
} else {
|
||||
applyPreference(prefId, applyToAllProfiles, newValue);
|
||||
}
|
||||
return super.onPreferenceChange(preference, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
public interface OnConfirmPreferenceChange {
|
||||
|
||||
boolean onConfirmPreferenceChange(String prefId, Object newValue, ApplyQueryType applyQueryType);
|
||||
|
||||
}
|
|
@ -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,38 +411,40 @@ 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 onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||
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(key) ? drivingStyleParameters : reliefFactorParameters;
|
||||
List<RoutingParameter> 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);
|
||||
} else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) {
|
||||
applyPreference(settings.FAST_ROUTE_MODE.getId(), applyToAllProfiles, !(Boolean) newValue);
|
||||
} 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;
|
||||
}
|
||||
applyPreference(ROUTING_RECALC_DISTANCE, applyToAllProfiles, valueToSave);
|
||||
applyPreference(settings.DISABLE_OFFROUTE_RECALC.getId(), applyToAllProfiles, !enabled);
|
||||
updateRouteRecalcDistancePref();
|
||||
} else {
|
||||
super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue);
|
||||
}
|
||||
|
||||
return super.onPreferenceChange(preference, newValue);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,8 +55,8 @@ 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);
|
||||
onConfirmPreferenceChange(
|
||||
settings.SHOW_ROUTING_ALARMS.getId(), checked, ApplyQueryType.SNACK_BAR);
|
||||
updateToolbarSwitch();
|
||||
enableDisablePreferences(checked);
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ 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);
|
||||
onConfirmPreferenceChange(
|
||||
settings.TURN_SCREEN_ON_ENABLED.getId(), checked, ApplyQueryType.SNACK_BAR);
|
||||
updateToolbarSwitch();
|
||||
enableDisablePreferences(checked);
|
||||
}
|
||||
|
|
|
@ -50,8 +50,8 @@ 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);
|
||||
onConfirmPreferenceChange(
|
||||
settings.VOICE_MUTE.getId(), checked, ApplyQueryType.SNACK_BAR);
|
||||
updateToolbarSwitch();
|
||||
enableDisablePreferences(!checked);
|
||||
updateMenu();
|
||||
|
@ -220,7 +220,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
|||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
settings.SPEAK_SPEED_CAMERA.setModeValue(getSelectedAppMode(), true);
|
||||
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);
|
||||
|
@ -268,13 +269,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
|||
startActivity(intent);
|
||||
return false;
|
||||
} else if (newValue instanceof String) {
|
||||
if (VOICE_PROVIDER_NOT_USE.equals(newValue)) {
|
||||
settings.VOICE_MUTE.setModeValue(selectedMode, true);
|
||||
updateToolbar();
|
||||
setupPreferences();
|
||||
}
|
||||
settings.VOICE_PROVIDER.setModeValue(selectedMode, (String) newValue);
|
||||
app.initVoiceCommandPlayer(getActivity(), selectedMode, false, null, true, false, false);
|
||||
onConfirmPreferenceChange(settings.VOICE_PROVIDER.getId(), newValue, ApplyQueryType.SNACK_BAR);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -283,10 +278,29 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
|||
confirmSpeedCamerasDlg();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
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 applyToAllProfiles, Object newValue) {
|
||||
if (prefId.equals(settings.VOICE_PROVIDER.getId()) && newValue instanceof String) {
|
||||
if (VOICE_PROVIDER_NOT_USE.equals(newValue)) {
|
||||
applyPreference(settings.VOICE_MUTE.getId(), applyToAllProfiles, true);
|
||||
updateToolbar();
|
||||
}
|
||||
applyPreference(settings.VOICE_PROVIDER.getId(), applyToAllProfiles, newValue);
|
||||
app.initVoiceCommandPlayer(getActivity(), getSelectedAppMode(),
|
||||
false, null, true, false, applyToAllProfiles);
|
||||
} 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) {
|
||||
|
@ -295,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, applyToAllProfiles, newValue);
|
||||
}
|
||||
|
||||
return super.onPreferenceChange(preference, newValue);
|
||||
}
|
||||
}
|
|
@ -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,8 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
|
|||
if (appMode != null) {
|
||||
outState.putString(APP_MODE_KEY, appMode.getStringKey());
|
||||
}
|
||||
outState.putString(APPLY_QUERY_TYPE, applyQueryType != null ?
|
||||
applyQueryType.name() : ApplyQueryType.NONE.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,4 +113,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -55,7 +55,6 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
app.getSettings().setPreferenceForAllModes(prefId, newValue);
|
||||
updateTargetSettings(false, true);
|
||||
dismiss();
|
||||
}
|
||||
|
@ -72,7 +71,6 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
app.getSettings().setPreference(prefId, newValue, getAppMode());
|
||||
updateTargetSettings(false, false);
|
||||
dismiss();
|
||||
}
|
||||
|
@ -106,11 +104,11 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
outState.putSerializable(NEW_VALUE_KEY, newValue);
|
||||
}
|
||||
|
||||
private void updateTargetSettings(boolean discard, boolean appliedToAllProfiles) {
|
||||
private void updateTargetSettings(boolean discard, boolean applyToAllProfiles) {
|
||||
BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment();
|
||||
if (target != null) {
|
||||
if (!discard) {
|
||||
target.onSettingApplied(getPrefId(), appliedToAllProfiles);
|
||||
target.onApplyPreferenceChange(getPrefId(), applyToAllProfiles, newValue);
|
||||
}
|
||||
target.updateSetting(getPrefId());
|
||||
if (!discard) {
|
||||
|
|
|
@ -26,7 +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.OnPreferenceChanged;
|
||||
import net.osmand.plus.settings.ApplyQueryType;
|
||||
import net.osmand.plus.settings.OnConfirmPreferenceChange;
|
||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||
|
||||
import static net.osmand.plus.settings.RouteParametersFragment.DEFAULT_MODE;
|
||||
|
@ -109,19 +110,18 @@ 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 OnConfirmPreferenceChange) {
|
||||
((OnConfirmPreferenceChange) target).onConfirmPreferenceChange(switchPref.getKey(), newValue, ApplyQueryType.NONE);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -152,11 +152,11 @@ 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 OnConfirmPreferenceChange) {
|
||||
((OnConfirmPreferenceChange) target).onConfirmPreferenceChange(
|
||||
preference.getId(), currentValue, ApplyQueryType.SNACK_BAR);
|
||||
}
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue