Merge pull request #7770 from osmandapp/preferences_fixes

Preferences fixes
This commit is contained in:
max-klaus 2019-10-28 17:48:54 +03:00 committed by GitHub
commit 11dffc4028
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 77 additions and 69 deletions

View file

@ -4,14 +4,16 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:layout_height="wrap_content"
android:background="?attr/actionModeBackground"
android:minHeight="@dimen/toolbar_height"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageButton
android:id="@+id/close_button"
@ -24,8 +26,7 @@
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?attr/app_bar_primary_item_color"

View file

@ -32,8 +32,7 @@
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?attr/app_bar_primary_item_color"

View file

@ -28,9 +28,8 @@
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/toolbar_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"

View file

@ -33,9 +33,8 @@
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/toolbar_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"

View file

@ -33,9 +33,8 @@
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/toolbar_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"

View file

@ -33,6 +33,7 @@ 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.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -122,7 +123,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
}
private Drawable getOsmandThemeIcon() {
return getIcon(settings.isLightContent() ? R.drawable.ic_action_sun : R.drawable.ic_action_moon);
return getContentIcon(settings.isLightContent() ? R.drawable.ic_action_sun : R.drawable.ic_action_moon);
}
private void setupRotateMapPref() {
@ -135,11 +136,11 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
private Drawable getRotateMapIcon() {
switch (settings.ROTATE_MAP.get()) {
case OsmandSettings.ROTATE_MAP_NONE:
return getIcon(R.drawable.ic_action_direction_north);
return getContentIcon(R.drawable.ic_action_direction_north);
case OsmandSettings.ROTATE_MAP_BEARING:
return getIcon(R.drawable.ic_action_direction_movement);
return getContentIcon(R.drawable.ic_action_direction_movement);
default:
return getIcon(R.drawable.ic_action_direction_compass);
return getContentIcon(R.drawable.ic_action_direction_compass);
}
}
@ -163,11 +164,11 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
private Drawable getMapScreenOrientationIcon() {
switch (settings.MAP_SCREEN_ORIENTATION.get()) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
return getIcon(R.drawable.ic_action_phone_portrait_orientation);
return getContentIcon(R.drawable.ic_action_phone_portrait_orientation);
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
return getIcon(R.drawable.ic_action_phone_landscape_orientation);
return getContentIcon(R.drawable.ic_action_phone_landscape_orientation);
default:
return getIcon(R.drawable.ic_action_phone_device_orientation);
return getContentIcon(R.drawable.ic_action_phone_device_orientation);
}
}
@ -190,7 +191,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
ListPreferenceEx unitsOfLength = (ListPreferenceEx) findPreference(settings.METRIC_SYSTEM.getId());
unitsOfLength.setEntries(entries);
unitsOfLength.setEntryValues(entryValues);
unitsOfLength.setIcon(getIcon(R.drawable.ic_action_ruler_unit));
unitsOfLength.setIcon(getContentIcon(R.drawable.ic_action_ruler_unit));
}
private void setupCoordinatesFormatPref() {
@ -220,7 +221,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
ListPreferenceEx angularUnits = (ListPreferenceEx) findPreference(settings.ANGULAR_UNITS.getId());
angularUnits.setEntries(entries);
angularUnits.setEntryValues(entryValues);
angularUnits.setIcon(getIcon(R.drawable.ic_action_angular_unit));
angularUnits.setIcon(getContentIcon(R.drawable.ic_action_angular_unit));
}
private void setupSpeedSystemPref() {
@ -358,8 +359,8 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
if (pref instanceof CommonPreference && !((CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId, newValue, this, false);
if (fragmentManager != null && newValue instanceof Serializable) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId, (Serializable) newValue, this, false);
}
return false;
}

View file

@ -62,7 +62,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
private void setupManageProfilesPref() {
Preference manageProfiles = findPreference("manage_profiles");
manageProfiles.setIcon(getIcon(R.drawable.ic_action_manage_profiles));
manageProfiles.setIcon(getContentIcon(R.drawable.ic_action_manage_profiles));
manageProfiles.setFragment(SettingsProfileFragment.class.getName());
}

View file

@ -28,6 +28,7 @@ public class ProxySettingsFragment extends BaseSettingsFragment {
setupProxyHostPref();
setupProxyPortPref();
enableDisablePreferences(settings.ENABLE_PROXY.get());
}
@Override

View file

@ -284,7 +284,7 @@ public class RouteParametersFragment extends BaseSettingsFragment {
private Drawable getRoutingPrefIcon(String prefId) {
switch (prefId) {
case GeneralRouter.ALLOW_PRIVATE:
return getIcon(R.drawable.ic_action_private_access);
return getContentIcon(R.drawable.ic_action_private_access);
case GeneralRouter.USE_SHORTEST_WAY:
return getContentIcon(R.drawable.ic_action_fuel);
case AVOID_ROUTING_PARAMETER_PREFIX:
@ -292,7 +292,7 @@ public class RouteParametersFragment extends BaseSettingsFragment {
case DRIVING_STYLE:
return getContentIcon(R.drawable.ic_action_bicycle_dark);
case "fast_route_mode":
return getIcon(R.drawable.ic_action_fastest_route);
return getContentIcon(R.drawable.ic_action_fastest_route);
case "enable_time_conditional_routing":
return getContentIcon(R.drawable.ic_action_road_works_dark);
default:

View file

@ -38,6 +38,7 @@ public class ScreenAlertsFragment extends BaseSettingsFragment {
showTunnels.setIcon(getIcon(R.drawable.list_warnings_tunnel));
setupScreenAlertsImage();
enableDisablePreferences(settings.SHOW_ROUTING_ALARMS.get());
}
@Override

View file

@ -24,6 +24,7 @@ public class TurnScreenOnFragment extends BaseSettingsFragment {
setupTurnScreenOnTimePref();
setupTurnScreenOnSensorPref();
enableDisablePreferences(settings.TURN_SCREEN_ON_ENABLED.get());
}
@Override

View file

@ -112,11 +112,11 @@ public class VehicleParametersFragment extends BaseSettingsFragment {
case GeneralRouter.DEFAULT_SPEED:
return getContentIcon(R.drawable.ic_action_speed);
case GeneralRouter.VEHICLE_HEIGHT:
return getIcon(R.drawable.ic_action_height_limit);
return getContentIcon(R.drawable.ic_action_height_limit);
case GeneralRouter.VEHICLE_WEIGHT:
return getIcon(R.drawable.ic_action_weight_limit);
return getContentIcon(R.drawable.ic_action_weight_limit);
case GeneralRouter.VEHICLE_WIDTH:
return getIcon(R.drawable.ic_action_width_limit);
return getContentIcon(R.drawable.ic_action_width_limit);
default:
return null;
}

View file

@ -18,22 +18,30 @@ import net.osmand.plus.settings.BaseSettingsFragment;
import org.apache.commons.logging.Log;
import java.io.Serializable;
public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSheet {
public static final String TAG = ChangeGeneralProfilesPrefBottomSheet.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(ChangeGeneralProfilesPrefBottomSheet.class);
private Object newValue;
private static final String NEW_VALUE_KEY = "new_value_key";
private Serializable newValue;
@Override
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
Bundle args = getArguments();
if (app == null || args == null || newValue == null || !args.containsKey(PREFERENCE_ID)) {
if (app == null || args == null) {
return;
}
final String prefId = args.getString(PREFERENCE_ID);
newValue = args.getSerializable(NEW_VALUE_KEY);
if (newValue == null || prefId == null) {
return;
}
items.add(new TitleItem(getString(R.string.change_default_settings)));
items.add(new LongDescriptionItem(getString(R.string.apply_preference_to_all_profiles)));
@ -90,6 +98,12 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
return true;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(NEW_VALUE_KEY, newValue);
}
private void updateTargetSettings() {
BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment();
if (target != null) {
@ -97,16 +111,16 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
}
}
public static void showInstance(@NonNull FragmentManager fm, String prefId, Object newValue, Fragment target, boolean usedOnMap) {
public static void showInstance(@NonNull FragmentManager fm, String prefId, Serializable newValue, Fragment target, boolean usedOnMap) {
try {
if (fm.findFragmentByTag(ChangeGeneralProfilesPrefBottomSheet.TAG) == null) {
Bundle args = new Bundle();
args.putString(PREFERENCE_ID, prefId);
args.putSerializable(NEW_VALUE_KEY, newValue);
ChangeGeneralProfilesPrefBottomSheet fragment = new ChangeGeneralProfilesPrefBottomSheet();
fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap);
fragment.newValue = newValue;
fragment.setTargetFragment(target, 0);
fragment.show(fm, ChangeGeneralProfilesPrefBottomSheet.TAG);
}

View file

@ -41,36 +41,14 @@ public class MultiSelectPreferencesBottomSheet extends BasePreferenceBottomSheet
private boolean prefChanged;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
multiSelectBooleanPreference = getListPreference();
if (savedInstanceState == null) {
if (multiSelectBooleanPreference.getEntries() == null || multiSelectBooleanPreference.getPrefsIds() == null) {
LOG.error("MultiSelectListPreference requires an entries array and an entryValues array.");
return;
}
enabledPrefs.clear();
enabledPrefs.addAll(multiSelectBooleanPreference.getValues());
prefChanged = false;
entries = multiSelectBooleanPreference.getEntries();
prefsIds = multiSelectBooleanPreference.getPrefsIds();
} else {
enabledPrefs.clear();
enabledPrefs.addAll(savedInstanceState.getStringArrayList(ENABLED_PREFERENCES_IDS));
prefChanged = savedInstanceState.getBoolean(PREFERENCE_CHANGED, false);
entries = savedInstanceState.getCharSequenceArray(PREFERENCES_ENTRIES);
prefsIds = savedInstanceState.getStringArray(PREFERENCES_IDS);
}
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
if (app == null || multiSelectBooleanPreference == null || prefsIds == null || entries == null) {
multiSelectBooleanPreference = getListPreference();
if (app == null || multiSelectBooleanPreference == null) {
return;
}
readSavedState(savedInstanceState);
String title = multiSelectBooleanPreference.getDialogTitle().toString();
items.add(new TitleItem(title));
@ -151,6 +129,26 @@ public class MultiSelectPreferencesBottomSheet extends BasePreferenceBottomSheet
return (MultiSelectBooleanPreference) getPreference();
}
private void readSavedState(Bundle savedInstanceState) {
if (savedInstanceState == null) {
if (multiSelectBooleanPreference.getEntries() == null || multiSelectBooleanPreference.getPrefsIds() == null) {
LOG.error("MultiSelectListPreference requires an entries array and an entryValues array.");
return;
}
enabledPrefs.clear();
enabledPrefs.addAll(multiSelectBooleanPreference.getValues());
prefChanged = false;
entries = multiSelectBooleanPreference.getEntries();
prefsIds = multiSelectBooleanPreference.getPrefsIds();
} else {
enabledPrefs.clear();
enabledPrefs.addAll(savedInstanceState.getStringArrayList(ENABLED_PREFERENCES_IDS));
prefChanged = savedInstanceState.getBoolean(PREFERENCE_CHANGED, false);
entries = savedInstanceState.getCharSequenceArray(PREFERENCES_ENTRIES);
prefsIds = savedInstanceState.getStringArray(PREFERENCES_IDS);
}
}
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String prefId, Fragment target, boolean usedOnMap) {
try {
Bundle args = new Bundle();

View file

@ -27,23 +27,18 @@ public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet
private int selectedEntryIndex = -1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listPreference = getListPreference();
if (savedInstanceState != null) {
selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY);
} else if (listPreference != null) {
selectedEntryIndex = listPreference.findIndexOfValue(listPreference.getValue());
}
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
Context ctx = getContext();
listPreference = getListPreference();
if (ctx == null || listPreference == null || listPreference.getEntries() == null || listPreference.getEntryValues() == null) {
return;
}
if (savedInstanceState != null) {
selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY);
} else {
selectedEntryIndex = listPreference.findIndexOfValue(listPreference.getValue());
}
String title = listPreference.getDialogTitle().toString();
items.add(new TitleItem(title));