From 423a330af2b75cb90b939ca030aca71bcbc16ce3 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Thu, 19 Dec 2024 22:36:37 +0100 Subject: [PATCH] making VoiceLanguageBottomSheetFragment searchable --- .../MapRouteInfoMenu.java | 5 +- .../RouteOptionsBottomSheet.java | 5 +- .../voice/VoiceAnnouncesFragment.java | 49 ++++++++++++------- .../VoiceLanguageBottomSheetFragment.java | 42 ++++++++++++---- .../SettingsSearchParameterizedTest.java | 6 ++- 5 files changed, 73 insertions(+), 34 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 61e4f7ede8c..e16b1a9790c 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -1212,8 +1212,9 @@ private void createMuteSoundRoutingParameterButton(MapActivity mapActivity, OsmandApplication app = getApp(); if (app != null) { if (app.getSettings().isVoiceProviderNotSelected(appMode)) { - VoiceLanguageBottomSheetFragment.showInstance(mapActivity.getSupportFragmentManager(), - null, appMode, true); + VoiceLanguageBottomSheetFragment + .createInstance(null, appMode, true) + .show(mapActivity.getSupportFragmentManager(), app); } else { app.getRoutingOptionsHelper().switchSound(); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 45abd96e6f3..fb06412f525 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -319,8 +319,9 @@ public void onClick(View v) { routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active); String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(applicationMode); if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { - VoiceLanguageBottomSheetFragment.showInstance(mapActivity.getSupportFragmentManager(), - RouteOptionsBottomSheet.this, applicationMode, usedOnMap); + VoiceLanguageBottomSheetFragment + .createInstance(RouteOptionsBottomSheet.this, applicationMode, usedOnMap) + .show(mapActivity.getSupportFragmentManager(), app); } else { cb.setChecked(!active); icon.setImageDrawable(getPaintedContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())); 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 88725099e53..92cb0932841 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java @@ -258,10 +258,6 @@ 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); } @@ -269,21 +265,36 @@ public void onDisplayPreferenceDialog(final Preference preference) { public Optional> getShowableSearchablePreferenceDialog( final Preference preference, final Fragment target) { - return settings.ARRIVAL_DISTANCE_FACTOR.getId().equals(preference.getKey()) ? - Optional.of( - new ShowableSearchablePreferenceDialog<>( - AnnouncementTimeBottomSheet.createInstance( - preference, - target, - getSelectedAppMode(), - false)) { - - @Override - protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) { - VoiceAnnouncesFragment.this.show(searchablePreferenceDialog); - } - }) : - Optional.empty(); + if (settings.ARRIVAL_DISTANCE_FACTOR.getId().equals(preference.getKey())) { + return Optional.of( + new ShowableSearchablePreferenceDialog<>( + AnnouncementTimeBottomSheet.createInstance( + preference, + target, + getSelectedAppMode(), + false)) { + + @Override + protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) { + VoiceAnnouncesFragment.this.show(searchablePreferenceDialog); + } + }); + } + if (settings.VOICE_PROVIDER.getId().equals(preference.getKey())) { + return Optional.of( + new ShowableSearchablePreferenceDialog<>( + VoiceLanguageBottomSheetFragment.createInstance( + target, + getSelectedAppMode(), + false)) { + + @Override + protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) { + searchablePreferenceDialog.show(requireActivity().getSupportFragmentManager(), app); + } + }); + } + return Optional.empty(); } private void show(final SearchablePreferenceDialog dialog) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceLanguageBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceLanguageBottomSheetFragment.java index 295a74ff12e..1e682dccaf7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceLanguageBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceLanguageBottomSheetFragment.java @@ -31,6 +31,7 @@ import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet; import net.osmand.plus.settings.fragments.OnPreferenceChanged; +import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog; import net.osmand.plus.settings.fragments.voice.VoiceItemsAdapter.VoiceItemsListener; import net.osmand.plus.track.fragments.TrackSelectSegmentBottomSheet; import net.osmand.plus.utils.AndroidUtils; @@ -40,8 +41,10 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; -public class VoiceLanguageBottomSheetFragment extends BasePreferenceBottomSheet implements DownloadEvents, VoiceItemsListener { +public class VoiceLanguageBottomSheetFragment extends BasePreferenceBottomSheet implements DownloadEvents, VoiceItemsListener, SearchablePreferenceDialog { private static final String TAG = TrackSelectSegmentBottomSheet.class.getSimpleName(); @@ -256,15 +259,34 @@ private void addVoiceItem(@NonNull List items, @NonNull VoiceType voi } } - public static void showInstance(@NonNull FragmentManager manager, @Nullable Fragment target, - @Nullable ApplicationMode appMode, boolean usedOnMap) { - if (AndroidUtils.isFragmentCanBeAdded(manager, TAG)) { - VoiceLanguageBottomSheetFragment fragment = new VoiceLanguageBottomSheetFragment(); - fragment.setRetainInstance(true); - fragment.setAppMode(appMode); - fragment.setUsedOnMap(usedOnMap); - fragment.setTargetFragment(target, 0); - fragment.show(manager, TAG); + public static VoiceLanguageBottomSheetFragment createInstance(final @Nullable Fragment target, + final @Nullable ApplicationMode appMode, + final boolean usedOnMap) { + VoiceLanguageBottomSheetFragment fragment = new VoiceLanguageBottomSheetFragment(); + fragment.setRetainInstance(true); + fragment.setAppMode(appMode); + fragment.setUsedOnMap(usedOnMap); + fragment.setTargetFragment(target, 0); + return fragment; + } + + @Override + public void show(final FragmentManager fragmentManager, final OsmandApplication app) { + if (AndroidUtils.isFragmentCanBeAdded(fragmentManager, TAG)) { + show(fragmentManager, TAG); } } + + @Override + public String getSearchableInfo() { + return Stream + .of( + R.string.language_description, + VoiceType.TTS.titleRes, + VoiceType.TTS.descriptionRes, + VoiceType.RECORDED.titleRes, + VoiceType.RECORDED.descriptionRes) + .map(this::getString) + .collect(Collectors.joining(", ")); + } } \ No newline at end of file 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 f199cbac7e8..29120e8d5e1 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 @@ -77,7 +77,11 @@ public static Iterable data() { {"DistanceDuringNavigationBottomSheet: description", searchQuery("Choose how distance information is displayed in navigation widgets")}, - {"VehicleParametersFragment: SimpleSingleSelectionBottomSheet, description", searchQuery(R.string.routing_attr_motor_type_description)} + {"VehicleParametersFragment: SimpleSingleSelectionBottomSheet, description", searchQuery(R.string.routing_attr_motor_type_description)}, + + {"VoiceLanguageBottomSheetFragment: language_description", searchQuery(R.string.language_description)}, + {"VoiceLanguageBottomSheetFragment: tts_description", searchQuery(R.string.tts_description)}, + {"VoiceLanguageBottomSheetFragment: recorded_description", searchQuery(R.string.recorded_description)}, }); }