[fenix] For https://github.com/mozilla-mobile/fenix/issues/8766: Show collections only when tabs are open or collection exists

pull/600/head
mcarare 5 years ago committed by Emily Kager
parent 39bd2f88c0
commit c7c6fd516a

@ -50,31 +50,56 @@ private fun normalModeAdapterItems(
items.add(AdapterItem.TabHeader(false, tabs.isNotEmpty())) items.add(AdapterItem.TabHeader(false, tabs.isNotEmpty()))
if (tabs.isNotEmpty()) { when {
items.addAll(tabs.reversed().map(AdapterItem::TabItem)) tabs.isNotEmpty() && collections.isNotEmpty() -> {
items.add(AdapterItem.SaveTabGroup) showTabs(items, tabs)
} else { showCollections(collections, expandedCollections, tabs, items)
items.add(noTabMessage) }
}
items.add(AdapterItem.CollectionHeader) tabs.isNotEmpty() && collections.isEmpty() -> {
if (collections.isNotEmpty()) { showTabs(items, tabs)
// If the collection is expanded, we want to add all of its tabs beneath it in the adapter items.add(noCollectionMessage)
collections.map { }
AdapterItem.CollectionItem(it, expandedCollections.contains(it.id), tabs.isNotEmpty())
}.forEach { tabs.isEmpty() && collections.isNotEmpty() -> {
items.add(it) items.add(noTabMessage)
if (it.expanded) { showCollections(collections, expandedCollections, tabs, items)
items.addAll(collectionTabItems(it.collection)) }
}
tabs.isEmpty() && collections.isEmpty() -> {
items.add(noTabMessage)
} }
} else {
items.add(noCollectionMessage)
} }
return items return items
} }
private fun showTabs(
items: MutableList<AdapterItem>,
tabs: List<Tab>
) {
items.addAll(tabs.reversed().map(AdapterItem::TabItem))
items.add(AdapterItem.SaveTabGroup)
}
private fun showCollections(
collections: List<TabCollection>,
expandedCollections: Set<Long>,
tabs: List<Tab>,
items: MutableList<AdapterItem>
) {
// If the collection is expanded, we want to add all of its tabs beneath it in the adapter
items.add(AdapterItem.CollectionHeader)
collections.map {
AdapterItem.CollectionItem(it, expandedCollections.contains(it.id), tabs.isNotEmpty())
}.forEach {
items.add(it)
if (it.expanded) {
items.addAll(collectionTabItems(it.collection))
}
}
}
private fun privateModeAdapterItems(tabs: List<Tab>): List<AdapterItem> { private fun privateModeAdapterItems(tabs: List<Tab>): List<AdapterItem> {
val items = mutableListOf<AdapterItem>() val items = mutableListOf<AdapterItem>()
items.add(AdapterItem.TabHeader(true, tabs.isNotEmpty())) items.add(AdapterItem.TabHeader(true, tabs.isNotEmpty()))

Loading…
Cancel
Save