Ink
07/02/2021, 11:31 AMCategory
items in my list and now I want to add Header for each single section.
model.apply {
val archiveList: MutableList<ArchiveItem> = mutableListOf()
val itemList: MutableList<ListItem> = mutableListOf()
archives.map {
archiveList.add(
ArchiveItem(
category = it.translateToCategory(it.domain.toString()),
title = it.title,
agreementNumber = it.agreementNumber,
startDate = it.startDate
)
)
archiveList
.sortedBy { it.category }
.groupBy { it.category }
.apply {
itemList.add(ArchiveListHeader(title = "My category"))
}
}
itemList.addAll(archiveList)
items = itemList
}
Ink
07/02/2021, 11:57 AMmodel.apply {
items = archives.groupBy { it.domain }
.map {
listOf(ArchiveListHeader(it.key ?: ""))
.plus(
it.value.map {
ArchiveItem(
category = it.translateToCategory(it.domain.toString()),
title = it.title,
agreementNumber = it.agreementNumber,
startDate = it.startDate
)
}
)
}
.flatten()
}