From 80c7ff949c65d1482ceb3d22fc1827fb7f68fc33 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Wed, 18 Dec 2024 18:23:47 +0100 Subject: [PATCH] refactoring --- .../DevelopmentSettingsFragment.java | 26 ++++--------------- .../ShowableSearchablePreferenceDialog.java | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/settings/fragments/search/ShowableSearchablePreferenceDialog.java diff --git a/OsmAnd/src/net/osmand/plus/plugins/development/DevelopmentSettingsFragment.java b/OsmAnd/src/net/osmand/plus/plugins/development/DevelopmentSettingsFragment.java index 3e530f110b1..07a82caa33b 100644 --- a/OsmAnd/src/net/osmand/plus/plugins/development/DevelopmentSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/plugins/development/DevelopmentSettingsFragment.java @@ -9,7 +9,6 @@ import android.os.Debug; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; @@ -26,6 +25,7 @@ import net.osmand.plus.settings.fragments.BaseSettingsFragment; 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.preferences.SwitchPreferenceEx; import net.osmand.plus.simulation.OsmAndLocationSimulation; import net.osmand.plus.simulation.SimulateLocationFragment; @@ -316,17 +316,6 @@ private void setupResetToDefaultButton() { resetToDefault.setIcon(getActiveIcon(R.drawable.ic_action_reset_to_default_dark)); } - private static abstract class ShowableSearchablePreferenceDialog { - - public final T searchablePreferenceDialog; - - public ShowableSearchablePreferenceDialog(final T searchablePreferenceDialog) { - this.searchablePreferenceDialog = searchablePreferenceDialog; - } - - public abstract void show(); - } - @Override public boolean onPreferenceClick(Preference preference) { String prefId = preference.getKey(); @@ -372,7 +361,7 @@ private Optional> createPreferenceDialog(f false)) { @Override - public void show() { + public void show(final SearchablePreferenceDialog searchablePreferenceDialog) { final FragmentActivity activity = getActivity(); if (activity != null) { searchablePreferenceDialog.show(activity.getSupportFragmentManager(), app); @@ -388,9 +377,8 @@ public void show() { target, getSelectedAppMode())) { - // FK-TODO: refactor @Override - public void show() { + public void show(final SearchablePreferenceDialog searchablePreferenceDialog) { final FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager != null) { searchablePreferenceDialog.show(fragmentManager, app); @@ -407,7 +395,7 @@ public void show() { getSelectedAppMode())) { @Override - public void show() { + public void show(final SearchablePreferenceDialog searchablePreferenceDialog) { final FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager != null) { searchablePreferenceDialog.show(fragmentManager, app); @@ -422,11 +410,7 @@ public void show() { public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { return this .createPreferenceDialog(preference, null) - .map(showableSearchablePreferenceDialog -> showableSearchablePreferenceDialog.searchablePreferenceDialog) - .map(searchablePreferenceDialog -> - new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>( - searchablePreferenceDialog, - _preferenceDialog -> searchablePreferenceDialog.getSearchableInfo())); + .map(ShowableSearchablePreferenceDialog::asPreferenceDialogAndSearchableInfoByPreferenceDialogProvider); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/search/ShowableSearchablePreferenceDialog.java b/OsmAnd/src/net/osmand/plus/settings/fragments/search/ShowableSearchablePreferenceDialog.java new file mode 100644 index 00000000000..d415d1e8a51 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/search/ShowableSearchablePreferenceDialog.java @@ -0,0 +1,26 @@ +package net.osmand.plus.settings.fragments.search; + +import androidx.fragment.app.Fragment; + +import de.KnollFrank.lib.settingssearch.provider.PreferenceDialogAndSearchableInfoByPreferenceDialogProvider; + +public abstract class ShowableSearchablePreferenceDialog { + + public final T searchablePreferenceDialog; + + public ShowableSearchablePreferenceDialog(final T searchablePreferenceDialog) { + this.searchablePreferenceDialog = searchablePreferenceDialog; + } + + public void show() { + show(searchablePreferenceDialog); + } + + public PreferenceDialogAndSearchableInfoByPreferenceDialogProvider asPreferenceDialogAndSearchableInfoByPreferenceDialogProvider() { + return new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>( + searchablePreferenceDialog, + SearchablePreferenceDialog::getSearchableInfo); + } + + protected abstract void show(final SearchablePreferenceDialog searchablePreferenceDialog); +}