mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/11245: Integrate Synced Tabs AwesomeBar suggestions
fix pr
This commit is contained in:
parent
ed97bf1db4
commit
199cdac801
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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>
|
||||
|
@ -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-->
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ class ToolbarViewTest {
|
||||
showClipboardSuggestions = false,
|
||||
showHistorySuggestions = false,
|
||||
showBookmarkSuggestions = false,
|
||||
showSyncedTabsSuggestions = false,
|
||||
searchAccessPoint = Event.PerformedSearch.SearchAccessPoint.NONE
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user