This library is an implementation of ListAdapter that removes the need to implement your own RecyclerView Adapter, ViewHolders and DiffUtil.Callback while allowing better separation between your ViewModel and view.
It automatically handles:
- Heterogenous view types
- DiffUtil callbacks for reordering animations
- ViewHolder implementation: views are automatically cached using Kotlin synthetics
Create an instance of ListAdapter.
From your view model, return a list of ItemContents to your Activity or Fragment.
Build a list of Items and submit it to your ListAdapter using ListAdapter.submitList()
.
ItemContent
should be a Kotlin data class with fields defining the properties for the item's views. The internal DiffUtil callback relies on ItemContent.equals()
to determine if the contents of an item in the list has changed.
Item
requires you to implement the following:
layout: Int
: the layout resource to usecontent: ItemContent
: the content describing this itemfun bind(view: View)
: bind the view toItemContent
See MainActivity.kt and MainViewModel.kt.