1
0
Fork 0

For #8766: Show collections only when tabs are open or collection exists

master
mcarare 2020-03-02 15:24:37 +02:00 committed by Emily Kager
parent 0b07f99127
commit 2bb2061931
1 changed files with 44 additions and 19 deletions

View File

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