For #14376: Reverse items with bottom toolbar (#14451)

pull/90/head
Tiger Oakes 4 years ago committed by GitHub
parent 113241e8ce
commit 043e061087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -81,20 +81,41 @@ class TabCounterMenu(
}
@VisibleForTesting
internal fun menuItems(showOnly: BrowsingMode?): List<MenuCandidate> {
internal fun menuItems(showOnly: BrowsingMode): List<MenuCandidate> {
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<MenuCandidate> {
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))
}
}

@ -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)

@ -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)

Loading…
Cancel
Save