Fix headers & footers for search

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-01-26 11:49:30 +01:00
parent 6fa059919f
commit cc103ebc9c
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
2 changed files with 5 additions and 3 deletions

View File

@ -43,6 +43,7 @@ class ContactsViewFooterSource(private val context: Context, private val element
override fun getElementType(data: Data<Participant, String>) = elementType
override fun computeFooters(page: Page, list: List<Participant>): List<Data<Participant, String>> {
lastAnchor = null
val results = arrayListOf<Data<Participant, String>>()
lastAnchor = if (list.isNotEmpty()) {
val participant = list.takeLast(1)[0]

View File

@ -32,12 +32,13 @@ import com.otaliastudios.elements.extensions.HeaderSource
class ContactsHeaderSource(private val context: Context, private val elementType: Int) : HeaderSource<Participant, String>() {
// Store the last header that was added, even if it belongs to a previous page.
private var lastHeader: String = ""
private var headersAlreadyAdded = mutableListOf<String>()
override fun dependsOn(source: Source<*>) = source is ContactsViewSource
override fun computeHeaders(page: Page, list: List<Participant>): List<Data<Participant, String>> {
val results = arrayListOf<Data<Participant, String>>()
headersAlreadyAdded = mutableListOf()
for (participant in list) {
val header = when (participant.source) {
"users" -> {
@ -57,9 +58,9 @@ class ContactsHeaderSource(private val context: Context, private val elementType
}
}
if (header != lastHeader) {
if (!headersAlreadyAdded.contains(header)) {
results.add(Data(participant, header))
lastHeader = header
headersAlreadyAdded.add(header)
}
}