From 12c8d94eeb9710a6b1e551354500f078df501a5d Mon Sep 17 00:00:00 2001 From: Mugurell Date: Wed, 16 Nov 2022 09:45:20 +0200 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/25816: Have the previous autocomplete functionality work with the new API The new API allows us to move from having just two autocomplete providers: a shipped list of domains and history result to any autocomplete providers. --- .../components/toolbar/ToolbarIntegration.kt | 22 ++++++++++++------- .../toolbar/DefaultToolbarIntegrationTest.kt | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt index 77e8205ab9..a2371f9feb 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt @@ -8,13 +8,13 @@ import android.content.Context import androidx.annotation.VisibleForTesting import androidx.core.content.ContextCompat import androidx.lifecycle.LifecycleOwner -import mozilla.components.browser.domains.autocomplete.DomainAutocompleteProvider +import mozilla.components.browser.domains.autocomplete.BaseDomainAutocompleteProvider import mozilla.components.browser.state.selector.normalTabs import mozilla.components.browser.state.selector.privateTabs import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.display.DisplayToolbar import mozilla.components.concept.engine.Engine -import mozilla.components.concept.storage.HistoryStorage +import mozilla.components.concept.toolbar.AutocompleteProvider import mozilla.components.feature.tabs.toolbar.TabCounterToolbarButton import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature import mozilla.components.feature.toolbar.ToolbarBehaviorController @@ -77,12 +77,13 @@ abstract class ToolbarIntegration( } } +@Suppress("LongParameterList") class DefaultToolbarIntegration( context: Context, toolbar: BrowserToolbar, toolbarMenu: ToolbarMenu, - domainAutocompleteProvider: DomainAutocompleteProvider, - historyStorage: HistoryStorage, + domainAutocompleteProvider: BaseDomainAutocompleteProvider, + historyStorage: AutocompleteProvider, lifecycleOwner: LifecycleOwner, sessionId: String? = null, isPrivate: Boolean, @@ -155,10 +156,15 @@ class DefaultToolbarIntegration( toolbar, engineForSpeculativeConnects, ).apply { - addDomainProvider(domainAutocompleteProvider) - if (context.settings().shouldShowHistorySuggestions) { - addHistoryStorageProvider(historyStorage) - } + updateAutocompleteProviders( + listOfNotNull( + when (context.settings().shouldShowHistorySuggestions) { + true -> historyStorage + false -> null + }, + domainAutocompleteProvider, + ), + ) } } diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultToolbarIntegrationTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultToolbarIntegrationTest.kt index 279903037a..21c2bbf604 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultToolbarIntegrationTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultToolbarIntegrationTest.kt @@ -38,7 +38,7 @@ class DefaultToolbarIntegrationTest { context = testContext, toolbar = mockk(relaxed = true), toolbarMenu = mockk(relaxed = true), - domainAutocompleteProvider = mockk(), + domainAutocompleteProvider = mockk(relaxed = true), historyStorage = mockk(), lifecycleOwner = mockk(), sessionId = null,