From 51060489740660ab0fba017411a97806ade215ba Mon Sep 17 00:00:00 2001 From: Roger Yang Date: Thu, 19 May 2022 13:07:44 -0400 Subject: [PATCH] [fenix] Close https://github.com/mozilla-mobile/fenix/issues/25288: Disable autocomplete for unified history search --- .../fenix/search/SearchDialogFragment.kt | 21 +++++++++++++++++-- .../fenix/search/toolbar/ToolbarView.kt | 18 ---------------- .../fenix/search/toolbar/ToolbarViewTest.kt | 2 -- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt index aa5e0b01b6..a451955b9c 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt @@ -40,6 +40,7 @@ import androidx.navigation.fragment.navArgs import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch +import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider import mozilla.components.browser.state.search.SearchEngine import mozilla.components.browser.state.state.searchEngines import mozilla.components.browser.toolbar.BrowserToolbar @@ -49,6 +50,7 @@ import mozilla.components.concept.menu.candidate.TextMenuCandidate import mozilla.components.concept.storage.HistoryStorage import mozilla.components.concept.toolbar.Toolbar import mozilla.components.feature.qr.QrFeature +import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature import mozilla.components.lib.state.ext.consumeFlow import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.service.glean.private.NoExtras @@ -204,15 +206,30 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler { requireContext(), requireContext().settings(), interactor, - historyStorageProvider(), isPrivate, binding.toolbar, - requireComponents.core.engine, fromHomeFragment ).also { inlineAutocompleteEditText = it.view.findViewById(R.id.mozac_browser_toolbar_edit_url_view) } + if (requireContext().settings().shouldAutocompleteInAwesomebar) { + val engineForSpeculativeConnects = if (!isPrivate) requireComponents.core.engine else null + + ToolbarAutocompleteFeature( + binding.toolbar, + engineForSpeculativeConnects, + { store.state.searchEngineSource.searchEngine?.type != SearchEngine.Type.APPLICATION } + ).apply { + addDomainProvider( + ShippedDomainsProvider().also { shippedDomainsProvider -> + shippedDomainsProvider.initialize(requireContext()) + } + ) + historyStorageProvider()?.also(::addHistoryStorageProvider) + } + } + val awesomeBar = binding.awesomeBar awesomeBarView = AwesomeBarView( diff --git a/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt b/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt index ea26df95cb..c58063d621 100644 --- a/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt +++ b/app/src/main/java/org/mozilla/fenix/search/toolbar/ToolbarView.kt @@ -10,11 +10,7 @@ import android.graphics.drawable.BitmapDrawable import androidx.annotation.VisibleForTesting import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat -import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider import mozilla.components.browser.toolbar.BrowserToolbar -import mozilla.components.concept.engine.Engine -import mozilla.components.concept.storage.HistoryStorage -import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature import mozilla.components.support.ktx.android.content.getColorFromAttr import mozilla.components.support.ktx.android.content.res.resolveAttribute import mozilla.components.support.ktx.android.view.hideKeyboard @@ -64,10 +60,8 @@ class ToolbarView( private val context: Context, private val settings: Settings, private val interactor: ToolbarInteractor, - private val historyStorage: HistoryStorage?, private val isPrivate: Boolean, val view: BrowserToolbar, - engine: Engine, fromHomeFragment: Boolean ) { @@ -122,18 +116,6 @@ class ToolbarView( } }) } - - val engineForSpeculativeConnects = if (!isPrivate) engine else null - - if (settings.shouldAutocompleteInAwesomebar) { - ToolbarAutocompleteFeature( - view, - engineForSpeculativeConnects - ).apply { - addDomainProvider(ShippedDomainsProvider().also { it.initialize(view.context) }) - historyStorage?.also(::addHistoryStorageProvider) - } - } } fun update(searchState: SearchFragmentState) { diff --git a/app/src/test/java/org/mozilla/fenix/search/toolbar/ToolbarViewTest.kt b/app/src/test/java/org/mozilla/fenix/search/toolbar/ToolbarViewTest.kt index 7f5119f8ac..d2d911beaf 100644 --- a/app/src/test/java/org/mozilla/fenix/search/toolbar/ToolbarViewTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/toolbar/ToolbarViewTest.kt @@ -158,10 +158,8 @@ class ToolbarViewTest { context, Settings(context), interactor, - historyStorage = null, isPrivate = isPrivate, view = toolbar, - engine = engine, fromHomeFragment = false ) }