Fix #7849
This commit is contained in:
parent
c2d19b7b76
commit
0b150971f6
5 changed files with 69 additions and 20 deletions
|
@ -2,15 +2,7 @@
|
|||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:title="@string/coordinates_format">
|
||||
|
||||
<Preference
|
||||
android:key="coordinates_format_info"
|
||||
android:layout="@layout/preference_info"
|
||||
android:persistent="false"
|
||||
android:selectable="false"
|
||||
android:title="@string/coordinates_format_info"
|
||||
tools:icon="@drawable/ic_action_info_dark" />
|
||||
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="format_degrees"
|
||||
android:layout="@layout/preference_radio_button"
|
||||
|
|
|
@ -428,6 +428,17 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
updatePreferencesScreen();
|
||||
}
|
||||
|
||||
public boolean shouldDismissOnChange() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.getSupportFragmentManager().popBackStack();
|
||||
}
|
||||
}
|
||||
|
||||
protected void enableDisablePreferences(boolean enable) {
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen != null) {
|
||||
|
|
|
@ -39,9 +39,6 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
|
|||
|
||||
@Override
|
||||
protected void setupPreferences() {
|
||||
Preference generalSettings = findPreference("coordinates_format_info");
|
||||
generalSettings.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
|
||||
|
||||
CheckBoxPreference degreesPref = (CheckBoxPreference) findPreference(FORMAT_DEGREES);
|
||||
CheckBoxPreference minutesPref = (CheckBoxPreference) findPreference(FORMAT_MINUTES);
|
||||
CheckBoxPreference secondsPref = (CheckBoxPreference) findPreference(FORMAT_SECONDS);
|
||||
|
@ -132,6 +129,11 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDismissOnChange() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateSelectedFormatPrefs(String key) {
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen != null) {
|
||||
|
|
|
@ -1,24 +1,38 @@
|
|||
package net.osmand.plus.settings.bottomsheets;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.preference.DialogPreference.TargetFragment;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String PREFERENCE_ID = "preference_id";
|
||||
|
||||
private String prefId;
|
||||
private Preference preference;
|
||||
|
||||
public String getPrefId() {
|
||||
if (prefId == null) {
|
||||
Bundle args = getArguments();
|
||||
if (args != null && args.containsKey(PREFERENCE_ID)) {
|
||||
prefId = args.getString(PREFERENCE_ID);
|
||||
}
|
||||
}
|
||||
return prefId;
|
||||
}
|
||||
|
||||
public Preference getPreference() {
|
||||
if (preference == null) {
|
||||
Bundle args = getArguments();
|
||||
if (args != null && args.containsKey(PREFERENCE_ID)) {
|
||||
String prefId = args.getString(PREFERENCE_ID);
|
||||
String prefId = getPrefId();
|
||||
if (prefId != null) {
|
||||
TargetFragment targetFragment = (TargetFragment) getTargetFragment();
|
||||
|
||||
if (targetFragment != null) {
|
||||
preference = targetFragment.findPreference(prefId);
|
||||
}
|
||||
|
@ -26,4 +40,21 @@ public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFra
|
|||
}
|
||||
return preference;
|
||||
}
|
||||
|
||||
public boolean shouldDismissOnChange() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static BasePreferenceBottomSheet findPreferenceBottomSheet(@NonNull FragmentManager manager, @NonNull String prefId) {
|
||||
List<Fragment> fragments = manager.getFragments();
|
||||
for (Fragment fragment : fragments) {
|
||||
if (fragment instanceof BasePreferenceBottomSheet) {
|
||||
BasePreferenceBottomSheet bottomSheet = (BasePreferenceBottomSheet) fragment;
|
||||
if (prefId.equals(bottomSheet.getPrefId())) {
|
||||
return bottomSheet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
app.getSettings().setSharedGeneralPreference(prefId, newValue);
|
||||
updateTargetSettings();
|
||||
updateTargetSettings(false);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
|
@ -71,7 +71,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
app.getSettings().setPreference(prefId, newValue);
|
||||
updateTargetSettings();
|
||||
updateTargetSettings(false);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
|
@ -85,7 +85,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
updateTargetSettings();
|
||||
updateTargetSettings(true);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
|
@ -104,10 +104,23 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
outState.putSerializable(NEW_VALUE_KEY, newValue);
|
||||
}
|
||||
|
||||
private void updateTargetSettings() {
|
||||
private void updateTargetSettings(boolean discard) {
|
||||
BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment();
|
||||
if (target != null) {
|
||||
target.updateAllSettings();
|
||||
if (!discard) {
|
||||
if (target.shouldDismissOnChange()) {
|
||||
target.dismiss();
|
||||
}
|
||||
FragmentManager manager = getFragmentManager();
|
||||
if (manager != null) {
|
||||
BasePreferenceBottomSheet preferenceBottomSheet =
|
||||
BasePreferenceBottomSheet.findPreferenceBottomSheet(manager, getPrefId());
|
||||
if (preferenceBottomSheet != null && preferenceBottomSheet.shouldDismissOnChange()) {
|
||||
preferenceBottomSheet.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue