1
0
Fork 0

For #964: Adds ability to disable each suggestion provider (#5096)

* For #964: Adds ability to disable each suggestion provider

* Fix nit
master
Sawyer Blatz 2019-09-05 14:45:44 -07:00 committed by GitHub
parent ccd9e44a3e
commit 2653b5966e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 108 additions and 40 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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

View File

@ -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)

View File

@ -25,16 +25,28 @@ class SearchEngineFragment : PreferenceFragmentCompat() {
val searchSuggestionsPreference =
findPreference<SwitchPreference>(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<SwitchPreference>(getPreferenceKey(R.string.pref_key_show_visited_sites_bookmarks))?.apply {
isChecked = Settings.getInstance(context).shouldShowVisitedSitesBookmarks
val showHistorySuggestions =
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_search_browsing_history))?.apply {
isChecked = Settings.getInstance(context).shouldShowHistorySuggestions
}
showVisitedSitesBookmarks?.onPreferenceChangeListener = SharedPreferenceUpdater()
val showBookmarkSuggestions =
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_search_bookmarks))?.apply {
isChecked = Settings.getInstance(context).shouldShowBookmarkSuggestions
}
val showClipboardSuggestions =
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_show_clipboard_suggestions))?.apply {
isChecked = Settings.getInstance(context).shouldShowClipboardSuggestions
}
showHistorySuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater()
showBookmarkSuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater()
showClipboardSuggestions?.onPreferenceChangeListener = SharedPreferenceUpdater()
}
}

View File

@ -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
)

View File

@ -54,7 +54,9 @@
<!-- Search Settings -->
<string name="pref_key_show_search_suggestions" translatable="false">pref_key_show_search_suggestions</string>
<string name="pref_key_show_visited_sites_bookmarks" translatable="false">pref_key_show_visited_sites_bookmarks</string>
<string name="pref_key_show_clipboard_suggestions" translatable="false">pref_key_show_clipboard_suggestions</string>
<string name="pref_key_search_browsing_history" translatable="false">pref_key_search_browsing_history</string>
<string name="pref_key_search_bookmarks" translatable="false">pref_key_search_bookmarks</string>
<!-- Site Permissions Settings -->
<string name="pref_key_optimize" translatable="false">pref_key_optimize</string>

View File

@ -117,8 +117,6 @@
<string name="preferences_category_about">About</string>
<!-- Preference for settings related to changing the default search engine -->
<string name="preferences_search_engine">Search engine</string>
<!-- Preference for showing visited sites and bookmarks in awesomebar -->
<string name="preference_show_visited_sites_bookmarks">Show visited sites and bookmarks</string>
<!-- Preference linking to help about Fenix -->
<string name="preferences_help">Help</string>
<!-- Preference link to rating Fenix on the Play Store -->
@ -172,6 +170,12 @@
<string name="preferences_remote_debugging">Remote debugging via USB</string>
<!-- Preference title for switch preference to show search suggestions -->
<string name="preferences_show_search_suggestions">Show search suggestions</string>
<!-- Preference title for switch preference to show a clipboard suggestion when searching -->
<string name="preferences_show_clipboard_suggestions">Show clipboard suggestions</string>
<!-- Preference title for switch preference to suggest browsing history when searching -->
<string name="preferences_search_browsing_history">Search browsing history</string>
<!-- Preference title for switch preference to suggest bookmarks when searching -->
<string name="preferences_search_bookmarks">Search bookmarks</string>
<!-- Preference for account settings -->
<string name="preferences_account_settings">Account settings</string>

View File

@ -13,7 +13,17 @@
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_show_visited_sites_bookmarks"
android:title='@string/preference_show_visited_sites_bookmarks'
android:key="@string/pref_key_show_clipboard_suggestions"
android:title="@string/preferences_show_clipboard_suggestions"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_search_browsing_history"
android:title='@string/preferences_search_browsing_history'
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_search_bookmarks"
android:title='@string/preferences_search_bookmarks'
app:iconSpaceReserved="false" />
</PreferenceScreen>

View File

@ -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
)
}

View File

@ -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

View File

@ -101,7 +101,7 @@ Private Tab, Share, Report Site Issue, Back/Forward button, Reload Button</td></
<td>
<table>
<tr><td>preference_key</td><td>The 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</td>
</tr>
<tr><td>enabled</td><td>Whether or not the preference is <b>now</b> enabled</td></tr>