Skip to content

Commit

Permalink
making VoiceLanguageBottomSheetFragment searchable
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Dec 19, 2024
1 parent 60ecd27 commit 423a330
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,32 +258,43 @@ 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);
}

@Override
public Optional<ShowableSearchablePreferenceDialog<?>> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -256,15 +259,34 @@ private void addVoiceItem(@NonNull List<IndexItem> 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(", "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public static Iterable<Object[]> 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)},
});
}

Expand Down

0 comments on commit 423a330

Please sign in to comment.