Skip to content

velos/listadapter-android

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages