From 0747499d6fa2b9c7ba1203b4fe3b1a82ce35f079 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Thu, 19 Dec 2024 09:33:25 +0100 Subject: [PATCH] refactoring VoiceAnnouncesFragment --- ...rchablePreferenceDialogFragmentHolder.java | 14 ----- .../voice/VoiceAnnouncesFragment.java | 58 ++++++++----------- 2 files changed, 25 insertions(+), 47 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/settings/fragments/SearchablePreferenceDialogFragmentHolder.java diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/SearchablePreferenceDialogFragmentHolder.java b/OsmAnd/src/net/osmand/plus/settings/fragments/SearchablePreferenceDialogFragmentHolder.java deleted file mode 100644 index b026a273026..00000000000 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/SearchablePreferenceDialogFragmentHolder.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.osmand.plus.settings.fragments; - -import androidx.fragment.app.Fragment; - -import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog; - -// FK-TODO: remove -public record SearchablePreferenceDialogFragmentHolder( - T searchablePreferenceDialogFragment) { - - public static SearchablePreferenceDialogFragmentHolder of(final T searchablePreferenceDialogFragment) { - return new SearchablePreferenceDialogFragmentHolder<>(searchablePreferenceDialogFragment); - } -} diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java index a639a185331..88725099e53 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.settings.fragments.voice; +import static net.osmand.plus.settings.fragments.search.PreferenceDialogs.showDialogForPreference; import static net.osmand.plus.utils.UiUtilities.CompoundButtonType.TOOLBAR; import android.graphics.drawable.ColorDrawable; @@ -12,6 +13,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; @@ -27,9 +29,9 @@ import net.osmand.plus.settings.bottomsheets.SpeedLimitBottomSheet; import net.osmand.plus.settings.fragments.ApplyQueryType; import net.osmand.plus.settings.fragments.BaseSettingsFragment; -import net.osmand.plus.settings.fragments.SearchablePreferenceDialogFragmentHolder; 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.utils.AndroidUtils; import net.osmand.plus.utils.ColorUtilities; @@ -39,9 +41,7 @@ import java.util.Optional; -import de.KnollFrank.lib.settingssearch.provider.PreferenceDialogAndSearchableInfoByPreferenceDialogProvider; - -public class VoiceAnnouncesFragment extends BaseSettingsFragment implements SearchablePreferenceDialogProvider { +public class VoiceAnnouncesFragment extends BaseSettingsFragment implements ShowableSearchablePreferenceDialogProvider { public static final String TAG = VoiceAnnouncesFragment.class.getSimpleName(); @@ -254,32 +254,35 @@ public boolean onPreferenceClick(Preference preference) { } @Override - public void onDisplayPreferenceDialog(Preference preference) { - this - .createSearchablePreferenceDialog(preference, this) - .map(SearchablePreferenceDialogFragmentHolder::searchablePreferenceDialogFragment) - .ifPresentOrElse( - this::show, - () -> { - if (settings.VOICE_PROVIDER.getId().equals(preference.getKey())) { - VoiceLanguageBottomSheetFragment.showInstance(requireActivity().getSupportFragmentManager(), this, getSelectedAppMode(), false); - } else { - super.onDisplayPreferenceDialog(preference); - } - }); + public void onDisplayPreferenceDialog(final Preference preference) { + if (showDialogForPreference(preference, this)) { + return; + } + if (settings.VOICE_PROVIDER.getId().equals(preference.getKey())) { + VoiceLanguageBottomSheetFragment.showInstance(requireActivity().getSupportFragmentManager(), this, getSelectedAppMode(), false); + return; + } + super.onDisplayPreferenceDialog(preference); } - private Optional> createSearchablePreferenceDialog( + @Override + public Optional> getShowableSearchablePreferenceDialog( final Preference preference, - final VoiceAnnouncesFragment target) { + final Fragment target) { return settings.ARRIVAL_DISTANCE_FACTOR.getId().equals(preference.getKey()) ? Optional.of( - SearchablePreferenceDialogFragmentHolder.of( + new ShowableSearchablePreferenceDialog<>( AnnouncementTimeBottomSheet.createInstance( preference, target, getSelectedAppMode(), - false))) : + false)) { + + @Override + protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) { + VoiceAnnouncesFragment.this.show(searchablePreferenceDialog); + } + }) : Optional.empty(); } @@ -304,15 +307,4 @@ private void setupSpeakCamerasPref() { SwitchPreferenceCompat showCameras = findPreference(settings.SPEAK_SPEED_CAMERA.getId()); showCameras.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get()); } - - @Override - public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { - return this - .createSearchablePreferenceDialog(preference, null) - .map(SearchablePreferenceDialogFragmentHolder::searchablePreferenceDialogFragment) - .map(preferenceDialog -> - new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>( - preferenceDialog, - _preferenceDialog -> preferenceDialog.getSearchableInfo())); - } }