From cc05f3185139a8f1a8bb785a315506196beda4a1 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Sun, 15 Dec 2024 03:25:15 +0100 Subject: [PATCH] refactoring --- .../fragments/GlobalSettingsFragment.java | 11 +++++------ .../fragments/VehicleParametersFragment.java | 5 +---- .../voice/VoiceAnnouncesFragment.java | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java index 822d5a909c5..4d677a5bcd5 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java @@ -75,12 +75,11 @@ protected void setupPreferences() { @Override public void onDisplayPreferenceDialog(Preference preference) { - final Optional preferenceDialog = createPreferenceDialog(preference, this); - if (preferenceDialog.isPresent()) { - show(preferenceDialog.get()); - } else { - super.onDisplayPreferenceDialog(preference); - } + this + .createPreferenceDialog(preference, this) + .ifPresentOrElse( + this::show, + () -> super.onDisplayPreferenceDialog(preference)); } private Optional createPreferenceDialog(final Preference preference, diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java index dccaaedff93..ad5acd96f34 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java @@ -272,10 +272,7 @@ public boolean onPreferenceClick(Preference preference) { @Override public void onDisplayPreferenceDialog(Preference preference) { this - .createPreferenceDialog( - preference, - this, - false) + .createPreferenceDialog(preference, this, false) .ifPresentOrElse( this::show, () -> super.onDisplayPreferenceDialog(preference)); 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 08097f1368b..820c0de8352 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java @@ -255,14 +255,17 @@ public boolean onPreferenceClick(Preference preference) { @Override public void onDisplayPreferenceDialog(Preference preference) { - final Optional searchablePreferenceDialog = createSearchablePreferenceDialog(preference, this); - if (searchablePreferenceDialog.isPresent()) { - show(searchablePreferenceDialog.get()); - } else if (settings.VOICE_PROVIDER.getId().equals(preference.getKey())) { - VoiceLanguageBottomSheetFragment.showInstance(requireActivity().getSupportFragmentManager(), this, getSelectedAppMode(), false); - } else { - super.onDisplayPreferenceDialog(preference); - } + this + .createSearchablePreferenceDialog(preference, this) + .ifPresentOrElse( + this::show, + () -> { + if (settings.VOICE_PROVIDER.getId().equals(preference.getKey())) { + VoiceLanguageBottomSheetFragment.showInstance(requireActivity().getSupportFragmentManager(), this, getSelectedAppMode(), false); + } else { + super.onDisplayPreferenceDialog(preference); + } + }); } private Optional createSearchablePreferenceDialog(