Show SnackBar when preference change p.4
This commit is contained in:
parent
ba7d1fa7e7
commit
b7e42c1646
8 changed files with 47 additions and 67 deletions
|
@ -21,7 +21,6 @@ import net.osmand.plus.myplaces.FavoritesActivity;
|
||||||
import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet;
|
import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet;
|
||||||
import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet.CopyAppModePrefsListener;
|
import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet.CopyAppModePrefsListener;
|
||||||
import net.osmand.plus.settings.BaseSettingsFragment;
|
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;
|
||||||
import net.osmand.plus.settings.bottomsheets.ResetProfilePrefsBottomSheet.ResetAppModePrefsListener;
|
import net.osmand.plus.settings.bottomsheets.ResetProfilePrefsBottomSheet.ResetAppModePrefsListener;
|
||||||
import net.osmand.plus.settings.bottomsheets.SingleSelectPreferenceBottomSheet;
|
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.settings.preferences.SwitchPreferenceEx;
|
||||||
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
@ -288,25 +286,19 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||||
String prefId = preference.getKey();
|
|
||||||
|
|
||||||
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
|
|
||||||
if (SAVE_GLOBAL_TRACK_INTERVAL.equals(prefId)) {
|
if (SAVE_GLOBAL_TRACK_INTERVAL.equals(prefId)) {
|
||||||
|
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
|
||||||
if (newValue instanceof Boolean) {
|
if (newValue instanceof Boolean) {
|
||||||
prefId = settings.SAVE_GLOBAL_TRACK_REMEMBER.getId();
|
applyPreference(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), applyToAllProfiles, false);
|
||||||
newValue = Boolean.FALSE;
|
} else if (pref instanceof OsmandSettings.CommonPreference
|
||||||
}
|
&& !((OsmandSettings.CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
|
||||||
if (pref instanceof OsmandSettings.CommonPreference && !((OsmandSettings.CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
|
applyPreference(SAVE_GLOBAL_TRACK_INTERVAL, applyToAllProfiles, newValue);
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
applyPreference(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), applyToAllProfiles, true);
|
||||||
if (fragmentManager != null && newValue instanceof Serializable) {
|
|
||||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
|
|
||||||
(Serializable) newValue, this, false, getSelectedAppMode());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
return super.onPreferenceChange(preference, newValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -343,16 +335,4 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment
|
||||||
updateAllSettings();
|
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -47,6 +47,7 @@ import androidx.preference.TwoStatePreference;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
|
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
@ -318,7 +319,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onConfirmPreferenceChange(String prefId, Object newValue, ApplyQueryType applyQueryType) {
|
public final boolean onConfirmPreferenceChange(String prefId, Object newValue, ApplyQueryType applyQueryType) {
|
||||||
if (applyQueryType != null && newValue instanceof Serializable) {
|
if (applyQueryType != null && newValue instanceof Serializable) {
|
||||||
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
|
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
|
||||||
if (pref instanceof CommonPreference) {
|
if (pref instanceof CommonPreference) {
|
||||||
|
@ -605,11 +606,12 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
updateAllSettings();
|
updateAllSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSettingApplied(String prefId, boolean appliedToAllProfiles) {
|
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||||
|
applyPreference(prefId, applyToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
protected final void applyPreference(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||||
if (appliedToAllProfiles) {
|
if (applyToAllProfiles) {
|
||||||
app.getSettings().setPreferenceForAllModes(prefId, newValue);
|
app.getSettings().setPreferenceForAllModes(prefId, newValue);
|
||||||
} else {
|
} else {
|
||||||
app.getSettings().setPreference(prefId, newValue, getSelectedAppMode());
|
app.getSettings().setPreference(prefId, newValue, getSelectedAppMode());
|
||||||
|
@ -922,6 +924,11 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
UiUtilities.setupSnackbarVerticalLayout(snackbar);
|
UiUtilities.setupSnackbarVerticalLayout(snackbar);
|
||||||
|
try {
|
||||||
|
snackbar.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
|
||||||
|
}
|
||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,18 +328,18 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||||
if (settings.DRIVING_REGION.getId().equals(prefId)) {
|
if (settings.DRIVING_REGION.getId().equals(prefId)) {
|
||||||
ApplicationMode selectedMode = getSelectedAppMode();
|
ApplicationMode selectedMode = getSelectedAppMode();
|
||||||
if (newValue == null) {
|
if (newValue == null) {
|
||||||
super.onApplyPreferenceChange(settings.DRIVING_REGION_AUTOMATIC.getId(), appliedToAllProfiles, true);
|
applyPreference(settings.DRIVING_REGION_AUTOMATIC.getId(), applyToAllProfiles, true);
|
||||||
MapViewTrackingUtilities mapViewTrackingUtilities = getMyApplication().getMapViewTrackingUtilities();
|
MapViewTrackingUtilities mapViewTrackingUtilities = requireMyApplication().getMapViewTrackingUtilities();
|
||||||
if (mapViewTrackingUtilities != null) {
|
if (mapViewTrackingUtilities != null) {
|
||||||
mapViewTrackingUtilities.resetDrivingRegionUpdate();
|
mapViewTrackingUtilities.resetDrivingRegionUpdate();
|
||||||
}
|
}
|
||||||
} else if (newValue instanceof OsmandSettings.DrivingRegion) {
|
} else if (newValue instanceof OsmandSettings.DrivingRegion) {
|
||||||
super.onApplyPreferenceChange(settings.DRIVING_REGION_AUTOMATIC.getId(), appliedToAllProfiles, false);
|
applyPreference(settings.DRIVING_REGION_AUTOMATIC.getId(), applyToAllProfiles, false);
|
||||||
if (appliedToAllProfiles) {
|
if (applyToAllProfiles) {
|
||||||
for (ApplicationMode appMode : ApplicationMode.allPossibleValues()) {
|
for (ApplicationMode appMode : ApplicationMode.allPossibleValues()) {
|
||||||
settings.DRIVING_REGION.setModeValue(appMode, (OsmandSettings.DrivingRegion) newValue);
|
settings.DRIVING_REGION.setModeValue(appMode, (OsmandSettings.DrivingRegion) newValue);
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
|
||||||
}
|
}
|
||||||
updateAllSettings();
|
updateAllSettings();
|
||||||
} else {
|
} else {
|
||||||
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
|
applyPreference(prefId, applyToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,20 +108,20 @@ public class MapDuringNavigationFragment extends BaseSettingsFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||||
if (settings.AUTO_ZOOM_MAP.getId().equals(prefId)) {
|
if (settings.AUTO_ZOOM_MAP.getId().equals(prefId)) {
|
||||||
if (newValue instanceof Integer) {
|
if (newValue instanceof Integer) {
|
||||||
int position = (int) newValue;
|
int position = (int) newValue;
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
super.onApplyPreferenceChange(settings.AUTO_ZOOM_MAP.getId(), appliedToAllProfiles, false);
|
applyPreference(settings.AUTO_ZOOM_MAP.getId(), applyToAllProfiles, false);
|
||||||
} else {
|
} else {
|
||||||
super.onApplyPreferenceChange(settings.AUTO_ZOOM_MAP.getId(), appliedToAllProfiles, true);
|
applyPreference(settings.AUTO_ZOOM_MAP.getId(), applyToAllProfiles, true);
|
||||||
super.onApplyPreferenceChange(settings.AUTO_ZOOM_MAP_SCALE.getId(),
|
applyPreference(settings.AUTO_ZOOM_MAP_SCALE.getId(),
|
||||||
appliedToAllProfiles, OsmandSettings.AutoZoomMap.values()[position - 1]);
|
applyToAllProfiles, OsmandSettings.AutoZoomMap.values()[position - 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
|
super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -92,12 +92,12 @@ public class NavigationFragment extends BaseSettingsFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||||
if (settings.VOICE_MUTE.getId().equals(prefId) && newValue instanceof Boolean) {
|
if (settings.VOICE_MUTE.getId().equals(prefId) && newValue instanceof Boolean) {
|
||||||
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, !(Boolean) newValue);
|
applyPreference(prefId, applyToAllProfiles, !(Boolean) newValue);
|
||||||
updateMenu();
|
updateMenu();
|
||||||
} else {
|
} else {
|
||||||
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
|
applyPreference(prefId, applyToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -411,7 +411,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||||
if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) {
|
if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) {
|
||||||
ApplicationMode appMode = getSelectedAppMode();
|
ApplicationMode appMode = getSelectedAppMode();
|
||||||
String selectedParameterId = (String) newValue;
|
String selectedParameterId = (String) newValue;
|
||||||
|
@ -422,11 +422,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
}
|
}
|
||||||
recalculateRoute();
|
recalculateRoute();
|
||||||
} else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) {
|
} else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) {
|
||||||
if (appliedToAllProfiles) {
|
applyPreference(settings.FAST_ROUTE_MODE.getId(), applyToAllProfiles, !(Boolean) newValue);
|
||||||
settings.setPreferenceForAllModes(settings.FAST_ROUTE_MODE.getId(), !(Boolean) newValue);
|
|
||||||
} else {
|
|
||||||
settings.setPreference(settings.FAST_ROUTE_MODE.getId(), !(Boolean) newValue, getSelectedAppMode());
|
|
||||||
}
|
|
||||||
} else if (ROUTING_RECALC_DISTANCE.equals(prefId)) {
|
} else if (ROUTING_RECALC_DISTANCE.equals(prefId)) {
|
||||||
boolean enabled = false;
|
boolean enabled = false;
|
||||||
float valueToSave = DISABLE_MODE;
|
float valueToSave = DISABLE_MODE;
|
||||||
|
@ -437,11 +433,11 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
valueToSave = (float) newValue;
|
valueToSave = (float) newValue;
|
||||||
enabled = valueToSave != DISABLE_MODE;
|
enabled = valueToSave != DISABLE_MODE;
|
||||||
}
|
}
|
||||||
super.onApplyPreferenceChange(ROUTING_RECALC_DISTANCE, appliedToAllProfiles, valueToSave);
|
applyPreference(ROUTING_RECALC_DISTANCE, applyToAllProfiles, valueToSave);
|
||||||
super.onApplyPreferenceChange(settings.DISABLE_OFFROUTE_RECALC.getId(), appliedToAllProfiles, !enabled);
|
applyPreference(settings.DISABLE_OFFROUTE_RECALC.getId(), applyToAllProfiles, !enabled);
|
||||||
updateRouteRecalcDistancePref();
|
updateRouteRecalcDistancePref();
|
||||||
} else {
|
} else {
|
||||||
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
|
super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,15 +291,15 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||||
if (prefId.equals(settings.VOICE_PROVIDER.getId()) && newValue instanceof String) {
|
if (prefId.equals(settings.VOICE_PROVIDER.getId()) && newValue instanceof String) {
|
||||||
if (VOICE_PROVIDER_NOT_USE.equals(newValue)) {
|
if (VOICE_PROVIDER_NOT_USE.equals(newValue)) {
|
||||||
super.onApplyPreferenceChange(settings.VOICE_MUTE.getId(), appliedToAllProfiles, true);
|
applyPreference(settings.VOICE_MUTE.getId(), applyToAllProfiles, true);
|
||||||
updateToolbar();
|
updateToolbar();
|
||||||
}
|
}
|
||||||
super.onApplyPreferenceChange(settings.VOICE_PROVIDER.getId(), appliedToAllProfiles, newValue);
|
applyPreference(settings.VOICE_PROVIDER.getId(), applyToAllProfiles, newValue);
|
||||||
app.initVoiceCommandPlayer(getActivity(), getSelectedAppMode(),
|
app.initVoiceCommandPlayer(getActivity(), getSelectedAppMode(),
|
||||||
false, null, true, false, appliedToAllProfiles);
|
false, null, true, false, applyToAllProfiles);
|
||||||
} else if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) {
|
} 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
|
// Sync DEFAULT value with CAR value, as we have other way to set it for now
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
}
|
}
|
||||||
settings.AUDIO_USAGE.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_USAGE.getModeValue(ApplicationMode.CAR));
|
settings.AUDIO_USAGE.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_USAGE.getModeValue(ApplicationMode.CAR));
|
||||||
} else {
|
} else {
|
||||||
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
|
super.onApplyPreferenceChange(prefId, applyToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -55,7 +55,6 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
app.getSettings().setPreferenceForAllModes(prefId, newValue);
|
|
||||||
updateTargetSettings(false, true);
|
updateTargetSettings(false, true);
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
@ -72,7 +71,6 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
app.getSettings().setPreference(prefId, newValue, getAppMode());
|
|
||||||
updateTargetSettings(false, false);
|
updateTargetSettings(false, false);
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
@ -106,12 +104,11 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
||||||
outState.putSerializable(NEW_VALUE_KEY, newValue);
|
outState.putSerializable(NEW_VALUE_KEY, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTargetSettings(boolean discard, boolean appliedToAllProfiles) {
|
private void updateTargetSettings(boolean discard, boolean applyToAllProfiles) {
|
||||||
BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment();
|
BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment();
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
if (!discard) {
|
if (!discard) {
|
||||||
target.onSettingApplied(getPrefId(), appliedToAllProfiles);
|
target.onApplyPreferenceChange(getPrefId(), applyToAllProfiles, newValue);
|
||||||
target.onApplyPreferenceChange(getPrefId(), appliedToAllProfiles, newValue);
|
|
||||||
}
|
}
|
||||||
target.updateSetting(getPrefId());
|
target.updateSetting(getPrefId());
|
||||||
if (!discard) {
|
if (!discard) {
|
||||||
|
|
Loading…
Reference in a new issue