For #11245: Integrate Synced Tabs AwesomeBar suggestions

fix pr
This commit is contained in:
Hakkı Kaan Çalışkan 2020-07-15 22:16:08 +03:00 committed by Jonathan Almeida
parent 2059156193
commit f87ca730a9
9 changed files with 43 additions and 0 deletions

View File

@ -66,6 +66,7 @@ data class SearchFragmentState(
val showClipboardSuggestions: Boolean,
val showHistorySuggestions: Boolean,
val showBookmarkSuggestions: Boolean,
val showSyncedTabsSuggestions: Boolean,
val tabId: String?,
val pastedText: String? = null,
val searchAccessPoint: Event.PerformedSearch.SearchAccessPoint?
@ -110,6 +111,7 @@ fun createInitialSearchFragmentState(
showClipboardSuggestions = settings.shouldShowClipboardSuggestions,
showHistorySuggestions = settings.shouldShowHistorySuggestions,
showBookmarkSuggestions = settings.shouldShowBookmarkSuggestions,
showSyncedTabsSuggestions = settings.shouldShowSyncedTabsSuggestions,
tabId = tabId,
pastedText = pastedText,
searchAccessPoint = searchAccessPoint

View File

@ -20,6 +20,7 @@ import mozilla.components.feature.awesomebar.provider.SearchSuggestionProvider
import mozilla.components.feature.awesomebar.provider.SessionSuggestionProvider
import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.feature.syncedtabs.SyncedTabsStorageSuggestionProvider
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.ktx.android.content.getColorFromAttr
import org.mozilla.fenix.HomeActivity
@ -32,6 +33,7 @@ import org.mozilla.fenix.search.SearchFragmentState
/**
* View that contains and configures the BrowserAwesomeBar
*/
@Suppress("LargeClass")
class AwesomeBarView(
private val activity: HomeActivity,
val interactor: AwesomeBarInteractor,
@ -41,6 +43,7 @@ class AwesomeBarView(
private val historyStorageProvider: HistoryStorageSuggestionProvider
private val shortcutsEnginePickerProvider: ShortcutsSuggestionProvider
private val bookmarksStorageSuggestionProvider: BookmarksStorageSuggestionProvider
private val syncedTabsStorageSuggestionProvider: SyncedTabsStorageSuggestionProvider
private val defaultSearchSuggestionProvider: SearchSuggestionProvider
private val defaultSearchActionProvider: SearchActionProvider
private val searchSuggestionProviderMap: MutableMap<SearchEngine, List<AwesomeBar.SuggestionProvider>>
@ -123,6 +126,13 @@ class AwesomeBarView(
engine = engineForSpeculativeConnects
)
syncedTabsStorageSuggestionProvider =
SyncedTabsStorageSuggestionProvider(
components.backgroundServices.syncedTabsStorage,
components.useCases.tabsUseCases.addTab,
components.core.icons
)
val searchBitmap = getDrawable(activity, R.drawable.ic_search)!!.apply {
colorFilter = createBlendModeColorFilterCompat(primaryTextColor, SRC_IN)
}.toBitmap()
@ -204,6 +214,7 @@ class AwesomeBarView(
}
}
@Suppress("ComplexMethod")
private fun getProvidersToAdd(state: SearchFragmentState): MutableSet<AwesomeBar.SuggestionProvider> {
val providersToAdd = mutableSetOf<AwesomeBar.SuggestionProvider>()
@ -219,6 +230,10 @@ class AwesomeBarView(
providersToAdd.addAll(getSelectedSearchSuggestionProvider(state))
}
if (state.showSyncedTabsSuggestions) {
providersToAdd.add(syncedTabsStorageSuggestionProvider)
}
if (activity.browsingModeManager.mode == BrowsingMode.Normal) {
providersToAdd.add(sessionProvider)
}
@ -243,6 +258,10 @@ class AwesomeBarView(
providersToRemove.addAll(getSelectedSearchSuggestionProvider(state))
}
if (!state.showSyncedTabsSuggestions) {
providersToRemove.add(syncedTabsStorageSuggestionProvider)
}
if (activity.browsingModeManager.mode == BrowsingMode.Private) {
providersToRemove.add(sessionProvider)
}

View File

@ -57,6 +57,11 @@ class SearchEngineFragment : PreferenceFragmentCompat() {
isChecked = context.settings().shouldShowBookmarkSuggestions
}
val showSyncedTabsSuggestions =
requirePreference<SwitchPreference>(R.string.pref_key_search_synced_tabs).apply {
isChecked = context.settings().shouldShowSyncedTabsSuggestions
}
val showClipboardSuggestions =
requirePreference<SwitchPreference>(R.string.pref_key_show_clipboard_suggestions).apply {
isChecked = context.settings().shouldShowClipboardSuggestions
@ -75,6 +80,7 @@ class SearchEngineFragment : PreferenceFragmentCompat() {
showSearchShortcuts.onPreferenceChangeListener = SharedPreferenceUpdater()
showHistorySuggestions.onPreferenceChangeListener = SharedPreferenceUpdater()
showBookmarkSuggestions.onPreferenceChangeListener = SharedPreferenceUpdater()
showSyncedTabsSuggestions.onPreferenceChangeListener = SharedPreferenceUpdater()
showClipboardSuggestions.onPreferenceChangeListener = SharedPreferenceUpdater()
searchSuggestionsInPrivatePreference.onPreferenceChangeListener = SharedPreferenceUpdater()
showVoiceSearchPreference.onPreferenceChangeListener = SharedPreferenceUpdater()

View File

@ -323,6 +323,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = true
)
val shouldShowSyncedTabsSuggestions by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_search_synced_tabs),
default = true
)
val shouldShowClipboardSuggestions by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_show_clipboard_suggestions),
default = true

View File

@ -94,6 +94,7 @@
<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>
<string name="pref_key_search_synced_tabs" translatable="false">pref_key_search_synced_tabs</string>
<string name="pref_key_show_search_suggestions_in_private" translatable="false">pref_key_show_search_suggestions_in_private</string>
<string name="pref_key_show_search_suggestions_in_private_onboarding" translatable="false">pref_key_show_search_suggestions_in_privateonboarding</string>
<string name="pref_key_show_voice_search" translatable="false">pref_key_show_voice_search</string>

View File

@ -320,6 +320,8 @@
<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 title for switch preference to suggest synced tabs when searching -->
<string name="preferences_search_synced_tabs">Search synced tabs</string>
<!-- Preference for account settings -->
<string name="preferences_account_settings">Account settings</string>
<!-- Preference for enabling url autocomplete-->

View File

@ -44,6 +44,10 @@
android:defaultValue="true"
android:key="@string/pref_key_search_bookmarks"
android:title='@string/preferences_search_bookmarks' />
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_search_synced_tabs"
android:title='@string/preferences_search_synced_tabs' />
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_show_voice_search"

View File

@ -72,6 +72,7 @@ class SearchFragmentStoreTest {
showClipboardSuggestions = false,
showHistorySuggestions = false,
showBookmarkSuggestions = false,
showSyncedTabsSuggestions = false,
tabId = null,
pastedText = "pastedText",
searchAccessPoint = SearchAccessPoint.ACTION
@ -128,6 +129,7 @@ class SearchFragmentStoreTest {
showClipboardSuggestions = false,
showHistorySuggestions = false,
showBookmarkSuggestions = false,
showSyncedTabsSuggestions = false,
tabId = "tabId",
pastedText = "",
searchAccessPoint = SearchAccessPoint.SHORTCUT
@ -234,6 +236,7 @@ class SearchFragmentStoreTest {
showClipboardSuggestions = false,
showHistorySuggestions = false,
showBookmarkSuggestions = false,
showSyncedTabsSuggestions = false,
searchAccessPoint = SearchAccessPoint.NONE
)
}

View File

@ -56,6 +56,7 @@ class ToolbarViewTest {
showClipboardSuggestions = false,
showHistorySuggestions = false,
showBookmarkSuggestions = false,
showSyncedTabsSuggestions = false,
searchAccessPoint = Event.PerformedSearch.SearchAccessPoint.NONE
)