* For #964: Adds ability to disable each suggestion provider * Fix nitmaster
parent
ccd9e44a3e
commit
2653b5966e
|
@ -106,7 +106,7 @@ events:
|
||||||
extra_keys:
|
extra_keys:
|
||||||
preference_key:
|
preference_key:
|
||||||
description: "The preference key for the switch preference the user toggled. We currently track:
|
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:
|
enabled:
|
||||||
description: "Whether or not the preference is *now* enabled"
|
description: "Whether or not the preference is *now* enabled"
|
||||||
bugs:
|
bugs:
|
||||||
|
|
|
@ -107,7 +107,6 @@ sealed class Event {
|
||||||
data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() {
|
data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() {
|
||||||
private val switchPreferenceTelemetryAllowList = listOf(
|
private val switchPreferenceTelemetryAllowList = listOf(
|
||||||
context.getString(R.string.pref_key_show_search_suggestions),
|
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_remote_debugging),
|
||||||
context.getString(R.string.pref_key_telemetry),
|
context.getString(R.string.pref_key_telemetry),
|
||||||
context.getString(R.string.pref_key_tracking_protection)
|
context.getString(R.string.pref_key_tracking_protection)
|
||||||
|
|
|
@ -21,9 +21,9 @@ import mozilla.components.lib.publicsuffixlist.PublicSuffixList
|
||||||
import mozilla.components.support.base.feature.LifecycleAwareFeature
|
import mozilla.components.support.base.feature.LifecycleAwareFeature
|
||||||
import mozilla.components.support.ktx.android.view.hideKeyboard
|
import mozilla.components.support.ktx.android.view.hideKeyboard
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.theme.ThemeManager
|
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.nav
|
||||||
|
import org.mozilla.fenix.theme.ThemeManager
|
||||||
import org.mozilla.fenix.utils.Settings
|
import org.mozilla.fenix.utils.Settings
|
||||||
|
|
||||||
class ToolbarIntegration(
|
class ToolbarIntegration(
|
||||||
|
@ -90,7 +90,7 @@ class ToolbarIntegration(
|
||||||
|
|
||||||
ToolbarAutocompleteFeature(toolbar).apply {
|
ToolbarAutocompleteFeature(toolbar).apply {
|
||||||
addDomainProvider(domainAutocompleteProvider)
|
addDomainProvider(domainAutocompleteProvider)
|
||||||
if (Settings.getInstance(context).shouldShowVisitedSitesBookmarks) {
|
if (Settings.getInstance(context).shouldShowHistorySuggestions) {
|
||||||
addHistoryStorageProvider(historyStorage)
|
addHistoryStorageProvider(historyStorage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,8 +91,10 @@ class SearchFragment : Fragment(), BackHandler {
|
||||||
showShortcutEnginePicker = displayShortcutEnginePicker,
|
showShortcutEnginePicker = displayShortcutEnginePicker,
|
||||||
searchEngineSource = currentSearchEngine,
|
searchEngineSource = currentSearchEngine,
|
||||||
defaultEngineSource = currentSearchEngine,
|
defaultEngineSource = currentSearchEngine,
|
||||||
showSuggestions = Settings.getInstance(requireContext()).showSearchSuggestions,
|
showSearchSuggestions = Settings.getInstance(requireContext()).shouldShowSearchSuggestions,
|
||||||
showVisitedSitesBookmarks = Settings.getInstance(requireContext()).shouldShowVisitedSitesBookmarks,
|
showClipboardSuggestions = Settings.getInstance(requireContext()).shouldShowClipboardSuggestions,
|
||||||
|
showHistorySuggestions = Settings.getInstance(requireContext()).shouldShowHistorySuggestions,
|
||||||
|
showBookmarkSuggestions = Settings.getInstance(requireContext()).shouldShowBookmarkSuggestions,
|
||||||
session = session
|
session = session
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -290,7 +292,7 @@ class SearchFragment : Fragment(), BackHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun historyStorageProvider(): HistoryStorage? {
|
private fun historyStorageProvider(): HistoryStorage? {
|
||||||
return if (Settings.getInstance(requireContext()).shouldShowVisitedSitesBookmarks) {
|
return if (Settings.getInstance(requireContext()).shouldShowHistorySuggestions) {
|
||||||
requireComponents.core.historyStorage
|
requireComponents.core.historyStorage
|
||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,10 @@ sealed class SearchEngineSource {
|
||||||
* @property showShortcutEnginePicker Whether or not to show the available search engine view
|
* @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 searchEngineSource The current selected search engine with the context of how it was selected
|
||||||
* @property defaultEngineSource The current default search engine source
|
* @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 showSearchSuggestions Whether or not to show search suggestions from the search engine in the AwesomeBar
|
||||||
* @property showVisitedSitesBookmarks Whether or not to show history and bookmark suggestions 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
|
* @property session The current session if available
|
||||||
*/
|
*/
|
||||||
data class SearchFragmentState(
|
data class SearchFragmentState(
|
||||||
|
@ -45,8 +47,10 @@ data class SearchFragmentState(
|
||||||
val showShortcutEnginePicker: Boolean,
|
val showShortcutEnginePicker: Boolean,
|
||||||
val searchEngineSource: SearchEngineSource,
|
val searchEngineSource: SearchEngineSource,
|
||||||
val defaultEngineSource: SearchEngineSource.Default,
|
val defaultEngineSource: SearchEngineSource.Default,
|
||||||
val showSuggestions: Boolean,
|
val showSearchSuggestions: Boolean,
|
||||||
val showVisitedSitesBookmarks: Boolean,
|
val showClipboardSuggestions: Boolean,
|
||||||
|
val showHistorySuggestions: Boolean,
|
||||||
|
val showBookmarkSuggestions: Boolean,
|
||||||
val session: Session?
|
val session: Session?
|
||||||
) : State
|
) : State
|
||||||
|
|
||||||
|
|
|
@ -171,26 +171,35 @@ class AwesomeBarView(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ComplexMethod")
|
||||||
fun update(state: SearchFragmentState) {
|
fun update(state: SearchFragmentState) {
|
||||||
view.removeAllProviders()
|
view.removeAllProviders()
|
||||||
|
|
||||||
if (state.showShortcutEnginePicker) {
|
if (state.showShortcutEnginePicker) {
|
||||||
view.addProviders(shortcutsEnginePickerProvider)
|
view.addProviders(shortcutsEnginePickerProvider)
|
||||||
} else {
|
} else {
|
||||||
if (state.showSuggestions) {
|
if (state.showSearchSuggestions) {
|
||||||
view.addProviders(when (state.searchEngineSource) {
|
view.addProviders(
|
||||||
is SearchEngineSource.Default -> defaultSearchSuggestionProvider
|
when (state.searchEngineSource) {
|
||||||
is SearchEngineSource.Shortcut -> createSuggestionProviderForEngine(
|
is SearchEngineSource.Default -> defaultSearchSuggestionProvider
|
||||||
state.searchEngineSource.searchEngine
|
is SearchEngineSource.Shortcut -> createSuggestionProviderForEngine(
|
||||||
)
|
state.searchEngineSource.searchEngine
|
||||||
})
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.showVisitedSitesBookmarks) {
|
if (state.showClipboardSuggestions) {
|
||||||
view.addProviders(bookmarksStorageSuggestionProvider, historyStorageProvider)
|
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) {
|
if ((container.context.asActivity() as? HomeActivity)?.browsingModeManager?.mode?.isPrivate == false) {
|
||||||
view.addProviders(sessionProvider)
|
view.addProviders(sessionProvider)
|
||||||
|
|
|
@ -25,16 +25,28 @@ class SearchEngineFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
val searchSuggestionsPreference =
|
val searchSuggestionsPreference =
|
||||||
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_show_search_suggestions))?.apply {
|
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_show_search_suggestions))?.apply {
|
||||||
isChecked = Settings.getInstance(context).showSearchSuggestions
|
isChecked = Settings.getInstance(context).shouldShowSearchSuggestions
|
||||||
}
|
}
|
||||||
|
|
||||||
searchSuggestionsPreference?.onPreferenceChangeListener = SharedPreferenceUpdater()
|
searchSuggestionsPreference?.onPreferenceChangeListener = SharedPreferenceUpdater()
|
||||||
|
|
||||||
val showVisitedSitesBookmarks =
|
val showHistorySuggestions =
|
||||||
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_show_visited_sites_bookmarks))?.apply {
|
findPreference<SwitchPreference>(getPreferenceKey(R.string.pref_key_search_browsing_history))?.apply {
|
||||||
isChecked = Settings.getInstance(context).shouldShowVisitedSitesBookmarks
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,8 +117,18 @@ class Settings private constructor(
|
||||||
.putFloat(appContext.getPreferenceKey(R.string.pref_key_accessibility_font_scale), value)
|
.putFloat(appContext.getPreferenceKey(R.string.pref_key_accessibility_font_scale), value)
|
||||||
.apply()
|
.apply()
|
||||||
|
|
||||||
val shouldShowVisitedSitesBookmarks by booleanPreference(
|
val shouldShowHistorySuggestions by booleanPreference(
|
||||||
appContext.getPreferenceKey(R.string.pref_key_show_visited_sites_bookmarks),
|
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
|
default = true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -162,7 +172,7 @@ class Settings private constructor(
|
||||||
).apply()
|
).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
val showSearchSuggestions by booleanPreference(
|
val shouldShowSearchSuggestions by booleanPreference(
|
||||||
appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions),
|
appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions),
|
||||||
default = true
|
default = true
|
||||||
)
|
)
|
||||||
|
|
|
@ -54,7 +54,9 @@
|
||||||
|
|
||||||
<!-- Search Settings -->
|
<!-- Search Settings -->
|
||||||
<string name="pref_key_show_search_suggestions" translatable="false">pref_key_show_search_suggestions</string>
|
<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 -->
|
<!-- Site Permissions Settings -->
|
||||||
<string name="pref_key_optimize" translatable="false">pref_key_optimize</string>
|
<string name="pref_key_optimize" translatable="false">pref_key_optimize</string>
|
||||||
|
|
|
@ -117,8 +117,6 @@
|
||||||
<string name="preferences_category_about">About</string>
|
<string name="preferences_category_about">About</string>
|
||||||
<!-- Preference for settings related to changing the default search engine -->
|
<!-- Preference for settings related to changing the default search engine -->
|
||||||
<string name="preferences_search_engine">Search engine</string>
|
<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 -->
|
<!-- Preference linking to help about Fenix -->
|
||||||
<string name="preferences_help">Help</string>
|
<string name="preferences_help">Help</string>
|
||||||
<!-- Preference link to rating Fenix on the Play Store -->
|
<!-- Preference link to rating Fenix on the Play Store -->
|
||||||
|
@ -172,6 +170,12 @@
|
||||||
<string name="preferences_remote_debugging">Remote debugging via USB</string>
|
<string name="preferences_remote_debugging">Remote debugging via USB</string>
|
||||||
<!-- Preference title for switch preference to show search suggestions -->
|
<!-- Preference title for switch preference to show search suggestions -->
|
||||||
<string name="preferences_show_search_suggestions">Show search suggestions</string>
|
<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 -->
|
<!-- Preference for account settings -->
|
||||||
<string name="preferences_account_settings">Account settings</string>
|
<string name="preferences_account_settings">Account settings</string>
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,17 @@
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="@string/pref_key_show_visited_sites_bookmarks"
|
android:key="@string/pref_key_show_clipboard_suggestions"
|
||||||
android:title='@string/preference_show_visited_sites_bookmarks'
|
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" />
|
app:iconSpaceReserved="false" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
|
@ -50,8 +50,10 @@ class SearchFragmentStoreTest {
|
||||||
searchEngineSource = mockk(),
|
searchEngineSource = mockk(),
|
||||||
defaultEngineSource = mockk(),
|
defaultEngineSource = mockk(),
|
||||||
showShortcutEnginePicker = false,
|
showShortcutEnginePicker = false,
|
||||||
showSuggestions = false,
|
showSearchSuggestions = false,
|
||||||
showVisitedSitesBookmarks = false,
|
showClipboardSuggestions = false,
|
||||||
|
showHistorySuggestions = false,
|
||||||
|
showBookmarkSuggestions = false,
|
||||||
session = null
|
session = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,10 +175,24 @@ class SettingsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldShowVisitedSitesBookmarks() {
|
fun shouldShowClipboardSuggestion() {
|
||||||
// When just created
|
// When just created
|
||||||
// Then
|
// 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
|
@Test
|
||||||
|
@ -225,7 +239,7 @@ class SettingsTest {
|
||||||
fun showSearchSuggestions() {
|
fun showSearchSuggestions() {
|
||||||
// When just created
|
// When just created
|
||||||
// Then
|
// Then
|
||||||
assertTrue(settings.showSearchSuggestions)
|
assertTrue(settings.shouldShowSearchSuggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -101,7 +101,7 @@ Private Tab, Share, Report Site Issue, Back/Forward button, Reload Button</td></
|
||||||
<td>
|
<td>
|
||||||
<table>
|
<table>
|
||||||
<tr><td>preference_key</td><td>The preference key for the switch preference the user toggled. We currently track: leakcanary,
|
<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>
|
tracking_protection</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>enabled</td><td>Whether or not the preference is <b>now</b> enabled</td></tr>
|
<tr><td>enabled</td><td>Whether or not the preference is <b>now</b> enabled</td></tr>
|
||||||
|
|
Loading…
Reference in New Issue