diff --git a/OsmAnd/build-common.gradle b/OsmAnd/build-common.gradle index bd2901633e2..c097a1633f7 100644 --- a/OsmAnd/build-common.gradle +++ b/OsmAnd/build-common.gradle @@ -394,7 +394,7 @@ dependencies { implementation "androidx.car.app:app-projected:1.4.0" implementation 'com.google.android.gms:play-services-location:21.3.0' - implementation 'com.github.KnollFrank:SettingsSearch:17e42c2fde' + implementation 'com.github.KnollFrank:SettingsSearch:b30144e8c4' // https://mvnrepository.com/artifact/com.google.guava/guava implementation 'com.google.guava:guava:33.3.1-android' diff --git a/OsmAnd/res/values-ast/strings.xml b/OsmAnd/res/values-ast/strings.xml index 6e8f9ce9b16..fd9b5052d0f 100644 --- a/OsmAnd/res/values-ast/strings.xml +++ b/OsmAnd/res/values-ast/strings.xml @@ -3692,7 +3692,7 @@ Arrive at destination Turn Time and distance intervals - The anouncement timing of different voice prompts depends on prompt type, current navigation speed, and default navigation speed. + The announcement timing of different voice prompts depends on prompt type, current navigation speed, and default navigation speed. Announcement time Start recording Show track on map diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 57fdb7b6219..cac51ae3f72 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2029,7 +2029,7 @@ You need to activate the sensor so OsmAnd can find it. Show track on map Start recording Announcement time - The anouncement timing of different voice prompts depends on prompt type, current navigation speed, and default navigation speed. + The announcement timing of different voice prompts depends on prompt type, current navigation speed, and default navigation speed. Time and distance intervals Turn Arrive at destination diff --git a/OsmAnd/src/net/osmand/plus/plugins/development/DevelopmentSettingsFragment.java b/OsmAnd/src/net/osmand/plus/plugins/development/DevelopmentSettingsFragment.java index 71a81cf83a9..18698728ad6 100644 --- a/OsmAnd/src/net/osmand/plus/plugins/development/DevelopmentSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/plugins/development/DevelopmentSettingsFragment.java @@ -406,7 +406,7 @@ public void show() { } @Override - public Optional getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { + public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { return this .createPreferenceDialog(preference, null) .map(showableSearchablePreferenceDialog -> showableSearchablePreferenceDialog.searchablePreferenceDialog) diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java index 45f729033bd..c82df3af3fb 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/AnnouncementTimeBottomSheet.java @@ -1,5 +1,7 @@ package net.osmand.plus.settings.bottomsheets; +import static net.osmand.plus.settings.bottomsheets.SingleSelectPreferenceBottomSheet.SELECTED_ENTRY_INDEX_KEY; + import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; @@ -9,6 +11,7 @@ import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import androidx.preference.Preference; import com.google.android.material.slider.Slider; import com.google.android.material.slider.Slider.OnChangeListener; @@ -16,22 +19,20 @@ import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.utils.UiUtilities; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem.Builder; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.routing.data.AnnounceTimeDistances; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.fragments.OnPreferenceChanged; +import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog; import net.osmand.plus.settings.preferences.ListPreferenceEx; +import net.osmand.plus.utils.UiUtilities; import net.osmand.plus.widgets.TextViewEx; import org.apache.commons.logging.Log; -import static net.osmand.plus.settings.bottomsheets.SingleSelectPreferenceBottomSheet.SELECTED_ENTRY_INDEX_KEY; - - -public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet { +public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet implements SearchablePreferenceDialog { public static final String TAG = AnnouncementTimeBottomSheet.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(AnnouncementTimeBottomSheet.class); @@ -43,7 +44,6 @@ public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet { private int selectedEntryIndex = -1; private TextViewEx tvSeekBarLabel; - private Slider slider; private ImageView ivArrow; private TextViewEx tvIntervalsDescr; @@ -116,7 +116,7 @@ private BaseBottomSheetItem createBottomSheetItem() { .inflate(R.layout.bottom_sheet_announcement_time, null); tvSeekBarLabel = rootView.findViewById(R.id.tv_seek_bar_label); - slider = rootView.findViewById(R.id.arrival_slider); + Slider slider = rootView.findViewById(R.id.arrival_slider); ivArrow = rootView.findViewById(R.id.iv_arrow); tvIntervalsDescr = rootView.findViewById(R.id.tv_interval_descr); int appModeColor = getAppMode().getProfileColor(nightMode); @@ -161,21 +161,42 @@ private void toggleDescriptionVisibility() { AndroidUiHelper.updateVisibility(tvIntervalsDescr, !collapsed); } - public static void showInstance(@NonNull FragmentManager fm, String prefKey, Fragment target, - @Nullable ApplicationMode appMode, boolean usedOnMap) { + @NonNull + public static AnnouncementTimeBottomSheet createInstance(final Preference preference, + final Fragment target, + final @Nullable ApplicationMode appMode, + final boolean usedOnMap) { + final Bundle args = new Bundle(); + args.putString(PREFERENCE_ID, preference.getKey()); + final AnnouncementTimeBottomSheet fragment = new AnnouncementTimeBottomSheet(); + fragment.setArguments(args); + fragment.setAppMode(appMode); + fragment.setUsedOnMap(usedOnMap); + fragment.setTargetFragment(target, 0); + if (target == null) { + fragment.setPreference(preference); + } + return fragment; + } + + @Override + public void show(final FragmentManager fragmentManager, final OsmandApplication app) { try { - if (!fm.isStateSaved()) { - Bundle args = new Bundle(); - args.putString(PREFERENCE_ID, prefKey); - AnnouncementTimeBottomSheet fragment = new AnnouncementTimeBottomSheet(); - fragment.setArguments(args); - fragment.setAppMode(appMode); - fragment.setUsedOnMap(usedOnMap); - fragment.setTargetFragment(target, 0); - fragment.show(fm, TAG); + if (!fragmentManager.isStateSaved()) { + show(fragmentManager, TAG); } - } catch (RuntimeException e) { + } catch (final RuntimeException e) { LOG.error("showInstance", e); } } + + @Override + public String getSearchableInfo() { + return String.join( + ", ", + getString(R.string.announcement_time_title), + getString(R.string.announcement_time_descr), + getString(R.string.announcement_time_intervals), + tvIntervalsDescr.getText()); + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java index be4ea73ccfb..5284cdf9514 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java @@ -37,17 +37,15 @@ import net.osmand.plus.settings.enums.AngularConstants; import net.osmand.plus.settings.enums.CompassMode; import net.osmand.plus.settings.enums.DrivingRegion; +import net.osmand.plus.settings.enums.VolumeUnit; import net.osmand.plus.settings.fragments.search.PreferenceFragmentHandler; import net.osmand.plus.settings.fragments.search.PreferenceFragmentHandlerProvider; import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog; import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialogProvider; -import net.osmand.plus.settings.enums.VolumeUnit; -import net.osmand.router.GeneralRouter; -import net.osmand.shared.settings.enums.MetricsConstants; -import net.osmand.shared.settings.enums.SpeedConstants; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import net.osmand.plus.utils.UiUtilities; +import net.osmand.router.GeneralRouter; import net.osmand.shared.settings.enums.MetricsConstants; import net.osmand.shared.settings.enums.SpeedConstants; @@ -511,7 +509,7 @@ private void show(final SearchablePreferenceDialog dialog) { } @Override - public Optional getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { + public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { return this .createPreferenceDialog(preference, null, Optional.of(preference)) .map(preferenceDialog -> diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java index 36f76a53c89..822d5a909c5 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java @@ -83,13 +83,6 @@ public void onDisplayPreferenceDialog(Preference preference) { } } - private void show(final SearchablePreferenceDialog dialog) { - final FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - dialog.show(fragmentManager, app); - } - } - private Optional createPreferenceDialog(final Preference preference, final GlobalSettingsFragment target) { return SEND_ANONYMOUS_DATA_PREF_ID.equals(preference.getKey()) ? @@ -97,8 +90,15 @@ private Optional createPreferenceDialog(final Prefer Optional.empty(); } + private void show(final SearchablePreferenceDialog dialog) { + final FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + dialog.show(fragmentManager, app); + } + } + @Override - public Optional getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { + public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { return this .createPreferenceDialog(preference, null) .map(preferenceDialog -> diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java index 28fc38a154b..8c523962ef8 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java @@ -329,7 +329,7 @@ private Optional createPreferenceDialog( } @Override - public Optional getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { + public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { if (DEFAULT_SPEED.equals(preference.getKey())) { return Optional.of( new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>( diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/profileappearance/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/profileappearance/ProfileAppearanceFragment.java index 5ead698adac..e8f4facd3ba 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/profileappearance/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/profileappearance/ProfileAppearanceFragment.java @@ -241,7 +241,7 @@ public boolean onPreferenceClick(Preference preference) { } @Override - public Optional getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { + public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { return this .createPreferenceDialog(preference) .map(preferenceDialog -> diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/search/PreferenceDialogAndSearchableInfoProvider.java b/OsmAnd/src/net/osmand/plus/settings/fragments/search/PreferenceDialogAndSearchableInfoProvider.java index 5acb961c285..6ea4c03cd76 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/search/PreferenceDialogAndSearchableInfoProvider.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/search/PreferenceDialogAndSearchableInfoProvider.java @@ -10,7 +10,7 @@ class PreferenceDialogAndSearchableInfoProvider implements de.KnollFrank.lib.settingssearch.provider.PreferenceDialogAndSearchableInfoProvider { @Override - public Optional getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider( + public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider( final Preference preference, final PreferenceFragmentCompat hostOfPreference) { // FK-TODO: handle more preference dialogs, which shall be searchable diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/search/SearchablePreferenceDialogProvider.java b/OsmAnd/src/net/osmand/plus/settings/fragments/search/SearchablePreferenceDialogProvider.java index 3173aecc7cf..4b0f0694b03 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/search/SearchablePreferenceDialogProvider.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/search/SearchablePreferenceDialogProvider.java @@ -8,5 +8,5 @@ public interface SearchablePreferenceDialogProvider { - Optional getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference); + Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference 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 0e834b84c42..08097f1368b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/voice/VoiceAnnouncesFragment.java @@ -12,6 +12,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; @@ -25,16 +26,22 @@ import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.bottomsheets.AnnouncementTimeBottomSheet; import net.osmand.plus.settings.bottomsheets.SpeedLimitBottomSheet; -import net.osmand.shared.settings.enums.SpeedConstants; import net.osmand.plus.settings.fragments.ApplyQueryType; import net.osmand.plus.settings.fragments.BaseSettingsFragment; +import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog; +import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialogProvider; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.utils.AndroidUtils; import net.osmand.plus.utils.ColorUtilities; import net.osmand.plus.utils.OsmAndFormatter; import net.osmand.plus.utils.UiUtilities; +import net.osmand.shared.settings.enums.SpeedConstants; + +import java.util.Optional; + +import de.KnollFrank.lib.settingssearch.provider.PreferenceDialogAndSearchableInfoByPreferenceDialogProvider; -public class VoiceAnnouncesFragment extends BaseSettingsFragment { +public class VoiceAnnouncesFragment extends BaseSettingsFragment implements SearchablePreferenceDialogProvider { public static final String TAG = VoiceAnnouncesFragment.class.getSimpleName(); @@ -248,19 +255,36 @@ public boolean onPreferenceClick(Preference preference) { @Override public void onDisplayPreferenceDialog(Preference preference) { - String prefId = preference.getKey(); - if (settings.ARRIVAL_DISTANCE_FACTOR.getId().equals(prefId)) { - FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - AnnouncementTimeBottomSheet.showInstance(fragmentManager, preference.getKey(), this, getSelectedAppMode(), false); - } - } else if (settings.VOICE_PROVIDER.getId().equals(prefId)) { + 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); } } + private Optional createSearchablePreferenceDialog( + final Preference preference, + final VoiceAnnouncesFragment target) { + return settings.ARRIVAL_DISTANCE_FACTOR.getId().equals(preference.getKey()) ? + Optional.of( + AnnouncementTimeBottomSheet.createInstance( + preference, + target, + getSelectedAppMode(), + false)) : + Optional.empty(); + } + + private void show(final SearchablePreferenceDialog dialog) { + final FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + dialog.show(fragmentManager, app); + } + } + @Override public void onPreferenceChanged(@NonNull String prefId) { if (prefId.equals(settings.SPEED_CAMERAS_UNINSTALLED.getId())) { @@ -276,4 +300,13 @@ private void setupSpeakCamerasPref() { showCameras.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get()); } + @Override + public Optional> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) { + return this + .createSearchablePreferenceDialog(preference, null) + .map(preferenceDialog -> + new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>( + (Fragment) preferenceDialog, + _preferenceDialog -> preferenceDialog.getSearchableInfo())); + } } diff --git a/OsmAnd/src/net/osmand/plus/simulation/SimulateLocationFragment.java b/OsmAnd/src/net/osmand/plus/simulation/SimulateLocationFragment.java index 35e5a076c4b..e0abe85bec6 100644 --- a/OsmAnd/src/net/osmand/plus/simulation/SimulateLocationFragment.java +++ b/OsmAnd/src/net/osmand/plus/simulation/SimulateLocationFragment.java @@ -303,7 +303,7 @@ public void show(final FragmentManager fragmentManager, final OsmandApplication public String getSearchableInfo() { return String.join( ", ", - getView().findViewById(R.id.title).getText(), + requireView().findViewById(R.id.title).getText(), getTitle(trackItem), getTitle(speedItem), getTitle(startItem)); diff --git a/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchTest.java b/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchTest.java index d3e40d63c3f..f0795bc5123 100644 --- a/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchTest.java +++ b/OsmAnd/test/java/net/osmand/plus/settings/fragments/search/SettingsSearchTest.java @@ -76,8 +76,25 @@ public void shouldSearchAndFindSpeedCameraSettings4EachApplicationMode() { @Test public void shouldSearchAndFindRecalculateRoutePreference() { + testSearchAndFind("Recalculate route"); + } + + @Test + public void test_search_within_AnnouncementTimeBottomSheet_title() { + testSearchAndFind(R.string.announcement_time_title); + } + + @Test + public void test_search_within_AnnouncementTimeBottomSheet_description() { + testSearchAndFind(R.string.announcement_time_descr); + } + + private void testSearchAndFind(final int id) { + testSearchAndFind(app.getResources().getString(id)); + } + + private void testSearchAndFind(final String searchQuery) { // Given - final String searchQuery = "Recalculate route"; clickSearchButton(); // When