diff --git a/app/metrics.yaml b/app/metrics.yaml index 07f68b043..a8290fb3c 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -106,7 +106,7 @@ events: extra_keys: preference_key: description: "The preference key for the switch preference the user toggled. We currently track: - show_search_suggestions, show_visited_sites_bookmarks, remote_debugging, telemetry, tracking_protection" + show_search_suggestions, remote_debugging, telemetry, tracking_protection" enabled: description: "Whether or not the preference is *now* enabled" bugs: diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt index 4aa09d800..b45d9957d 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt @@ -107,7 +107,6 @@ sealed class Event { data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() { private val switchPreferenceTelemetryAllowList = listOf( context.getString(R.string.pref_key_show_search_suggestions), - context.getString(R.string.pref_key_show_visited_sites_bookmarks), context.getString(R.string.pref_key_remote_debugging), context.getString(R.string.pref_key_telemetry), context.getString(R.string.pref_key_tracking_protection) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt index efaac3f7f..f6c3025f0 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt @@ -21,9 +21,9 @@ import mozilla.components.lib.publicsuffixlist.PublicSuffixList import mozilla.components.support.base.feature.LifecycleAwareFeature import mozilla.components.support.ktx.android.view.hideKeyboard import org.mozilla.fenix.R -import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.nav +import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.utils.Settings class ToolbarIntegration( @@ -90,7 +90,7 @@ class ToolbarIntegration( ToolbarAutocompleteFeature(toolbar).apply { addDomainProvider(domainAutocompleteProvider) - if (Settings.getInstance(context).shouldShowVisitedSitesBookmarks) { + if (Settings.getInstance(context).shouldShowHistorySuggestions) { addHistoryStorageProvider(historyStorage) } } diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt index 7949ea6e4..3a0d56d22 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt @@ -91,8 +91,10 @@ class SearchFragment : Fragment(), BackHandler { showShortcutEnginePicker = displayShortcutEnginePicker, searchEngineSource = currentSearchEngine, defaultEngineSource = currentSearchEngine, - showSuggestions = Settings.getInstance(requireContext()).showSearchSuggestions, - showVisitedSitesBookmarks = Settings.getInstance(requireContext()).shouldShowVisitedSitesBookmarks, + showSearchSuggestions = Settings.getInstance(requireContext()).shouldShowSearchSuggestions, + showClipboardSuggestions = Settings.getInstance(requireContext()).shouldShowClipboardSuggestions, + showHistorySuggestions = Settings.getInstance(requireContext()).shouldShowHistorySuggestions, + showBookmarkSuggestions = Settings.getInstance(requireContext()).shouldShowBookmarkSuggestions, session = session ) ) @@ -290,7 +292,7 @@ class SearchFragment : Fragment(), BackHandler { } private fun historyStorageProvider(): HistoryStorage? { - return if (Settings.getInstance(requireContext()).shouldShowVisitedSitesBookmarks) { + return if (Settings.getInstance(requireContext()).shouldShowHistorySuggestions) { requireComponents.core.historyStorage } else null } diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt b/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt index 540e106b9..c69cfb522 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt @@ -36,8 +36,10 @@ sealed class SearchEngineSource { * @property showShortcutEnginePicker Whether or not to show the available search engine view * @property searchEngineSource The current selected search engine with the context of how it was selected * @property defaultEngineSource The current default search engine source - * @property showSuggestions Whether or not to show search suggestions for the selected search engine in the AwesomeBar - * @property showVisitedSitesBookmarks Whether or not to show history and bookmark suggestions in the AwesomeBar + * @property showSearchSuggestions Whether or not to show search suggestions from the search engine in the AwesomeBar + * @property showClipboardSuggestions Whether or not to show clipboard suggestion in the AwesomeBar + * @property showHistorySuggestions Whether or not to show history suggestions in the AwesomeBar + * @property showBookmarkSuggestions Whether or not to show the bookmark suggestion in the AwesomeBar * @property session The current session if available */ data class SearchFragmentState( @@ -45,8 +47,10 @@ data class SearchFragmentState( val showShortcutEnginePicker: Boolean, val searchEngineSource: SearchEngineSource, val defaultEngineSource: SearchEngineSource.Default, - val showSuggestions: Boolean, - val showVisitedSitesBookmarks: Boolean, + val showSearchSuggestions: Boolean, + val showClipboardSuggestions: Boolean, + val showHistorySuggestions: Boolean, + val showBookmarkSuggestions: Boolean, val session: Session? ) : State diff --git a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt index 42c6335ab..1c3448136 100644 --- a/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt +++ b/app/src/main/java/org/mozilla/fenix/search/awesomebar/AwesomeBarView.kt @@ -171,26 +171,35 @@ class AwesomeBarView( } } + @SuppressWarnings("ComplexMethod") fun update(state: SearchFragmentState) { view.removeAllProviders() if (state.showShortcutEnginePicker) { view.addProviders(shortcutsEnginePickerProvider) } else { - if (state.showSuggestions) { - view.addProviders(when (state.searchEngineSource) { - is SearchEngineSource.Default -> defaultSearchSuggestionProvider - is SearchEngineSource.Shortcut -> createSuggestionProviderForEngine( - state.searchEngineSource.searchEngine - ) - }) + if (state.showSearchSuggestions) { + view.addProviders( + when (state.searchEngineSource) { + is SearchEngineSource.Default -> defaultSearchSuggestionProvider + is SearchEngineSource.Shortcut -> createSuggestionProviderForEngine( + state.searchEngineSource.searchEngine + ) + } + ) } - if (state.showVisitedSitesBookmarks) { - view.addProviders(bookmarksStorageSuggestionProvider, historyStorageProvider) + if (state.showClipboardSuggestions) { + view.addProviders(clipboardSuggestionProvider) } - view.addProviders(clipboardSuggestionProvider) + if (state.showHistorySuggestions) { + view.addProviders(historyStorageProvider) + } + + if (state.showBookmarkSuggestions) { + view.addProviders(bookmarksStorageSuggestionProvider) + } if ((container.context.asActivity() as? HomeActivity)?.browsingModeManager?.mode?.isPrivate == false) { view.addProviders(sessionProvider) diff --git a/app/src/main/java/org/mozilla/fenix/settings/SearchEngineFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SearchEngineFragment.kt index 766f33568..a795a7863 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SearchEngineFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SearchEngineFragment.kt @@ -25,16 +25,28 @@ class SearchEngineFragment : PreferenceFragmentCompat() { val searchSuggestionsPreference = findPreference(getPreferenceKey(R.string.pref_key_show_search_suggestions))?.apply { - isChecked = Settings.getInstance(context).showSearchSuggestions + isChecked = Settings.getInstance(context).shouldShowSearchSuggestions } searchSuggestionsPreference?.onPreferenceChangeListener = SharedPreferenceUpdater() - val showVisitedSitesBookmarks = - findPreference(getPreferenceKey(R.string.pref_key_show_visited_sites_bookmarks))?.apply { - isChecked = Settings.getInstance(context).shouldShowVisitedSitesBookmarks + val showHistorySuggestions = + findPreference(getPreferenceKey(R.string.pref_key_search_browsing_history))?.apply { + isChecked = Settings.getInstance(context).shouldShowHistorySuggestions } - showVisitedSitesBookmarks?.onPreferenceChangeListener = SharedPreferenceUpdater() + val showBookmarkSuggestions = + findPreference(getPreferenceKey(R.string.pref_key_search_bookmarks))?.apply { + isChecked = Settings.getInstance(context).shouldShowBookmarkSuggestions + } + + val showClipboardSuggestions = + findPreference(getPreferenceKey(R.string.pref_key_show_clipboard_suggestions))?.apply { + isChecked = Settings.getInstance(context).shouldShowClipboardSuggestions + } + + showHistorySuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater() + showBookmarkSuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater() + showClipboardSuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater() } } diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 057cba83b..d0e594d37 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -117,8 +117,18 @@ class Settings private constructor( .putFloat(appContext.getPreferenceKey(R.string.pref_key_accessibility_font_scale), value) .apply() - val shouldShowVisitedSitesBookmarks by booleanPreference( - appContext.getPreferenceKey(R.string.pref_key_show_visited_sites_bookmarks), + val shouldShowHistorySuggestions by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_search_browsing_history), + default = true + ) + + val shouldShowBookmarkSuggestions by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_search_bookmarks), + default = true + ) + + val shouldShowClipboardSuggestions by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_show_clipboard_suggestions), default = true ) @@ -162,7 +172,7 @@ class Settings private constructor( ).apply() } - val showSearchSuggestions by booleanPreference( + val shouldShowSearchSuggestions by booleanPreference( appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions), default = true ) diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index da1a71a8d..c1d8890f1 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -54,7 +54,9 @@ pref_key_show_search_suggestions - pref_key_show_visited_sites_bookmarks + pref_key_show_clipboard_suggestions + pref_key_search_browsing_history + pref_key_search_bookmarks pref_key_optimize diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7f27693e5..b0a954949 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -117,8 +117,6 @@ About Search engine - - Show visited sites and bookmarks Help @@ -172,6 +170,12 @@ Remote debugging via USB Show search suggestions + + Show clipboard suggestions + + Search browsing history + + Search bookmarks Account settings diff --git a/app/src/main/res/xml/search_engine_preferences.xml b/app/src/main/res/xml/search_engine_preferences.xml index 48edd4f37..fe19d5442 100644 --- a/app/src/main/res/xml/search_engine_preferences.xml +++ b/app/src/main/res/xml/search_engine_preferences.xml @@ -13,7 +13,17 @@ app:iconSpaceReserved="false" /> + + diff --git a/app/src/test/java/org/mozilla/fenix/search/SearchFragmentStoreTest.kt b/app/src/test/java/org/mozilla/fenix/search/SearchFragmentStoreTest.kt index f01e7724b..f95d5f33a 100644 --- a/app/src/test/java/org/mozilla/fenix/search/SearchFragmentStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/SearchFragmentStoreTest.kt @@ -50,8 +50,10 @@ class SearchFragmentStoreTest { searchEngineSource = mockk(), defaultEngineSource = mockk(), showShortcutEnginePicker = false, - showSuggestions = false, - showVisitedSitesBookmarks = false, + showSearchSuggestions = false, + showClipboardSuggestions = false, + showHistorySuggestions = false, + showBookmarkSuggestions = false, session = null ) } diff --git a/app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt b/app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt index a7901283e..2f1d509a3 100644 --- a/app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt +++ b/app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt @@ -175,10 +175,24 @@ class SettingsTest { } @Test - fun shouldShowVisitedSitesBookmarks() { + fun shouldShowClipboardSuggestion() { // When just created // Then - assertTrue(settings.shouldShowVisitedSitesBookmarks) + assertTrue(settings.shouldShowClipboardSuggestions) + } + + @Test + fun shouldShowHistorySuggestions() { + // When just created + // Then + assertTrue(settings.shouldShowHistorySuggestions) + } + + @Test + fun shouldShowBookmarkSuggestions() { + // When just created + // Then + assertTrue(settings.shouldShowBookmarkSuggestions) } @Test @@ -225,7 +239,7 @@ class SettingsTest { fun showSearchSuggestions() { // When just created // Then - assertTrue(settings.showSearchSuggestions) + assertTrue(settings.shouldShowSearchSuggestions) } @Test diff --git a/docs/metrics.md b/docs/metrics.md index aaab9fe4e..a5e55b80e 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -101,7 +101,7 @@ Private Tab, Share, Report Site Issue, Back/Forward button, Reload Button
preference_keyThe preference key for the switch preference the user toggled. We currently track: leakcanary, -make_default_browser, show_search_suggestions, show_visited_sites_bookmarks, remote_debugging, telemetry, +make_default_browser, show_search_suggestions, remote_debugging, telemetry, tracking_protection
enabledWhether or not the preference is now enabled