2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] Close https://github.com/mozilla-mobile/fenix/issues/22223: Move to the selected page when switching modes

This commit is contained in:
Jonathan Almeida 2021-11-09 12:19:35 -05:00 committed by mergify[bot]
parent 1fbd8f0b7e
commit a08fcc9a9d
3 changed files with 11 additions and 4 deletions

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.tabstray
import androidx.annotation.VisibleForTesting
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.base.feature.LifecycleAwareFeature
@ -21,6 +22,7 @@ import org.mozilla.fenix.utils.Do
*/
class TabLayoutMediator(
private val tabLayout: TabLayout,
private val tabPager: ViewPager2,
interactor: TabsTrayInteractor,
private val browsingModeManager: BrowsingModeManager,
private val tabsTrayStore: TabsTrayStore,
@ -55,6 +57,7 @@ class TabLayoutMediator(
fun selectTabAtPosition(position: Int) {
tabLayout.getTabAt(position)?.select()
tabPager.setCurrentItem(position, false)
tabsTrayStore.dispatch(TabsTrayAction.PageSelected(Page.positionToPage(position)))
}
}

View File

@ -254,6 +254,7 @@ class TabsTrayFragment : AppCompatDialogFragment() {
tabLayoutMediator.set(
feature = TabLayoutMediator(
tabLayout = tabsTrayBinding.tabLayout,
tabPager = tabsTrayBinding.tabsTray,
interactor = tabsTrayInteractor,
browsingModeManager = activity.browsingModeManager,
tabsTrayStore = tabsTrayStore,

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.tabstray
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import io.mockk.every
import io.mockk.mockk
@ -23,10 +24,11 @@ class TabLayoutMediatorTest {
private val metrics: MetricController = mockk(relaxed = true)
private val tabLayout: TabLayout = mockk(relaxed = true)
private val tab: TabLayout.Tab = mockk(relaxed = true)
private val viewPager: ViewPager2 = mockk(relaxed = true)
@Test
fun `page to normal tab position when mode is also normal`() {
val mediator = TabLayoutMediator(tabLayout, interactor, modeManager, tabsTrayStore, metrics)
val mediator = TabLayoutMediator(tabLayout, viewPager, interactor, modeManager, tabsTrayStore, metrics)
every { modeManager.mode }.answers { BrowsingMode.Normal }
every { tabLayout.getTabAt(POSITION_NORMAL_TABS) }.answers { tab }
@ -34,12 +36,13 @@ class TabLayoutMediatorTest {
mediator.selectActivePage()
verify { tab.select() }
verify { viewPager.setCurrentItem(POSITION_NORMAL_TABS, false) }
verify { tabsTrayStore.dispatch(TabsTrayAction.PageSelected(Page.positionToPage(POSITION_NORMAL_TABS))) }
}
@Test
fun `page to private tab position when mode is also private`() {
val mediator = TabLayoutMediator(tabLayout, interactor, modeManager, tabsTrayStore, metrics)
val mediator = TabLayoutMediator(tabLayout, viewPager, interactor, modeManager, tabsTrayStore, metrics)
every { modeManager.mode }.answers { BrowsingMode.Private }
every { tabLayout.getTabAt(POSITION_PRIVATE_TABS) }.answers { tab }
@ -52,7 +55,7 @@ class TabLayoutMediatorTest {
@Test
fun `selectTabAtPosition will dispatch the correct TabsTrayStore action`() {
val mediator = TabLayoutMediator(tabLayout, interactor, modeManager, tabsTrayStore, metrics)
val mediator = TabLayoutMediator(tabLayout, viewPager, interactor, modeManager, tabsTrayStore, metrics)
every { tabLayout.getTabAt(POSITION_NORMAL_TABS) }.answers { tab }
every { tabLayout.getTabAt(POSITION_PRIVATE_TABS) }.answers { tab }
@ -73,7 +76,7 @@ class TabLayoutMediatorTest {
@Test
fun `lifecycle methods adds and removes observer`() {
val mediator = TabLayoutMediator(tabLayout, interactor, modeManager, tabsTrayStore, metrics)
val mediator = TabLayoutMediator(tabLayout, viewPager, interactor, modeManager, tabsTrayStore, metrics)
every { modeManager.mode }.answers { BrowsingMode.Private }