Show SnackBar when preference change (fixes p.2)
This commit is contained in:
parent
5446ad43f8
commit
6fd89d17e6
14 changed files with 141 additions and 101 deletions
|
@ -15,12 +15,15 @@ import android.os.Build;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewParent;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -37,6 +40,7 @@ import androidx.core.view.ViewCompat;
|
||||||
import androidx.core.widget.TintableCompoundButton;
|
import androidx.core.widget.TintableCompoundButton;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
import com.google.android.material.snackbar.SnackbarContentLayout;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
|
@ -390,6 +394,28 @@ public class UiUtilities {
|
||||||
view.setBackgroundColor(ContextCompat.getColor(ctx, backgroundColor));
|
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) {
|
public static void rotateImageByLayoutDirection(ImageView image, int layoutDirection) {
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -83,7 +83,7 @@ import java.io.Serializable;
|
||||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
|
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
|
||||||
|
|
||||||
public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener,
|
public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener,
|
||||||
OnPreferenceClickListener, AppModeChangedListener, OnApplyPreference {
|
OnPreferenceClickListener, AppModeChangedListener, OnConfirmPreferenceChange {
|
||||||
|
|
||||||
private static final Log LOG = PlatformUtil.getLog(BaseSettingsFragment.class);
|
private static final Log LOG = PlatformUtil.getLog(BaseSettingsFragment.class);
|
||||||
|
|
||||||
|
@ -314,26 +314,28 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
return onApplyPreference(preference.getKey(), newValue, getApplyQueryType());
|
return onConfirmPreferenceChange(preference.getKey(), newValue, getApplyQueryType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onApplyPreference(String prefId, Object newValue, ApplyQueryType applyQueryType) {
|
public boolean onConfirmPreferenceChange(String prefId, Object newValue, ApplyQueryType applyQueryType) {
|
||||||
if (applyQueryType != null && newValue instanceof Serializable) {
|
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) {
|
||||||
if (applyQueryType == ApplyQueryType.SNACK_BAR) {
|
if (applyQueryType == ApplyQueryType.SNACK_BAR) {
|
||||||
applySettingWithSnackBar(prefId, (Serializable) newValue);
|
applyPreferenceWithSnackBar(prefId, (Serializable) newValue);
|
||||||
|
return true;
|
||||||
} else if (applyQueryType == ApplyQueryType.BOTTOM_SHEET) {
|
} else if (applyQueryType == ApplyQueryType.BOTTOM_SHEET) {
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
if (fragmentManager != null) {
|
if (fragmentManager != null) {
|
||||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
|
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
|
||||||
(Serializable) newValue, this, false, getSelectedAppMode());
|
(Serializable) newValue, this, false, getSelectedAppMode());
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
} else if (applyQueryType == ApplyQueryType.NONE) {
|
} else if (applyQueryType == ApplyQueryType.NONE) {
|
||||||
onSettingApplied(prefId, newValue, false);
|
onApplyPreferenceChange(prefId, false, newValue);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -363,7 +365,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
if (preference instanceof ListPreferenceEx) {
|
if (preference instanceof ListPreferenceEx) {
|
||||||
SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode, isProfileDependent(), false);
|
SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode, isProfileDependent(), false);
|
||||||
} else if (preference instanceof SwitchPreferenceEx) {
|
} 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) {
|
} else if (preference instanceof EditTextPreference) {
|
||||||
EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
|
EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
|
||||||
} else if (preference instanceof MultiSelectBooleanPreference) {
|
} else if (preference instanceof MultiSelectBooleanPreference) {
|
||||||
|
@ -606,7 +608,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
public void onSettingApplied(String prefId, boolean appliedToAllProfiles) {
|
public void onSettingApplied(String prefId, boolean appliedToAllProfiles) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) {
|
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
||||||
if (appliedToAllProfiles) {
|
if (appliedToAllProfiles) {
|
||||||
app.getSettings().setPreferenceForAllModes(prefId, newValue);
|
app.getSettings().setPreferenceForAllModes(prefId, newValue);
|
||||||
} else {
|
} else {
|
||||||
|
@ -904,8 +906,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void applySettingWithSnackBar(final String prefId, final Serializable newValue) {
|
protected void applyPreferenceWithSnackBar(final String prefId, final Serializable newValue) {
|
||||||
onSettingApplied(prefId, newValue, false);
|
onApplyPreferenceChange(prefId, false, newValue);
|
||||||
updateSetting(prefId);
|
updateSetting(prefId);
|
||||||
View containerView = getView();
|
View containerView = getView();
|
||||||
if (containerView != null) {
|
if (containerView != null) {
|
||||||
|
@ -916,9 +918,10 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
.setAction(R.string.apply_to_all_profiles, new View.OnClickListener() {
|
.setAction(R.string.apply_to_all_profiles, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
onSettingApplied(prefId, newValue, true);
|
onApplyPreferenceChange(prefId, true, newValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
UiUtilities.setupSnackbarVerticalLayout(snackbar);
|
||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.widget.AppCompatCheckedTextView;
|
import androidx.appcompat.widget.AppCompatCheckedTextView;
|
||||||
import androidx.appcompat.widget.SwitchCompat;
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
import androidx.preference.SwitchPreferenceCompat;
|
import androidx.preference.SwitchPreferenceCompat;
|
||||||
|
@ -25,16 +24,13 @@ import androidx.preference.SwitchPreferenceCompat;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.Version;
|
import net.osmand.plus.Version;
|
||||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
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.ListPreferenceEx;
|
||||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -355,7 +351,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
String prefId = preference.getKey();
|
String prefId = preference.getKey();
|
||||||
if (settings.ROTATE_MAP.getId().equals(prefId)) {
|
if (settings.ROTATE_MAP.getId().equals(prefId)) {
|
||||||
onApplyPreference(prefId, newValue, ApplyQueryType.SNACK_BAR);
|
onConfirmPreferenceChange(prefId, newValue, ApplyQueryType.SNACK_BAR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return super.onPreferenceChange(preference, newValue);
|
return super.onPreferenceChange(preference, newValue);
|
||||||
|
|
|
@ -2,7 +2,6 @@ package net.osmand.plus.settings;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import net.osmand.plus.ApplicationMode;
|
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.AutoZoomMap;
|
import net.osmand.plus.OsmandSettings.AutoZoomMap;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -102,38 +101,27 @@ public class MapDuringNavigationFragment extends BaseSettingsFragment {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
if (preference.getKey().equals(settings.AUTO_ZOOM_MAP.getId())) {
|
if (preference.getKey().equals(settings.AUTO_ZOOM_MAP.getId())) {
|
||||||
onApplyPreference(settings.AUTO_ZOOM_MAP.getId(), newValue, ApplyQueryType.SNACK_BAR);
|
onConfirmPreferenceChange(settings.AUTO_ZOOM_MAP.getId(), newValue, ApplyQueryType.SNACK_BAR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onPreferenceChange(preference, newValue);
|
return super.onPreferenceChange(preference, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) {
|
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
||||||
if (settings.AUTO_ZOOM_MAP.getId().equals(prefId)) {
|
if (settings.AUTO_ZOOM_MAP.getId().equals(prefId)) {
|
||||||
if (newValue instanceof Integer) {
|
if (newValue instanceof Integer) {
|
||||||
ApplicationMode selectedMode = getSelectedAppMode();
|
|
||||||
int position = (int) newValue;
|
int position = (int) newValue;
|
||||||
if (appliedToAllProfiles) {
|
if (position == 0) {
|
||||||
if (position == 0) {
|
super.onApplyPreferenceChange(settings.AUTO_ZOOM_MAP.getId(), appliedToAllProfiles, false);
|
||||||
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 {
|
} else {
|
||||||
if (position == 0) {
|
super.onApplyPreferenceChange(settings.AUTO_ZOOM_MAP.getId(), appliedToAllProfiles, true);
|
||||||
settings.AUTO_ZOOM_MAP.setModeValue(selectedMode, false);
|
super.onApplyPreferenceChange(settings.AUTO_ZOOM_MAP_SCALE.getId(),
|
||||||
} else {
|
appliedToAllProfiles, OsmandSettings.AutoZoomMap.values()[position - 1]);
|
||||||
settings.AUTO_ZOOM_MAP.setModeValue(selectedMode, true);
|
|
||||||
settings.AUTO_ZOOM_MAP_SCALE.setModeValue(selectedMode,
|
|
||||||
OsmandSettings.AutoZoomMap.values()[position - 1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
super.onSettingApplied(prefId, newValue, appliedToAllProfiles);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,6 @@ import net.osmand.router.GeneralRouter;
|
||||||
import net.osmand.router.RoutingConfiguration;
|
import net.osmand.router.RoutingConfiguration;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -93,13 +92,13 @@ public class NavigationFragment extends BaseSettingsFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) {
|
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
||||||
if (settings.VOICE_MUTE.getId().equals(prefId) && newValue instanceof Boolean) {
|
if (settings.VOICE_MUTE.getId().equals(prefId) && newValue instanceof Boolean) {
|
||||||
super.onSettingApplied(prefId, !(Boolean) newValue, appliedToAllProfiles);
|
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, !(Boolean) newValue);
|
||||||
updateMenu();
|
updateMenu();
|
||||||
return;
|
} else {
|
||||||
|
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
super.onSettingApplied(prefId, newValue, appliedToAllProfiles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package net.osmand.plus.settings;
|
|
||||||
|
|
||||||
public interface OnApplyPreference {
|
|
||||||
|
|
||||||
boolean onApplyPreference(String prefId, Object newValue, ApplyQueryType applyQueryType);
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package net.osmand.plus.settings;
|
||||||
|
|
||||||
|
public interface OnConfirmPreferenceChange {
|
||||||
|
|
||||||
|
boolean onConfirmPreferenceChange(String prefId, Object newValue, ApplyQueryType applyQueryType);
|
||||||
|
|
||||||
|
}
|
|
@ -411,7 +411,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSettingApplied(String prefId, Object newValue, boolean appliedToAllProfiles) {
|
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
||||||
if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) {
|
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;
|
||||||
|
@ -421,14 +421,12 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
SettingsNavigationActivity.setRoutingParameterSelected(settings, appMode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId));
|
SettingsNavigationActivity.setRoutingParameterSelected(settings, appMode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId));
|
||||||
}
|
}
|
||||||
recalculateRoute();
|
recalculateRoute();
|
||||||
return;
|
|
||||||
} else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) {
|
} else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) {
|
||||||
if (appliedToAllProfiles) {
|
if (appliedToAllProfiles) {
|
||||||
settings.setPreferenceForAllModes(settings.FAST_ROUTE_MODE.getId(), !(Boolean) newValue);
|
settings.setPreferenceForAllModes(settings.FAST_ROUTE_MODE.getId(), !(Boolean) newValue);
|
||||||
} else {
|
} else {
|
||||||
settings.setPreference(settings.FAST_ROUTE_MODE.getId(), !(Boolean) newValue, getSelectedAppMode());
|
settings.setPreference(settings.FAST_ROUTE_MODE.getId(), !(Boolean) newValue, getSelectedAppMode());
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
} 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;
|
||||||
|
@ -439,25 +437,18 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
valueToSave = (float) newValue;
|
valueToSave = (float) newValue;
|
||||||
enabled = valueToSave != DISABLE_MODE;
|
enabled = valueToSave != DISABLE_MODE;
|
||||||
}
|
}
|
||||||
if (appliedToAllProfiles) {
|
super.onApplyPreferenceChange(ROUTING_RECALC_DISTANCE, appliedToAllProfiles, valueToSave);
|
||||||
settings.setPreferenceForAllModes(prefId, valueToSave);
|
super.onApplyPreferenceChange(settings.DISABLE_OFFROUTE_RECALC.getId(), appliedToAllProfiles, !enabled);
|
||||||
settings.setPreferenceForAllModes(settings.DISABLE_OFFROUTE_RECALC.getId(), !enabled);
|
|
||||||
} else {
|
|
||||||
settings.setPreference(prefId, valueToSave, getSelectedAppMode());
|
|
||||||
settings.setPreference(settings.DISABLE_OFFROUTE_RECALC.getId(), !enabled, getSelectedAppMode());
|
|
||||||
}
|
|
||||||
updateRouteRecalcDistancePref();
|
updateRouteRecalcDistancePref();
|
||||||
return;
|
} else {
|
||||||
|
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
super.onSettingApplied(prefId, newValue, appliedToAllProfiles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPreferenceChanged(String prefId) {
|
public void onPreferenceChanged(String prefId) {
|
||||||
if (AVOID_ROUTING_PARAMETER_PREFIX.equals(prefId) || PREFER_ROUTING_PARAMETER_PREFIX.equals(prefId)) {
|
if (AVOID_ROUTING_PARAMETER_PREFIX.equals(prefId) || PREFER_ROUTING_PARAMETER_PREFIX.equals(prefId)) {
|
||||||
recalculateRoute();
|
recalculateRoute();
|
||||||
} else if (ROUTING_RECALC_DISTANCE.equals(prefId)) {
|
|
||||||
updateRouteRecalcDistancePref();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,8 @@ public class ScreenAlertsFragment extends BaseSettingsFragment {
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
ApplicationMode selectedMode = getSelectedAppMode();
|
ApplicationMode selectedMode = getSelectedAppMode();
|
||||||
boolean checked = !settings.SHOW_ROUTING_ALARMS.getModeValue(selectedMode);
|
boolean checked = !settings.SHOW_ROUTING_ALARMS.getModeValue(selectedMode);
|
||||||
onApplyPreference(settings.SHOW_ROUTING_ALARMS.getId(), checked, ApplyQueryType.SNACK_BAR);
|
onConfirmPreferenceChange(
|
||||||
|
settings.SHOW_ROUTING_ALARMS.getId(), checked, ApplyQueryType.SNACK_BAR);
|
||||||
updateToolbarSwitch();
|
updateToolbarSwitch();
|
||||||
enableDisablePreferences(checked);
|
enableDisablePreferences(checked);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,8 @@ public class TurnScreenOnFragment extends BaseSettingsFragment {
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
ApplicationMode selectedMode = getSelectedAppMode();
|
ApplicationMode selectedMode = getSelectedAppMode();
|
||||||
boolean checked = !settings.TURN_SCREEN_ON_ENABLED.getModeValue(selectedMode);
|
boolean checked = !settings.TURN_SCREEN_ON_ENABLED.getModeValue(selectedMode);
|
||||||
onApplyPreference(settings.TURN_SCREEN_ON_ENABLED.getId(), checked, ApplyQueryType.SNACK_BAR);
|
onConfirmPreferenceChange(
|
||||||
|
settings.TURN_SCREEN_ON_ENABLED.getId(), checked, ApplyQueryType.SNACK_BAR);
|
||||||
updateToolbarSwitch();
|
updateToolbarSwitch();
|
||||||
enableDisablePreferences(checked);
|
enableDisablePreferences(checked);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
ApplicationMode selectedMode = getSelectedAppMode();
|
ApplicationMode selectedMode = getSelectedAppMode();
|
||||||
boolean checked = !settings.VOICE_MUTE.getModeValue(selectedMode);
|
boolean checked = !settings.VOICE_MUTE.getModeValue(selectedMode);
|
||||||
onApplyPreference(settings.VOICE_MUTE.getId(), checked, ApplyQueryType.SNACK_BAR);
|
onConfirmPreferenceChange(
|
||||||
|
settings.VOICE_MUTE.getId(), checked, ApplyQueryType.SNACK_BAR);
|
||||||
updateToolbarSwitch();
|
updateToolbarSwitch();
|
||||||
enableDisablePreferences(!checked);
|
enableDisablePreferences(!checked);
|
||||||
updateMenu();
|
updateMenu();
|
||||||
|
@ -219,7 +220,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
onApplyPreference(settings.SPEAK_SPEED_CAMERA.getId(), true, ApplyQueryType.SNACK_BAR);
|
onConfirmPreferenceChange(
|
||||||
|
settings.SPEAK_SPEED_CAMERA.getId(), true, ApplyQueryType.SNACK_BAR);
|
||||||
SwitchPreferenceCompat speakSpeedCamera = (SwitchPreferenceCompat) findPreference(settings.SPEAK_SPEED_CAMERA.getId());
|
SwitchPreferenceCompat speakSpeedCamera = (SwitchPreferenceCompat) findPreference(settings.SPEAK_SPEED_CAMERA.getId());
|
||||||
if (speakSpeedCamera != null) {
|
if (speakSpeedCamera != null) {
|
||||||
speakSpeedCamera.setChecked(true);
|
speakSpeedCamera.setChecked(true);
|
||||||
|
@ -267,13 +269,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return false;
|
return false;
|
||||||
} else if (newValue instanceof String) {
|
} else if (newValue instanceof String) {
|
||||||
if (VOICE_PROVIDER_NOT_USE.equals(newValue)) {
|
onConfirmPreferenceChange(settings.VOICE_PROVIDER.getId(), newValue, ApplyQueryType.SNACK_BAR);
|
||||||
onApplyPreference(settings.VOICE_MUTE.getId(), true, ApplyQueryType.SNACK_BAR);
|
|
||||||
updateToolbar();
|
|
||||||
// setupPreferences(); //TODO doesn't need anymore
|
|
||||||
}
|
|
||||||
onApplyPreference(settings.VOICE_PROVIDER.getId(), newValue, ApplyQueryType.SNACK_BAR);
|
|
||||||
app.initVoiceCommandPlayer(getActivity(), selectedMode, false, null, true, false, false);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -282,10 +278,29 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
confirmSpeedCamerasDlg();
|
confirmSpeedCamerasDlg();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return onApplyPreference(settings.SPEAK_SPEED_CAMERA.getId(), false, ApplyQueryType.SNACK_BAR);
|
return onConfirmPreferenceChange(
|
||||||
|
settings.SPEAK_SPEED_CAMERA.getId(), false, ApplyQueryType.SNACK_BAR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) {
|
if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) {
|
||||||
|
return onConfirmPreferenceChange(
|
||||||
|
settings.AUDIO_MANAGER_STREAM.getId(), newValue, ApplyQueryType.SNACK_BAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onPreferenceChange(preference, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplyPreferenceChange(String prefId, boolean appliedToAllProfiles, Object newValue) {
|
||||||
|
if (prefId.equals(settings.VOICE_PROVIDER.getId()) && newValue instanceof String) {
|
||||||
|
if (VOICE_PROVIDER_NOT_USE.equals(newValue)) {
|
||||||
|
super.onApplyPreferenceChange(settings.VOICE_MUTE.getId(), appliedToAllProfiles, true);
|
||||||
|
updateToolbar();
|
||||||
|
}
|
||||||
|
super.onApplyPreferenceChange(settings.VOICE_PROVIDER.getId(), appliedToAllProfiles, newValue);
|
||||||
|
app.initVoiceCommandPlayer(getActivity(), getSelectedAppMode(),
|
||||||
|
false, null, true, false, appliedToAllProfiles);
|
||||||
|
} else if (prefId.equals(settings.AUDIO_MANAGER_STREAM.getId())) {
|
||||||
// Sync DEFAULT value with CAR value, as we have other way to set it for now
|
// Sync DEFAULT value with CAR value, as we have other way to set it for now
|
||||||
|
|
||||||
if (getSelectedAppMode().equals(ApplicationMode.CAR) && newValue instanceof Integer) {
|
if (getSelectedAppMode().equals(ApplicationMode.CAR) && newValue instanceof Integer) {
|
||||||
|
@ -294,10 +309,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
||||||
settings.AUDIO_MANAGER_STREAM.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_MANAGER_STREAM.getModeValue(ApplicationMode.CAR));
|
settings.AUDIO_MANAGER_STREAM.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_MANAGER_STREAM.getModeValue(ApplicationMode.CAR));
|
||||||
}
|
}
|
||||||
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 {
|
||||||
return true;
|
super.onApplyPreferenceChange(prefId, appliedToAllProfiles, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onPreferenceChange(preference, newValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ import androidx.preference.Preference;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.settings.ApplyQueryType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,12 +19,14 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
|
||||||
|
|
||||||
public static final String PREFERENCE_ID = "preference_id";
|
public static final String PREFERENCE_ID = "preference_id";
|
||||||
private static final String APP_MODE_KEY = "app_mode_key";
|
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 static final String PROFILE_DEPENDENT = "profile_dependent";
|
||||||
|
|
||||||
private String prefId;
|
private String prefId;
|
||||||
private Preference preference;
|
private Preference preference;
|
||||||
private ApplicationMode appMode;
|
private ApplicationMode appMode;
|
||||||
private boolean profileDependent;
|
private boolean profileDependent;
|
||||||
|
private ApplyQueryType applyQueryType;
|
||||||
|
|
||||||
public void setAppMode(ApplicationMode appMode) {
|
public void setAppMode(ApplicationMode appMode) {
|
||||||
this.appMode = appMode;
|
this.appMode = appMode;
|
||||||
|
@ -38,6 +41,7 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
|
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
|
||||||
|
applyQueryType = ApplyQueryType.valueOf(savedInstanceState.getString(APPLY_QUERY_TYPE));
|
||||||
profileDependent = savedInstanceState.getBoolean(PROFILE_DEPENDENT, false);
|
profileDependent = savedInstanceState.getBoolean(PROFILE_DEPENDENT, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +53,9 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
|
||||||
if (appMode != null) {
|
if (appMode != null) {
|
||||||
outState.putString(APP_MODE_KEY, appMode.getStringKey());
|
outState.putString(APP_MODE_KEY, appMode.getStringKey());
|
||||||
}
|
}
|
||||||
|
if (applyQueryType != null) {
|
||||||
|
outState.putString(APPLY_QUERY_TYPE, applyQueryType.name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -107,4 +114,12 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
|
||||||
public boolean isProfileDependent() {
|
public boolean isProfileDependent() {
|
||||||
return profileDependent;
|
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.BottomSheetItemWithCompoundButton;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
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.OnPreferenceChanged;
|
||||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||||
|
|
||||||
|
@ -74,16 +76,25 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
boolean newValue = !pref.getModeValue(getAppMode());
|
boolean newValue = !pref.getModeValue(getAppMode());
|
||||||
if (switchPreference.callChangeListener(newValue)) {
|
Fragment targetFragment = getTargetFragment();
|
||||||
switchPreference.setChecked(newValue);
|
if (targetFragment instanceof OnConfirmPreferenceChange) {
|
||||||
preferenceBtn[0].setTitle(newValue ? on : off);
|
ApplyQueryType applyQueryType = getApplyQueryType();
|
||||||
preferenceBtn[0].setChecked(newValue);
|
if (applyQueryType == ApplyQueryType.SNACK_BAR) {
|
||||||
preferenceBtn[0].setTitleColorId(newValue ? activeColor : disabledColor);
|
applyQueryType = ApplyQueryType.NONE;
|
||||||
updateCustomButtonView(v, newValue);
|
}
|
||||||
|
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 (targetFragment instanceof OnPreferenceChanged) {
|
||||||
if (target instanceof OnPreferenceChanged) {
|
((OnPreferenceChanged) targetFragment).onPreferenceChanged(switchPreference.getKey());
|
||||||
((OnPreferenceChanged) target).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,
|
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 {
|
try {
|
||||||
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
|
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
@ -155,6 +167,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
fragment.setUsedOnMap(usedOnMap);
|
fragment.setUsedOnMap(usedOnMap);
|
||||||
fragment.setAppMode(appMode);
|
fragment.setAppMode(appMode);
|
||||||
|
fragment.setApplyQueryType(applyQueryType);
|
||||||
fragment.setTargetFragment(target, 0);
|
fragment.setTargetFragment(target, 0);
|
||||||
fragment.setProfileDependent(profileDependent);
|
fragment.setProfileDependent(profileDependent);
|
||||||
fragment.show(fm, BooleanPreferenceBottomSheet.TAG);
|
fragment.show(fm, BooleanPreferenceBottomSheet.TAG);
|
||||||
|
|
|
@ -27,8 +27,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitmeListDividerItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.settings.ApplyQueryType;
|
import net.osmand.plus.settings.ApplyQueryType;
|
||||||
import net.osmand.plus.settings.OnApplyPreference;
|
import net.osmand.plus.settings.OnConfirmPreferenceChange;
|
||||||
import net.osmand.plus.settings.OnPreferenceChanged;
|
|
||||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||||
|
|
||||||
import static net.osmand.plus.settings.RouteParametersFragment.DEFAULT_MODE;
|
import static net.osmand.plus.settings.RouteParametersFragment.DEFAULT_MODE;
|
||||||
|
@ -121,11 +120,8 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
|
||||||
updateCustomButtonView(v, enabled);
|
updateCustomButtonView(v, enabled);
|
||||||
Fragment target = getTargetFragment();
|
Fragment target = getTargetFragment();
|
||||||
float newValue = enabled ? DEFAULT_MODE : DISABLE_MODE;
|
float newValue = enabled ? DEFAULT_MODE : DISABLE_MODE;
|
||||||
if (target instanceof OnApplyPreference) {
|
if (target instanceof OnConfirmPreferenceChange) {
|
||||||
((OnApplyPreference) target).onApplyPreference(switchPref.getKey(), newValue, ApplyQueryType.NONE);
|
((OnConfirmPreferenceChange) target).onConfirmPreferenceChange(switchPref.getKey(), newValue, ApplyQueryType.NONE);
|
||||||
}
|
|
||||||
if (target instanceof OnPreferenceChanged) {
|
|
||||||
((OnPreferenceChanged) target).onPreferenceChanged(switchPref.getKey());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -157,11 +153,9 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
|
||||||
protected void onRightBottomButtonClick() {
|
protected void onRightBottomButtonClick() {
|
||||||
if (enabled && sliderPositionChanged) {
|
if (enabled && sliderPositionChanged) {
|
||||||
Fragment target = getTargetFragment();
|
Fragment target = getTargetFragment();
|
||||||
if (target instanceof OnApplyPreference) {
|
if (target instanceof OnConfirmPreferenceChange) {
|
||||||
((OnApplyPreference) target).onApplyPreference(preference.getId(), currentValue, ApplyQueryType.SNACK_BAR);
|
((OnConfirmPreferenceChange) target).onConfirmPreferenceChange(
|
||||||
}
|
preference.getId(), currentValue, ApplyQueryType.SNACK_BAR);
|
||||||
if (target instanceof OnPreferenceChanged) {
|
|
||||||
((OnPreferenceChanged) target).onPreferenceChanged(preference.getId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
|
|
Loading…
Reference in a new issue