diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounterMenu.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounterMenu.kt index 6076dbc54..6d6bebe5a 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounterMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounterMenu.kt @@ -81,20 +81,41 @@ class TabCounterMenu( } @VisibleForTesting - internal fun menuItems(showOnly: BrowsingMode?): List { + internal fun menuItems(showOnly: BrowsingMode): List { return when (showOnly) { BrowsingMode.Normal -> listOf(newTabItem) BrowsingMode.Private -> listOf(newPrivateTabItem) - null -> listOf( - newTabItem, - newPrivateTabItem, - DividerMenuCandidate(), - closeTabItem - ) } } - fun updateMenu(showOnly: BrowsingMode? = null) { + @VisibleForTesting + internal fun menuItems(toolbarPosition: ToolbarPosition): List { + val items = listOf( + newTabItem, + newPrivateTabItem, + DividerMenuCandidate(), + closeTabItem + ) + + return when (toolbarPosition) { + ToolbarPosition.BOTTOM -> items.reversed() + ToolbarPosition.TOP -> items + } + } + + /** + * Update the displayed menu items. + * @param showOnly Show only the new tab item corresponding to the given [BrowsingMode]. + */ + fun updateMenu(showOnly: BrowsingMode) { menuController.submitList(menuItems(showOnly)) } + + /** + * Update the displayed menu items. + * @param toolbarPosition Return a list that is ordered based on the given [ToolbarPosition]. + */ + fun updateMenu(toolbarPosition: ToolbarPosition) { + menuController.submitList(menuItems(toolbarPosition)) + } } diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounterToolbarButton.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounterToolbarButton.kt index 0b743e744..118c062ff 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounterToolbarButton.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/TabCounterToolbarButton.kt @@ -34,6 +34,7 @@ class TabCounterToolbarButton( override fun createView(parent: ViewGroup): View { val store = parent.context.components.core.store val metrics = parent.context.components.analytics.metrics + val settings = parent.context.components.settings store.flowScoped(lifecycleOwner) { flow -> flow.map { state -> state.getNormalOrPrivateTabs(isPrivate).size } @@ -42,7 +43,7 @@ class TabCounterToolbarButton( } val menu = TabCounterMenu(parent.context, metrics, onItemTapped) - menu.updateMenu() + menu.updateMenu(settings.toolbarPosition) val view = TabCounter(parent.context).apply { reference = WeakReference(this) diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/TabCounterMenuTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/TabCounterMenuTest.kt index ae6926090..a85c533b2 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/TabCounterMenuTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/TabCounterMenuTest.kt @@ -40,7 +40,7 @@ class TabCounterMenuTest { @Test fun `all items use primary text color styling`() { - val items = menu.menuItems(showOnly = null) + val items = menu.menuItems(ToolbarPosition.BOTTOM) assertEquals(4, items.size) val textItems = items.mapNotNull { it as? TextMenuCandidate } @@ -85,7 +85,7 @@ class TabCounterMenuTest { @Test fun `return two new tab items and a close button`() { - val (newTab, newPrivateTab, divider, closeTab) = menu.menuItems(showOnly = null) + val (newTab, newPrivateTab, divider, closeTab) = menu.menuItems(ToolbarPosition.TOP) assertEquals("New tab", (newTab as TextMenuCandidate).text) assertEquals("New private tab", (newPrivateTab as TextMenuCandidate).text)