Skip to content

Commit

Permalink
refactoring VoiceAnnouncesFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Dec 19, 2024
1 parent c129d34 commit 0747499
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 47 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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<SearchablePreferenceDialogFragmentHolder<?>> createSearchablePreferenceDialog(
@Override
public Optional<ShowableSearchablePreferenceDialog<?>> 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();
}

Expand All @@ -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<PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<?>> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) {
return this
.createSearchablePreferenceDialog(preference, null)
.map(SearchablePreferenceDialogFragmentHolder::searchablePreferenceDialogFragment)
.map(preferenceDialog ->
new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>(
preferenceDialog,
_preferenceDialog -> preferenceDialog.getSearchableInfo()));
}
}

0 comments on commit 0747499

Please sign in to comment.