Irurueta Android Recycler View Manager
| This documentation was generated with the assistance of AI. Please report any inaccuracies. |
A small Android library that takes the bookkeeping out of RecyclerView adapter notifications. Give
RecyclerViewManager the previous and the new version of your list, and it calls the right notifyItemInserted,
notifyItemRemoved, notifyItemMoved and notifyItemChanged methods on your adapter, so RecyclerView animates
each change instead of redrawing the whole list.
Why use it
-
Works with any adapter.
RecyclerViewManagerwraps a plainRecyclerView.Adapter. You don’t have to migrate toListAdapter, and you keep full control of how your data is stored. -
Two small rules describe your data. One comparator says whether two items are the same entity (for example, the same id). The other says whether that entity’s content changed (for example, its name).
-
Correct, animated notifications. Changes are detected with the hermes
SequentialListItemChangeDetector. Its positions are relative to the list as each previous change is applied, which is exactly howRecyclerViewinterprets a sequence of notifications.
At a glance
private val adapter = ItemAdapter(emptyList())
private val manager = RecyclerViewManager<ItemViewHolder, Item>(
adapter,
// ItemComparator: are both items the same entity?
{ item1, item2 -> item1.id == item2.id },
// ItemContentComparator: is the content of the same entity unchanged?
{ item1, item2 -> item1.name == item2.name }
)
fun updateItems(newItems: List<Item>) {
val oldItems = adapter.items
// 1. Hand the new data to the adapter first: getItemCount() must already
// return the size of the new list.
adapter.items = newItems
// 2. Compute the differences and notify the adapter (old list first!).
manager.notifyChanges(oldItems, newItems)
}
Where to go next
-
Installation: add the dependency to your build.
-
Usage: a step-by-step guide with code examples.
-
Sample app: the complete example shipped in this repository.
-
Building, testing and contributing: work on the library itself.
-
Reference: API documentation (Dokka) and quality reports.