Bug 1849073 - Part 3: Remove trivial `showUnifiedSearchFeature` and `enableUnifiedSearchSettingsUI` checks

fenix/120.0
Gabriel Luong 8 months ago committed by mergify[bot]
parent bdb12a0806
commit a3aa4539eb

@ -617,19 +617,15 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
}
/**
* If unified search is enabled try to migrate the topic specific engine to the
* first general or custom search engine available.
* Migrate the topic specific engine to the first general or custom search engine available.
*/
@Suppress("NestedBlockDepth")
private fun migrateTopicSpecificSearchEngines() {
if (settings().showUnifiedSearchFeature) {
components.core.store.state.search.selectedOrDefaultSearchEngine.let { currentSearchEngine ->
if (currentSearchEngine?.isGeneral == false) {
components.core.store.state.search.searchEngines.firstOrNull() { nextSearchEngine ->
nextSearchEngine.isGeneral
}?.let {
components.useCases.searchUseCases.selectSearchEngine(it)
}
components.core.store.state.search.selectedOrDefaultSearchEngine.let { currentSearchEngine ->
if (currentSearchEngine?.isGeneral == false) {
components.core.store.state.search.searchEngines.firstOrNull { nextSearchEngine ->
nextSearchEngine.isGeneral
}?.let {
components.useCases.searchUseCases.selectSearchEngine(it)
}
}
}

@ -368,7 +368,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
components.core.contileTopSitesUpdater.startPeriodicWork()
}
if (settings().enableUnifiedSearchSettingsUI && !settings().hiddenEnginesRestored) {
if (!settings().hiddenEnginesRestored) {
settings().hiddenEnginesRestored = true
components.useCases.searchUseCases.restoreHiddenSearchEngines.invoke()
}

@ -286,11 +286,7 @@ class Core(
BrowserStore(
initialState = BrowserState(
search = SearchState(
applicationSearchEngines = if (context.settings().showUnifiedSearchFeature) {
applicationSearchEngines
} else {
emptyList()
},
applicationSearchEngines = applicationSearchEngines,
),
),
middleware = middlewareList + EngineMiddleware.create(

@ -38,11 +38,11 @@ abstract class ToolbarIntegration(
val store = context.components.core.store
private val toolbarPresenter: ToolbarPresenter = ToolbarPresenter(
toolbar,
store,
sessionId,
context.settings().showUnifiedSearchFeature,
ToolbarFeature.UrlRenderConfiguration(
toolbar = toolbar,
store = store,
customTabId = sessionId,
shouldDisplaySearchTerms = true,
urlRenderConfiguration = ToolbarFeature.UrlRenderConfiguration(
context.components.publicSuffixList,
ThemeManager.resolveAttribute(R.attr.textPrimary, context),
renderStyle = renderStyle,

@ -6,8 +6,6 @@ package org.mozilla.fenix.home.toolbar
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import androidx.core.view.isGone
import androidx.core.view.isVisible
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
@ -38,11 +36,6 @@ class SearchSelectorBinding(
override fun start() {
super.start()
context.settings().showUnifiedSearchFeature.let {
binding.searchSelectorButton.isVisible = it
binding.searchEngineIcon.isGone = it
}
binding.searchSelectorButton.apply {
setOnClickListener {
val orientation = if (context.settings().shouldUseBottomToolbar) {
@ -80,11 +73,7 @@ class SearchSelectorBinding(
}
}
if (context.settings().showUnifiedSearchFeature) {
binding.searchSelectorButton.setIcon(icon, name)
} else {
binding.searchEngineIcon.setImageDrawable(icon)
}
binding.searchSelectorButton.setIcon(icon, name)
}
}
}

@ -236,7 +236,6 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
getPreviousDestination()?.destination?.id == R.id.homeFragment
toolbarView = ToolbarView(
requireContext(),
requireContext().settings(),
requireComponents,
interactor,
@ -492,11 +491,8 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
toolbarView.update(it)
awesomeBarView.update(it)
if (showUnifiedSearchFeature) {
addSearchSelector()
updateQrButton(it)
}
addSearchSelector()
updateQrButton(it)
updateVoiceSearchButton()
}
}

@ -439,11 +439,7 @@ class AwesomeBarView(
engine,
shortcutSearchUseCase,
components.core.client,
limit = if (activity.settings().showUnifiedSearchFeature) {
METADATA_SHORTCUT_SUGGESTION_LIMIT
} else {
METADATA_SUGGESTION_LIMIT
},
limit = METADATA_SHORTCUT_SUGGESTION_LIMIT,
mode = SearchSuggestionProvider.Mode.MULTIPLE_SUGGESTIONS,
icon = searchBitmap,
engine = engineForSpeculativeConnects,

@ -4,9 +4,6 @@
package org.mozilla.fenix.search.toolbar
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import androidx.annotation.VisibleForTesting
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
@ -52,9 +49,7 @@ interface ToolbarInteractor : SearchSelectorInteractor {
/**
* View that contains and configures the BrowserToolbar to only be used in its editing mode.
*/
@Suppress("LongParameterList")
class ToolbarView(
private val context: Context,
private val settings: Settings,
private val components: Components,
private val interactor: ToolbarInteractor,
@ -146,33 +141,16 @@ class ToolbarView(
interactor.onTextChanged(view.url.toString())
// If search terms are displayed, move the cursor to the end instead of selecting all text.
if (settings.showUnifiedSearchFeature && searchState.searchTerms.isNotBlank()) {
if (searchState.searchTerms.isNotBlank()) {
view.editMode(cursorPlacement = Toolbar.CursorPlacement.END)
} else {
view.editMode()
}
isInitialized = true
}
configureAutocomplete(searchState.searchEngineSource)
val searchEngine = searchState.searchEngineSource.searchEngine
if (!settings.showUnifiedSearchFeature && searchEngine != null) {
val iconSize =
context.resources.getDimensionPixelSize(R.dimen.preference_icon_drawable_size)
val scaledIcon = Bitmap.createScaledBitmap(
searchEngine.icon,
iconSize,
iconSize,
true,
)
val icon = BitmapDrawable(context.resources, scaledIcon)
view.edit.setIcon(icon, searchEngine.name)
}
}
private fun configureAutocomplete(searchEngineSource: SearchEngineSource) {

@ -78,32 +78,14 @@ class RadioSearchEngineListPreference @JvmOverloads constructor(
ViewGroup.LayoutParams.WRAP_CONTENT,
)
val isLastGeneralOrCustomSearchEngine = state.searchEngines.filter {
it.isGeneral
}.size == 1
state.searchEngines.filter { engine ->
if (context.settings().enableUnifiedSearchSettingsUI) {
engine.type != SearchEngine.Type.APPLICATION && engine.isGeneral
} else {
engine.type != SearchEngine.Type.APPLICATION
}
engine.type != SearchEngine.Type.APPLICATION && engine.isGeneral
}.forEach { engine ->
val isLastSearchEngineAvailable =
state.searchEngines.count { it.type != SearchEngine.Type.APPLICATION } > 1
val allowDeletion = if (context.settings().enableUnifiedSearchSettingsUI) {
engine.type == SearchEngine.Type.CUSTOM
} else {
if (context.settings().showUnifiedSearchFeature) {
isLastSearchEngineAvailable && !(engine.isGeneral && isLastGeneralOrCustomSearchEngine)
} else {
isLastSearchEngineAvailable
}
}
val searchEngineView = makeButtonFromSearchEngine(
engine = engine,
layoutInflater = layoutInflater,
res = context.resources,
allowDeletion = allowDeletion,
allowDeletion = engine.type == SearchEngine.Type.CUSTOM,
isSelected = engine == state.selectedOrDefaultSearchEngine,
)
@ -124,12 +106,13 @@ class RadioSearchEngineListPreference @JvmOverloads constructor(
val binding = SearchEngineRadioButtonBinding.bind(wrapper)
if (context.settings().showUnifiedSearchFeature && !engine.isGeneral) {
if (!engine.isGeneral) {
binding.radioButton.isEnabled = false
wrapper.isEnabled = false
} else {
wrapper.setOnClickListener { binding.radioButton.isChecked = true }
}
binding.radioButton.tag = engine.id
binding.radioButton.isChecked = isSelected
binding.radioButton.setOnCheckedChangeListener(this)
@ -189,18 +172,12 @@ class RadioSearchEngineListPreference @JvmOverloads constructor(
val selectedOrDefaultSearchEngine = context.components.core.store.state.search.selectedOrDefaultSearchEngine
if (selectedOrDefaultSearchEngine == engine) {
val nextSearchEngine =
if (context.settings().showUnifiedSearchFeature) {
context.components.core.store.state.search.searchEngines.firstOrNull {
it.id != engine.id && (it.isGeneral || it.type == SearchEngine.Type.CUSTOM)
}
?: context.components.core.store.state.search.searchEngines.firstOrNull {
it.id != engine.id
}
} else {
context.components.core.store.state.search.searchEngines.firstOrNull {
context.components.core.store.state.search.searchEngines.firstOrNull {
it.id != engine.id && (it.isGeneral || it.type == SearchEngine.Type.CUSTOM)
}
?: context.components.core.store.state.search.searchEngines.firstOrNull {
it.id != engine.id
}
}
nextSearchEngine?.let {
context.components.useCases.searchUseCases.selectSearchEngine(

@ -134,17 +134,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/bottom_bar">
<ImageView
android:id="@+id/search_engine_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start|center_vertical"
android:layout_marginStart="8dp"
android:layout_marginEnd="12dp"
android:clickable="false"
android:focusable="false"
android:importantForAccessibility="no" />
<org.mozilla.fenix.search.toolbar.SearchSelector
android:id="@+id/search_selector_button"
android:layout_width="wrap_content"

@ -20,7 +20,6 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
import mozilla.components.browser.toolbar.behavior.ToolbarPosition as MozacToolbarPosition
@ -42,7 +41,6 @@ class BrowserToolbarViewTest {
every { testContext.components.useCases } returns mockk(relaxed = true)
every { testContext.components.core } returns mockk(relaxed = true)
every { testContext.components.publicSuffixList } returns PublicSuffixList(testContext)
every { testContext.settings().showUnifiedSearchFeature } returns false
toolbarView = BrowserToolbarView(
context = testContext,

@ -766,9 +766,7 @@ class AwesomeBarViewTest {
@Test
fun `GIVEN a search is made by the user WHEN configuring providers THEN search engine suggestion provider should always be added`() {
val settings: Settings = mockk(relaxed = true) {
every { showUnifiedSearchFeature } returns true
}
val settings: Settings = mockk(relaxed = true)
every { activity.settings() } returns settings
val state = getSearchProviderState(
searchEngineSource = SearchEngineSource.Default(mockk(relaxed = true)),
@ -781,9 +779,7 @@ class AwesomeBarViewTest {
@Test
fun `GIVEN a search from the default engine with all suggestions asked WHEN configuring providers THEN add them all`() {
val settings: Settings = mockk(relaxed = true) {
every { showUnifiedSearchFeature } returns false
}
val settings: Settings = mockk(relaxed = true)
val url = Uri.parse("https://www.test.com")
every { activity.settings() } returns settings
every { activity.browsingModeManager.mode } returns BrowsingMode.Normal
@ -820,9 +816,7 @@ class AwesomeBarViewTest {
@Test
fun `GIVEN a search from the default engine with no suggestions asked WHEN configuring providers THEN add only search engine suggestion provider`() {
val settings: Settings = mockk(relaxed = true) {
every { showUnifiedSearchFeature } returns true
}
val settings: Settings = mockk(relaxed = true)
every { activity.settings() } returns settings
every { activity.browsingModeManager.mode } returns BrowsingMode.Normal
val state = getSearchProviderState(

@ -23,7 +23,6 @@ import mozilla.components.browser.state.state.searchEngines
import mozilla.components.browser.storage.sync.PlacesBookmarksStorage
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.edit.EditToolbar
import mozilla.components.concept.toolbar.Toolbar
import mozilla.components.feature.awesomebar.provider.SessionAutocompleteProvider
import mozilla.components.feature.syncedtabs.SyncedTabsAutocompleteProvider
@ -205,17 +204,6 @@ class ToolbarViewTest {
verify(exactly = 0) { toolbar.setSearchTerms("Search Terms") }
}
@Test
fun `searchEngine name and icon get set on update`() {
val editToolbar: EditToolbar = mockk(relaxed = true)
every { toolbar.edit } returns editToolbar
val toolbarView = buildToolbarView(false)
toolbarView.update(defaultState)
verify { editToolbar.setIcon(any(), "Search Engine") }
}
@Test
fun `WHEN the default general search engine is selected THEN show text for default engine`() {
val toolbarView = buildToolbarView(false)
@ -863,7 +851,6 @@ class ToolbarViewTest {
settings: Settings = context.settings(),
components: Components = mockk(relaxed = true),
) = ToolbarView(
context = context,
settings = settings,
components = components,
interactor = interactor,

Loading…
Cancel
Save