From 0b150971f6f5f66cc3d79cf92f7214cb14008348 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Wed, 6 Nov 2019 17:30:00 +0300 Subject: [PATCH] Fix #7849 --- OsmAnd/res/xml/coordinates_format.xml | 10 +---- .../plus/settings/BaseSettingsFragment.java | 11 ++++++ .../settings/CoordinatesFormatFragment.java | 8 ++-- .../BasePreferenceBottomSheet.java | 39 +++++++++++++++++-- .../ChangeGeneralProfilesPrefBottomSheet.java | 21 ++++++++-- 5 files changed, 69 insertions(+), 20 deletions(-) diff --git a/OsmAnd/res/xml/coordinates_format.xml b/OsmAnd/res/xml/coordinates_format.xml index db722783f8..083f42182b 100644 --- a/OsmAnd/res/xml/coordinates_format.xml +++ b/OsmAnd/res/xml/coordinates_format.xml @@ -2,15 +2,7 @@ - - - + fragments = manager.getFragments(); + for (Fragment fragment : fragments) { + if (fragment instanceof BasePreferenceBottomSheet) { + BasePreferenceBottomSheet bottomSheet = (BasePreferenceBottomSheet) fragment; + if (prefId.equals(bottomSheet.getPrefId())) { + return bottomSheet; + } + } + } + return null; + } } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java index ba9e39aa50..b336b668b4 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java @@ -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(); + } + } + } } }