Allow a variant of `update` that is akin to clear+addAll, but using notifyDataSetChanged()
See original GitHub issueIs your feature request related to a problem? Please describe A clear and concise description of what the problem is.
To replace a list of items with a new list of items without using update
(DiffUtil), I’m trying to use clear()
then addAll()
, however, this kills the scroll position on update.
Describe the solution you’d like A clear and concise description of what you want to happen.
Kinda like the (unfortunately private) setNewGroups
method of GroupAdapter
, I’d love to do:
adapter.replaceItems(Collection<? extends Group>)
But using adapter.notifyDataSetChanged
so that scroll position is preserved.
Additional context Add any other context about the problem here.
Currently I’m using a workaround
fun GroupieItemAdapter.replaceItemsWith(
recyclerView: RecyclerView,
withAnimations: Boolean = false,
block: MutableList<GroupieItem>.() -> Unit
): GroupieItemAdapter {
if (withAnimations) {
this.update(mutableListOf<GroupieItem>().apply(block))
} else {
val layoutManager = recyclerView.layoutManager
val state = layoutManager?.onSaveInstanceState()
this.clear()
this.addAll(mutableListOf<GroupieItem>().apply(block))
layoutManager?.onRestoreInstanceState(state) // fixme
}
return this
}
But I’m not really a fan of it, as there’s a good chance this is unpredictable with non-LinearLayoutManagers.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7
Top GitHub Comments
Confirm, in 2.9.0 this feature is available. Thanks for releasing!
If I did every step correctly, 2.9.0 is released with this feature.
The bug fix to the other reported issue should go in
2.9.1
.