Answer the question
In order to leave comments, you need to log in
Magic RV, ListAdapter and DiffUtil?
Hello!
I did pagination up/down according to the standard template - RV, ListAdapter, DiffUtli(itemsTheSame + contentTheSame) with the addition of my ItemLoader to the adapter when approaching the top/bottom edge of the list and subsequent request to the repository.
The data that comes to the adapter is a sorted list of 50 objects, in which a maximum of the 20 first or last changes with each update. No more than 7-8 pieces are visible on the screen. Those. it is guaranteed that each time the list is updated, the currently visible items are present in the new list, have not changed, and have retained their relative position to each other.
When scrolling down, the loader was added like this:
val cachedList = currentData.toMutableList()
cachedList.add(item)
updateData(cachedList.toList())
val cachedList = currentData.toMutableList()
cachedList.add(0, item)
updateData(cachedList.toList())
open fun updateData(data: List<AdapterItem>) {
currentData = data
submitList(data)
}
val cachedList = currentData.toMutableList()
cachedList[0] = item
updateData(cachedList.toList())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question