For #19475 - Cleanup - respect naming scheme in TabsTrayController

In our current MVI implementation the View Interactors are first called in
response to a direct user action and contain methods following the
"onXXHappened" naming scheme and then delegate other Interactors / Controllers
for specific actions.

Controllers contain the business logic for actually updating the app's state
and offer methods following the "handleXXAction" naming scheme.
upstream-sync
Mugurell 3 years ago
parent 727d0256e0
commit dc26272381

@ -78,7 +78,7 @@ internal class TabLayoutObserver(
true true
} }
interactor.setCurrentTrayPosition(tab.position, animate) interactor.onTrayPositionSelected(tab.position, animate)
Do exhaustive when (Page.positionToPage(tab.position)) { Do exhaustive when (Page.positionToPage(tab.position)) {
Page.NormalTabs -> metrics.track(Event.TabsTrayNormalModeTapped) Page.NormalTabs -> metrics.track(Event.TabsTrayNormalModeTapped)

@ -18,23 +18,20 @@ import org.mozilla.fenix.tabtray.TabTrayDialogFragmentDirections
interface TabsTrayController { interface TabsTrayController {
/** /**
* Called when user clicks the new tab button. * Called to open a new tab.
*/ */
fun onNewTabTapped(isPrivate: Boolean) fun handleOpeningNewTab(isPrivate: Boolean)
} }
class DefaultTabsTrayController( class DefaultTabsTrayController(
private val store: TabsTrayStore,
private val browsingModeManager: BrowsingModeManager, private val browsingModeManager: BrowsingModeManager,
private val navController: NavController, private val navController: NavController,
private val profiler: Profiler?, private val profiler: Profiler?,
private val navigationInteractor: NavigationInteractor, private val navigationInteractor: NavigationInteractor,
private val metrics: MetricController, private val metrics: MetricController,
private val ioScope: CoroutineScope,
private val accountManager: FxaAccountManager
) : TabsTrayController { ) : TabsTrayController {
override fun onNewTabTapped(isPrivate: Boolean) { override fun handleOpeningNewTab(isPrivate: Boolean) {
val startTime = profiler?.getProfilerTime() val startTime = profiler?.getProfilerTime()
browsingModeManager.mode = BrowsingMode.fromBoolean(isPrivate) browsingModeManager.mode = BrowsingMode.fromBoolean(isPrivate)
navController.navigateBlockingForAsyncNavGraph( navController.navigateBlockingForAsyncNavGraph(

@ -29,7 +29,6 @@ import kotlinx.android.synthetic.main.tabstray_multiselect_items.*
import kotlinx.android.synthetic.main.tabstray_multiselect_items.view.* import kotlinx.android.synthetic.main.tabstray_multiselect_items.view.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.plus
import mozilla.components.browser.state.selector.findTab import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
import mozilla.components.browser.state.selector.normalTabs import mozilla.components.browser.state.selector.normalTabs
@ -124,14 +123,11 @@ class TabsTrayFragment : AppCompatDialogFragment(), TabsTrayInteractor {
) )
tabsTrayController = DefaultTabsTrayController( tabsTrayController = DefaultTabsTrayController(
store = tabsTrayStore,
browsingModeManager = activity.browsingModeManager, browsingModeManager = activity.browsingModeManager,
navController = findNavController(), navController = findNavController(),
navigationInteractor = navigationInteractor, navigationInteractor = navigationInteractor,
profiler = requireComponents.core.engine.profiler, profiler = requireComponents.core.engine.profiler,
accountManager = requireComponents.backgroundServices.accountManager,
metrics = requireComponents.analytics.metrics, metrics = requireComponents.analytics.metrics,
ioScope = lifecycleScope + Dispatchers.IO
) )
browserTrayInteractor = DefaultBrowserTrayInteractor( browserTrayInteractor = DefaultBrowserTrayInteractor(
@ -262,13 +258,13 @@ class TabsTrayFragment : AppCompatDialogFragment(), TabsTrayInteractor {
) )
} }
override fun setCurrentTrayPosition(position: Int, smoothScroll: Boolean) { override fun onTrayPositionSelected(position: Int, smoothScroll: Boolean) {
tabsTray.setCurrentItem(position, smoothScroll) tabsTray.setCurrentItem(position, smoothScroll)
tab_layout.getTabAt(position)?.select() tab_layout.getTabAt(position)?.select()
tabsTrayStore.dispatch(TabsTrayAction.PageSelected(Page.positionToPage(position))) tabsTrayStore.dispatch(TabsTrayAction.PageSelected(Page.positionToPage(position)))
} }
override fun navigateToBrowser() { override fun onBrowserTabSelected() {
dismissTabsTray() dismissTabsTray()
val navController = findNavController() val navController = findNavController()

@ -13,12 +13,12 @@ interface TabsTrayInteractor {
* @param position The position on the tray to focus. * @param position The position on the tray to focus.
* @param smoothScroll If true, animate the scrolling from the current tab to [position]. * @param smoothScroll If true, animate the scrolling from the current tab to [position].
*/ */
fun setCurrentTrayPosition(position: Int, smoothScroll: Boolean) fun onTrayPositionSelected(position: Int, smoothScroll: Boolean)
/** /**
* Dismisses the tabs tray and navigates to the browser. * Dismisses the tabs tray and navigates to the browser.
*/ */
fun navigateToBrowser() fun onBrowserTabSelected()
/** /**
* Invoked when a tab is removed from the tabs tray with the given [tabId]. * Invoked when a tab is removed from the tabs tray with the given [tabId].

@ -57,7 +57,7 @@ class DefaultBrowserTrayInteractor(
private val selectTabWrapper by lazy { private val selectTabWrapper by lazy {
SelectTabUseCaseWrapper(metrics, selectTab) { SelectTabUseCaseWrapper(metrics, selectTab) {
trayInteractor.navigateToBrowser() trayInteractor.onBrowserTabSelected()
} }
} }
@ -73,7 +73,6 @@ class DefaultBrowserTrayInteractor(
*/ */
override fun open(item: Tab) { override fun open(item: Tab) {
selectTabWrapper.invoke(item.id) selectTabWrapper.invoke(item.id)
trayInteractor.navigateToBrowser()
} }
/** /**
@ -133,6 +132,6 @@ class DefaultBrowserTrayInteractor(
* See [BrowserTrayInteractor.onFabClicked] * See [BrowserTrayInteractor.onFabClicked]
*/ */
override fun onFabClicked(isPrivate: Boolean) { override fun onFabClicked(isPrivate: Boolean) {
controller.onNewTabTapped(isPrivate) controller.handleOpeningNewTab(isPrivate)
} }
} }

@ -36,7 +36,7 @@ class BrowserTrayList @JvmOverloads constructor(
context.components.analytics.metrics, context.components.analytics.metrics,
context.components.useCases.tabsUseCases.selectTab context.components.useCases.tabsUseCases.selectTab
) { ) {
interactor.navigateToBrowser() interactor.onBrowserTabSelected()
} }
val removeTabUseCase = RemoveTabUseCaseWrapper( val removeTabUseCase = RemoveTabUseCaseWrapper(

@ -37,7 +37,7 @@ class TabLayoutObserverTest {
store.waitUntilIdle() store.waitUntilIdle()
verify { interactor.setCurrentTrayPosition(1, false) } verify { interactor.onTrayPositionSelected(1, false) }
verify { metrics.track(Event.TabsTrayPrivateModeTapped) } verify { metrics.track(Event.TabsTrayPrivateModeTapped) }
every { tab.position } returns 0 every { tab.position } returns 0
@ -46,7 +46,7 @@ class TabLayoutObserverTest {
store.waitUntilIdle() store.waitUntilIdle()
verify { interactor.setCurrentTrayPosition(0, true) } verify { interactor.onTrayPositionSelected(0, true) }
verify { metrics.track(Event.TabsTrayNormalModeTapped) } verify { metrics.track(Event.TabsTrayNormalModeTapped) }
every { tab.position } returns 2 every { tab.position } returns 2
@ -55,7 +55,7 @@ class TabLayoutObserverTest {
store.waitUntilIdle() store.waitUntilIdle()
verify { interactor.setCurrentTrayPosition(2, true) } verify { interactor.onTrayPositionSelected(2, true) }
verify { metrics.track(Event.TabsTraySyncedModeTapped) } verify { metrics.track(Event.TabsTraySyncedModeTapped) }
} }
@ -67,12 +67,12 @@ class TabLayoutObserverTest {
observer.onTabSelected(tab) observer.onTabSelected(tab)
verify { interactor.setCurrentTrayPosition(1, false) } verify { interactor.onTrayPositionSelected(1, false) }
verify { metrics.track(Event.TabsTrayPrivateModeTapped) } verify { metrics.track(Event.TabsTrayPrivateModeTapped) }
observer.onTabSelected(tab) observer.onTabSelected(tab)
verify { interactor.setCurrentTrayPosition(1, true) } verify { interactor.onTrayPositionSelected(1, true) }
verify { metrics.track(Event.TabsTrayPrivateModeTapped) } verify { metrics.track(Event.TabsTrayPrivateModeTapped) }
} }
} }

Loading…
Cancel
Save