Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 2.23 KB

README.md

File metadata and controls

37 lines (27 loc) · 2.23 KB

ListAdapter

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

How to use

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 use
  • content: ItemContent: the content describing this item
  • fun bind(view: View): bind the view to ItemContent

Example

See MainActivity.kt and MainViewModel.kt.