Remove general preferences and make apply to all save every profile pref

This commit is contained in:
Vitaliy 2019-12-17 12:08:09 +02:00
parent 0ac801f8f2
commit 6c5dd70691
3 changed files with 39 additions and 60 deletions

View file

@ -237,7 +237,7 @@ public class OsmandSettings {
if (pref instanceof CommonPreference) {
CommonPreference commonPreference = (CommonPreference) pref;
if (!commonPreference.global) {
List<ApplicationMode> modes = commonPreference.general ? Collections.singletonList(ApplicationMode.DEFAULT) : ApplicationMode.allPossibleValues();
List<ApplicationMode> modes = ApplicationMode.allPossibleValues();
for (ApplicationMode mode : modes) {
if (!commonPreference.isSetForMode(mode)) {
setPreference(key, globalPrefsMap.get(key), mode);
@ -290,25 +290,10 @@ public class OsmandSettings {
return registeredPreferences.get(key);
}
public boolean setSharedGeneralPreference(String key, Object value) {
OsmandPreference<?> preference = registeredPreferences.get(key);
if (preference instanceof CommonPreference) {
CommonPreference commonPref = (CommonPreference) preference;
if (commonPref.general) {
for (ApplicationMode mode : ApplicationMode.values(ctx)) {
if (commonPref.isSetForMode(mode)) {
settingsAPI.edit(getProfilePreferences(mode)).remove(key).commit();
}
}
boolean valueSaved = setPreference(key, value, ApplicationMode.DEFAULT);
if (valueSaved) {
commonPref.cachedValue = null;
}
return valueSaved;
}
public void setPreferenceForAllModes(String key, Object value) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
setPreference(key, value, mode);
}
return false;
}
public boolean setPreference(String key, Object value) {
@ -592,7 +577,6 @@ public class OsmandSettings {
public abstract class CommonPreference<T> extends PreferenceWithListener<T> {
private final String id;
private boolean global;
private boolean general;
private T cachedValue;
private Object cachedPreference;
private boolean cache;
@ -621,11 +605,6 @@ public class OsmandSettings {
return this;
}
public CommonPreference<T> makeGeneral() {
general = true;
return this;
}
protected Object getPreferences() {
return global ? globalPreferences : profilePreferences;
}
@ -664,7 +643,7 @@ public class OsmandSettings {
if (pt != null) {
return getProfileDefaultValue(pt);
}
if (general && settingsAPI.contains(defaultProfilePreferences, getId())) {
if (settingsAPI.contains(defaultProfilePreferences, getId())) {
return getValue(defaultProfilePreferences, defaultValue);
} else {
return defaultValue;
@ -1277,7 +1256,7 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> FIRST_MAP_IS_DOWNLOADED = new BooleanPreference(
"first_map_is_downloaded", false);
public final CommonPreference<Boolean> DRIVING_REGION_AUTOMATIC = new BooleanPreference("driving_region_automatic", true).makeProfile().makeGeneral().cache();
public final CommonPreference<Boolean> DRIVING_REGION_AUTOMATIC = new BooleanPreference("driving_region_automatic", true).makeProfile().cache();
public final OsmandPreference<DrivingRegion> DRIVING_REGION = new EnumIntPreference<DrivingRegion>(
"default_driving_region", DrivingRegion.EUROPE_ASIA, DrivingRegion.values()) {
protected boolean setValue(Object prefs, DrivingRegion val) {
@ -1309,7 +1288,7 @@ public class OsmandSettings {
return DrivingRegion.EUROPE_ASIA;
}
}.makeProfile().makeGeneral().cache();
}.makeProfile().cache();
// this value string is synchronized with settings_pref.xml preference name
// cache of metrics constants as they are used very often
@ -1319,12 +1298,12 @@ public class OsmandSettings {
return DRIVING_REGION.get().defMetrics;
}
}.makeProfile().makeGeneral();
}.makeProfile();
//public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeGlobal();
public final OsmandPreference<AngularConstants> ANGULAR_UNITS = new EnumIntPreference<AngularConstants>(
"angular_measurement", AngularConstants.DEGREES, AngularConstants.values()).makeProfile().makeGeneral();
"angular_measurement", AngularConstants.DEGREES, AngularConstants.values()).makeProfile();
public final OsmandPreference<SpeedConstants> SPEED_SYSTEM = new EnumIntPreference<SpeedConstants>(
@ -1354,7 +1333,7 @@ public class OsmandSettings {
;
}.makeProfile().makeGeneral();
}.makeProfile();
// this value string is synchronized with settings_pref.xml preference name
@ -1391,7 +1370,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> USE_TRACKBALL_FOR_MOVEMENTS =
new BooleanPreference("use_trackball_for_movements", true).makeProfile().makeGeneral();
new BooleanPreference("use_trackball_for_movements", true).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> ACCESSIBILITY_SMART_AUTOANNOUNCE =
@ -1418,12 +1397,12 @@ public class OsmandSettings {
new BooleanAccessibilityPreference("direction_haptic_feedback", false).makeGlobal();
// magnetic field doesn'torkmost of the time on some phones
public final OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS = new BooleanPreference("use_magnetic_field_sensor_compass", false).makeProfile().makeGeneral().cache();
public final OsmandPreference<Boolean> USE_KALMAN_FILTER_FOR_COMPASS = new BooleanPreference("use_kalman_filter_compass", true).makeProfile().makeGeneral().cache();
public final OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS = new BooleanPreference("use_magnetic_field_sensor_compass", false).makeProfile().cache();
public final OsmandPreference<Boolean> USE_KALMAN_FILTER_FOR_COMPASS = new BooleanPreference("use_kalman_filter_compass", true).makeProfile().cache();
public final OsmandPreference<Boolean> DO_NOT_SHOW_STARTUP_MESSAGES = new BooleanPreference("do_not_show_startup_messages", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SHOW_DOWNLOAD_MAP_DIALOG = new BooleanPreference("show_download_map_dialog", true).makeGlobal().cache();
public final OsmandPreference<Boolean> DO_NOT_USE_ANIMATIONS = new BooleanPreference("do_not_use_animations", false).makeProfile().makeGeneral().cache();
public final OsmandPreference<Boolean> DO_NOT_USE_ANIMATIONS = new BooleanPreference("do_not_use_animations", false).makeProfile().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_MAP_DOWNLOADS_DATA = new BooleanPreference("send_anonymous_map_downloads_data", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_APP_USAGE_DATA = new BooleanPreference("send_anonymous_app_usage_data", false).makeGlobal().cache();
@ -1431,7 +1410,7 @@ public class OsmandSettings {
public final OsmandPreference<Integer> SEND_ANONYMOUS_DATA_REQUESTS_COUNT = new IntPreference("send_anonymous_data_requests_count", 0).makeGlobal().cache();
public final OsmandPreference<Integer> SEND_ANONYMOUS_DATA_LAST_REQUEST_NS = new IntPreference("send_anonymous_data_last_request_ns", -1).makeGlobal().cache();
public final OsmandPreference<Boolean> MAP_EMPTY_STATE_ALLOWED = new BooleanPreference("map_empty_state_allowed", false).makeProfile().makeGeneral().cache();
public final OsmandPreference<Boolean> MAP_EMPTY_STATE_ALLOWED = new BooleanPreference("map_empty_state_allowed", false).makeProfile().cache();
public final CommonPreference<Float> TEXT_SCALE = new FloatPreference("text_scale", 1f).makeProfile().cache();
@ -1575,10 +1554,10 @@ public class OsmandSettings {
public static final String SAVE_CURRENT_TRACK = "save_current_track"; //$NON-NLS-1$
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_TO_GPX = new BooleanPreference("save_global_track_to_gpx", false).makeGlobal().cache();
public final CommonPreference<Integer> SAVE_GLOBAL_TRACK_INTERVAL = new IntPreference("save_global_track_interval", 5000).makeProfile().makeGeneral().cache();
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_REMEMBER = new BooleanPreference("save_global_track_remember", false).makeProfile().makeGeneral().cache();
public final CommonPreference<Integer> SAVE_GLOBAL_TRACK_INTERVAL = new IntPreference("save_global_track_interval", 5000).makeProfile().cache();
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_REMEMBER = new BooleanPreference("save_global_track_remember", false).makeProfile().cache();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> SAVE_TRACK_TO_GPX = new BooleanPreference("save_track_to_gpx", false).makeProfile().makeGeneral().cache();
public final CommonPreference<Boolean> SAVE_TRACK_TO_GPX = new BooleanPreference("save_track_to_gpx", false).makeProfile().cache();
{
SAVE_TRACK_TO_GPX.setModeDefaultValue(ApplicationMode.CAR, false);
@ -1590,11 +1569,11 @@ public class OsmandSettings {
public static final Integer MONTHLY_DIRECTORY = 1;
public static final Integer DAILY_DIRECTORY = 2;
public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeProfile();
public final CommonPreference<Boolean> SAVE_HEADING_TO_GPX = new BooleanPreference("save_heading_to_gpx", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> SAVE_HEADING_TO_GPX = new BooleanPreference("save_heading_to_gpx", false).makeProfile();
public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeProfile().makeGeneral();
public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> FAST_ROUTE_MODE = new BooleanPreference("fast_route_mode", true).makeProfile();
@ -1701,7 +1680,7 @@ public class OsmandSettings {
public final CommonPreference<Integer> CURRENT_TRACK_COLOR = new IntPreference("current_track_color", 0).makeGlobal().cache();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile().makeGeneral();
public final CommonPreference<Integer> SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile();
{
SAVE_TRACK_INTERVAL.setModeDefaultValue(ApplicationMode.CAR, 3000);
@ -1710,40 +1689,40 @@ public class OsmandSettings {
}
// Please note that SAVE_TRACK_MIN_DISTANCE, SAVE_TRACK_PRECISION, SAVE_TRACK_MIN_SPEED should all be "0" for the default profile, as we have no interface to change them
public final CommonPreference<Float> SAVE_TRACK_MIN_DISTANCE = new FloatPreference("save_track_min_distance", 0).makeProfile().makeGeneral();
public final CommonPreference<Float> SAVE_TRACK_MIN_DISTANCE = new FloatPreference("save_track_min_distance", 0).makeProfile();
//{
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.CAR, 5.f);
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.BICYCLE, 5.f);
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 5.f);
//}
public final CommonPreference<Float> SAVE_TRACK_PRECISION = new FloatPreference("save_track_precision", 50.0f).makeProfile().makeGeneral();
public final CommonPreference<Float> SAVE_TRACK_PRECISION = new FloatPreference("save_track_precision", 50.0f).makeProfile();
//{
// SAVE_TRACK_PRECISION.setModeDefaultValue(ApplicationMode.CAR, 50.f);
// SAVE_TRACK_PRECISION.setModeDefaultValue(ApplicationMode.BICYCLE, 50.f);
// SAVE_TRACK_PRECISION.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 50.f);
//}
public final CommonPreference<Float> SAVE_TRACK_MIN_SPEED = new FloatPreference("save_track_min_speed", 0.f).makeProfile().makeGeneral();
public final CommonPreference<Float> SAVE_TRACK_MIN_SPEED = new FloatPreference("save_track_min_speed", 0.f).makeProfile();
//{
// SAVE_TRACK_MIN_SPEED.setModeDefaultValue(ApplicationMode.CAR, 2.f);
// SAVE_TRACK_MIN_SPEED.setModeDefaultValue(ApplicationMode.BICYCLE, 1.f);
// SAVE_TRACK_MIN_SPEED.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0.f);
//}
public final CommonPreference<Boolean> AUTO_SPLIT_RECORDING = new BooleanPreference("auto_split_recording", true).makeProfile().makeGeneral();
public final CommonPreference<Boolean> AUTO_SPLIT_RECORDING = new BooleanPreference("auto_split_recording", true).makeProfile();
public final CommonPreference<Boolean> SHOW_TRIP_REC_NOTIFICATION = new BooleanPreference("show_trip_recording_notification", true).makeProfile().makeGeneral();
public final CommonPreference<Boolean> SHOW_TRIP_REC_NOTIFICATION = new BooleanPreference("show_trip_recording_notification", true).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> LIVE_MONITORING = new BooleanPreference("live_monitoring", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> LIVE_MONITORING = new BooleanPreference("live_monitoring", false).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5000).makeProfile().makeGeneral();
public final CommonPreference<Integer> LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5000).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 900000).makeProfile().makeGeneral();
public final CommonPreference<Integer> LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 900000).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<String> LIVE_MONITORING_URL = new StringPreference("live_monitoring_url",
"https://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={4}&speed={5}").makeProfile().makeGeneral();
"https://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={4}&speed={5}").makeProfile();
public final CommonPreference<String> GPS_STATUS_APP = new StringPreference("gps_status_app", "").makeGlobal();
@ -1780,7 +1759,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Integer> MAP_SCREEN_ORIENTATION =
new IntPreference("map_screen_orientation", -1/*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/).makeProfile().makeGeneral();
new IntPreference("map_screen_orientation", -1/*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
// public final CommonPreference<Boolean> SHOW_VIEW_ANGLE = new BooleanPreference("show_view_angle", false).makeProfile().cache();
@ -1837,7 +1816,7 @@ public class OsmandSettings {
public static final int ROTATE_MAP_BEARING = 1;
public static final int ROTATE_MAP_COMPASS = 2;
public final CommonPreference<Integer> ROTATE_MAP =
new IntPreference("rotate_map", ROTATE_MAP_NONE).makeProfile().makeGeneral().cache();
new IntPreference("rotate_map", ROTATE_MAP_NONE).makeProfile().cache();
{
ROTATE_MAP.setModeDefaultValue(ApplicationMode.CAR, ROTATE_MAP_BEARING);
@ -1851,7 +1830,7 @@ public class OsmandSettings {
public static final int MIDDLE_BOTTOM_CONSTANT = 2;
public static final int MIDDLE_TOP_CONSTANT = 3;
public static final int LANDSCAPE_MIDDLE_RIGHT_CONSTANT = 4;
public final CommonPreference<Boolean> CENTER_POSITION_ON_MAP = new BooleanPreference("center_position_on_map", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> CENTER_POSITION_ON_MAP = new BooleanPreference("center_position_on_map", false).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Integer> MAX_LEVEL_TO_DOWNLOAD_TILE = new IntPreference("max_level_download_tile", 20).makeProfile().cache();
@ -1949,7 +1928,7 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> ANIMATE_MY_LOCATION = new BooleanPreference("animate_my_location", true).makeProfile().cache();
public final OsmandPreference<Integer> EXTERNAL_INPUT_DEVICE = new IntPreference("external_input_device", 0).makeProfile().makeGeneral();
public final OsmandPreference<Integer> EXTERNAL_INPUT_DEVICE = new IntPreference("external_input_device", 0).makeProfile();
public final OsmandPreference<Boolean> ROUTE_MAP_MARKERS_START_MY_LOC = new BooleanPreference("route_map_markers_start_my_loc", false).makeGlobal().cache();
public final OsmandPreference<Boolean> ROUTE_MAP_MARKERS_ROUND_TRIP = new BooleanPreference("route_map_markers_round_trip", false).makeGlobal().cache();
@ -3097,7 +3076,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> CONTRIBUTION_INSTALL_APP_DATE = new StringPreference("CONTRIBUTION_INSTALL_APP_DATE", null).makeGlobal();
public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeProfile().makeGeneral();
public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeProfile();
public final OsmandPreference<Boolean> FOLLOW_THE_ROUTE = new BooleanPreference("follow_to_route", false).makeGlobal();
public final OsmandPreference<String> FOLLOW_THE_GPX_ROUTE = new StringPreference("follow_gpx", null).makeGlobal();
@ -3163,7 +3142,7 @@ public class OsmandSettings {
new IntPreference("FAVORITES_TAB", 0).makeGlobal().cache();
public final CommonPreference<Integer> OSMAND_THEME =
new IntPreference("osmand_theme", OSMAND_LIGHT_THEME).makeProfile().makeGeneral().cache();
new IntPreference("osmand_theme", OSMAND_LIGHT_THEME).makeProfile().cache();
public boolean isLightActionBar() {
return isLightContent();

View file

@ -293,7 +293,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
settings.setSharedGeneralPreference(prefId, newValue);
settings.setPreferenceForAllModes(prefId, newValue);
} else {
settings.setPreference(prefId, newValue);
}

View file

@ -54,7 +54,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
app.getSettings().setSharedGeneralPreference(prefId, newValue);
app.getSettings().setPreferenceForAllModes(prefId, newValue);
updateTargetSettings(false);
dismiss();
}