diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java index ab4e887a4f0..2823401520a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java @@ -376,6 +376,14 @@ protected void displayPreferenceDialog(@NonNull String prefKey) { @Override public void onDisplayPreferenceDialog(Preference preference) { + if (this instanceof ShowableSearchablePreferenceDialogProvider showableSearchablePreferenceDialogProvider) { + final Optional> preferenceDialog = showableSearchablePreferenceDialogProvider.getShowableSearchablePreferenceDialog(preference, this); + if (preferenceDialog.isPresent()) { + preferenceDialog.get().show(); + return; + } + } + FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager == null) { return; diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java index 4d677a5bcd5..e09fad24fef 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java @@ -34,18 +34,17 @@ import net.osmand.plus.settings.datastorage.item.StorageItem; import net.osmand.plus.settings.enums.LocationSource; import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog; -import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialogProvider; +import net.osmand.plus.settings.fragments.search.ShowableSearchablePreferenceDialog; +import net.osmand.plus.settings.fragments.search.ShowableSearchablePreferenceDialogProvider; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import java.util.Map; import java.util.Optional; -import de.KnollFrank.lib.settingssearch.provider.PreferenceDialogAndSearchableInfoByPreferenceDialogProvider; - public class GlobalSettingsFragment extends BaseSettingsFragment - implements OnSendAnalyticsPrefsUpdate, OnSelectProfileCallback, SearchablePreferenceDialogProvider { + implements OnSendAnalyticsPrefsUpdate, OnSelectProfileCallback, ShowableSearchablePreferenceDialogProvider { public static final String TAG = GlobalSettingsFragment.class.getSimpleName(); @@ -74,38 +73,22 @@ protected void setupPreferences() { } @Override - public void onDisplayPreferenceDialog(Preference preference) { - this - .createPreferenceDialog(preference, this) - .ifPresentOrElse( - this::show, - () -> super.onDisplayPreferenceDialog(preference)); - } - - private Optional createPreferenceDialog(final Preference preference, - final GlobalSettingsFragment target) { + public Optional> getShowableSearchablePreferenceDialog(final Preference preference, final Fragment target) { return SEND_ANONYMOUS_DATA_PREF_ID.equals(preference.getKey()) ? - Optional.of(SendAnalyticsBottomSheetDialogFragment.createInstance(target)) : + Optional.of( + new ShowableSearchablePreferenceDialog<>(SendAnalyticsBottomSheetDialogFragment.createInstance(target)) { + + @Override + protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) { + final FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + searchablePreferenceDialog.show(fragmentManager, app); + } + } + }) : Optional.empty(); } - private void show(final SearchablePreferenceDialog dialog) { - final FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - dialog.show(fragmentManager, app); - } - } - - @Override - public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { - return this - .createPreferenceDialog(preference, null) - .map(preferenceDialog -> - new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>( - (Fragment) preferenceDialog, - _preferenceDialog -> preferenceDialog.getSearchableInfo())); - } - @Override protected void onBindPreferenceViewHolder(@NonNull Preference preference, @NonNull PreferenceViewHolder holder) { diff --git a/OsmAnd/src/net/osmand/plus/settings/preferences/SwitchPreferenceEx.java b/OsmAnd/src/net/osmand/plus/settings/preferences/SwitchPreferenceEx.java index 78fe0875820..0527b4a8dad 100644 --- a/OsmAnd/src/net/osmand/plus/settings/preferences/SwitchPreferenceEx.java +++ b/OsmAnd/src/net/osmand/plus/settings/preferences/SwitchPreferenceEx.java @@ -44,13 +44,6 @@ public void setDescription(int titleResId) { setDescription(getContext().getString(titleResId)); } - @Override - protected void onClick() { - if (getFragment() == null && getIntent() == null) { - getPreferenceManager().showDialog(this); - } - } - @Override public String getSearchableInfo() { return Optionals diff --git a/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchParameterizedTest.java b/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchParameterizedTest.java index 65fa49b7075..ad53372312a 100644 --- a/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchParameterizedTest.java +++ b/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchParameterizedTest.java @@ -57,6 +57,8 @@ public static Iterable data() { {"GoodsRestrictionsBottomSheet: goods_delivery_desc_3", R.string.goods_delivery_desc_3}, {"GoodsRestrictionsBottomSheet: goods_delivery_desc_4", R.string.goods_delivery_desc_4}, + {"SendAnalyticsBottomSheetDialogFragment: description", R.string.make_osmand_better_descr}, + // FK-TODO: enable development plugin for these two test cases // {"LocationInterpolationBottomSheet: title", R.string.location_interpolation_percent}, // {"LocationInterpolationBottomSheet: description", R.string.location_interpolation_percent_desc}