Android Paging3 insertSeparators doesn't work as intended

Viewed 562

I'm try to add separators to my list e.g A, "Apple", "Anaconda", B "Boys", "Bostwana" however, insertSeparators doesn't seem to indicate when we are at the beginning or end.

adapter.submitData(pagingData.insertSeparators { before, after ->
    val afterDate = DateItem().withDate(after?.transactionDate)
    val beforeDate = DateItem().withDate(before?.transactionDate)

    if (after != null && (before == null || afterDate.toString() != beforeDate?.toString())) {
        return@insertSeparators afterDate
    }
    return@insertSeparators null
})

My expectations are that before will be null at the beginning while after will be null at the end of the list. But it's never null thus hard to know when we are at the beginning or end.

1 Answers
Related