For #11245: Integrate Synced Tabs AwesomeBar suggestions

fix pr
pull/122/head^2
Hakkı Kaan Çalışkan 4 years ago committed by Jonathan Almeida
parent 2059156193
commit f87ca730a9

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

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

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

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

@ -94,6 +94,7 @@
<string name="pref_key_show_clipboard_suggestions" translatable="false">pref_key_show_clipboard_suggestions</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_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_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" 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_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> <string name="pref_key_show_voice_search" translatable="false">pref_key_show_voice_search</string>

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

@ -44,6 +44,10 @@
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key_search_bookmarks" android:key="@string/pref_key_search_bookmarks"
android:title='@string/preferences_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 <SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key_show_voice_search" android:key="@string/pref_key_show_voice_search"

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

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

Loading…
Cancel
Save