mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
Bug 1822606 - Refactor HomeFragment.navigateToSearch() to the ToolbarController
This commit is contained in:
parent
59c4860c1e
commit
d474c99acb
@ -79,14 +79,12 @@ import mozilla.components.support.ktx.android.content.getColorFromAttr
|
||||
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
||||
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
|
||||
import org.mozilla.fenix.Config
|
||||
import org.mozilla.fenix.GleanMetrics.Events
|
||||
import org.mozilla.fenix.GleanMetrics.HomeScreen
|
||||
import org.mozilla.fenix.GleanMetrics.PrivateBrowsingShortcutCfr
|
||||
import org.mozilla.fenix.GleanMetrics.UnifiedSearch
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.addons.showSnackBar
|
||||
import org.mozilla.fenix.browser.BrowserAnimator.Companion.getToolbarNavOptions
|
||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.PrivateShortcutCreateManager
|
||||
@ -594,7 +592,7 @@ class HomeFragment : Fragment() {
|
||||
binding.toolbar.compoundDrawablePadding =
|
||||
view.resources.getDimensionPixelSize(R.dimen.search_bar_search_engine_icon_padding)
|
||||
binding.toolbarWrapper.setOnClickListener {
|
||||
navigateToSearch()
|
||||
sessionControlInteractor.onNavigateSearch()
|
||||
}
|
||||
|
||||
binding.toolbarWrapper.setOnLongClickListener {
|
||||
@ -631,7 +629,7 @@ class HomeFragment : Fragment() {
|
||||
updateTabCounter(requireComponents.core.store.state)
|
||||
|
||||
if (bundleArgs.getBoolean(FOCUS_ON_ADDRESS_BAR)) {
|
||||
navigateToSearch()
|
||||
sessionControlInteractor.onNavigateSearch()
|
||||
} else if (bundleArgs.getBoolean(SCROLL_TO_COLLECTION)) {
|
||||
MainScope().launch {
|
||||
delay(ANIM_SCROLL_DELAY)
|
||||
@ -975,19 +973,7 @@ class HomeFragment : Fragment() {
|
||||
private fun hideOnboardingAndOpenSearch() {
|
||||
hideOnboardingIfNeeded()
|
||||
appBarLayout?.setExpanded(true, true)
|
||||
navigateToSearch()
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun navigateToSearch() {
|
||||
val directions =
|
||||
HomeFragmentDirections.actionGlobalSearchDialog(
|
||||
sessionId = null,
|
||||
)
|
||||
|
||||
nav(R.id.homeFragment, directions, getToolbarNavOptions(requireContext()))
|
||||
|
||||
Events.searchBarTapped.record(Events.SearchBarTappedExtra("HOME"))
|
||||
sessionControlInteractor.onNavigateSearch()
|
||||
}
|
||||
|
||||
private fun subscribeToTabCollections(): Observer<List<TabCollection>> {
|
||||
|
@ -158,6 +158,11 @@ interface SessionControlController {
|
||||
*/
|
||||
fun handlePaste(clipboardText: String)
|
||||
|
||||
/**
|
||||
* @see [ToolbarInteractor.onNavigateSearch]
|
||||
*/
|
||||
fun handleNavigateSearch()
|
||||
|
||||
/**
|
||||
* @see [CollectionInteractor.onAddTabsToCollectionTapped]
|
||||
*/
|
||||
@ -584,6 +589,21 @@ class DefaultSessionControlController(
|
||||
navController.nav(R.id.homeFragment, directions)
|
||||
}
|
||||
|
||||
override fun handleNavigateSearch() {
|
||||
val directions =
|
||||
HomeFragmentDirections.actionGlobalSearchDialog(
|
||||
sessionId = null,
|
||||
)
|
||||
|
||||
navController.nav(
|
||||
R.id.homeFragment,
|
||||
directions,
|
||||
BrowserAnimator.getToolbarNavOptions(activity),
|
||||
)
|
||||
|
||||
Events.searchBarTapped.record(Events.SearchBarTappedExtra("HOME"))
|
||||
}
|
||||
|
||||
override fun handleMessageClicked(message: Message) {
|
||||
messageController.onMessagePressed(message)
|
||||
}
|
||||
|
@ -147,6 +147,11 @@ interface ToolbarInteractor {
|
||||
* Navigates to search with clipboard text.
|
||||
*/
|
||||
fun onPaste(clipboardText: String)
|
||||
|
||||
/**
|
||||
* Navigates to the search dialog.
|
||||
*/
|
||||
fun onNavigateSearch()
|
||||
}
|
||||
|
||||
interface CustomizeHomeIteractor {
|
||||
@ -347,6 +352,10 @@ class SessionControlInteractor(
|
||||
controller.handlePaste(clipboardText)
|
||||
}
|
||||
|
||||
override fun onNavigateSearch() {
|
||||
controller.handleNavigateSearch()
|
||||
}
|
||||
|
||||
override fun onRemoveCollectionsPlaceholder() {
|
||||
controller.handleRemoveCollectionsPlaceholder()
|
||||
}
|
||||
|
@ -1015,6 +1015,25 @@ class DefaultSessionControlControllerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handleNavigateSearch() {
|
||||
assertNull(Events.searchBarTapped.testGetValue())
|
||||
|
||||
createController().handleNavigateSearch()
|
||||
|
||||
assertNotNull(Events.searchBarTapped.testGetValue())
|
||||
val recordedEvents = Events.searchBarTapped.testGetValue()!!
|
||||
assertEquals(1, recordedEvents.size)
|
||||
assertEquals("HOME", recordedEvents.single().extra?.getValue("source"))
|
||||
|
||||
verify {
|
||||
navController.navigate(
|
||||
match<NavDirections> { it.actionId == R.id.action_global_search_dialog },
|
||||
any<NavOptions>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handleRemoveCollectionsPlaceholder() {
|
||||
createController().handleRemoveCollectionsPlaceholder()
|
||||
|
@ -146,6 +146,12 @@ class SessionControlInteractorTest {
|
||||
verify { controller.handlePasteAndGo("text") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onNavigateSearch() {
|
||||
interactor.onNavigateSearch()
|
||||
verify { controller.handleNavigateSearch() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onRemoveCollectionsPlaceholder() {
|
||||
interactor.onRemoveCollectionsPlaceholder()
|
||||
|
Loading…
Reference in New Issue
Block a user