* PagedListAdapter is a RecyclerView.Adapter base class which can present the content of PagedLists * in a RecyclerView. It requests new pages as the user scrolls, and handles new PagedLists by * computing list differences on a background thread, and dispatching minimal, efficient updates to * the RecyclerView to ensure minimal UI thread work. *
* If you want to use your own Adapter base class, try using a PagedListAdapterHelper inside your * adapter instead. * * @see android.arch.paging.PagedListAdapter * @see android.arch.paging.PagedListAdapterHelper */ class CheeseAdapter : PagedListAdapter(diffCallback) { override fun onBindViewHolder(holder: CheeseViewHolder, position: Int) { holder.bindTo(getItem(position)) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CheeseViewHolder = CheeseViewHolder(parent) companion object { /** * This diff callback informs the PagedListAdapter how to compute list differences when new * PagedLists arrive. * * When you add a Cheese with the 'Add' button, the PagedListAdapter uses diffCallback to * detect there's only a single item difference from before, so it only needs to animate and * rebind a single view. * * @see android.support.v7.util.DiffUtil */ private val diffCallback = object : DiffCallback() { override fun areItemsTheSame(oldItem: Cheese, newItem: Cheese): Boolean = oldItem.id == newItem.id /** * Note that in kotlin, == checking on data classes compares all contents, but in Java, * typically you'll implement Object#equals, and use it to compare object contents. */ override fun areContentsTheSame(oldItem: Cheese, newItem: Cheese): Boolean = oldItem == newItem } } }
* When you add a Cheese with the 'Add' button, the PagedListAdapter uses diffCallback to * detect there's only a single item difference from before, so it only needs to animate and * rebind a single view. * * @see android.support.v7.util.DiffUtil */ private val diffCallback = object : DiffCallback() { override fun areItemsTheSame(oldItem: Cheese, newItem: Cheese): Boolean = oldItem.id == newItem.id /** * Note that in kotlin, == checking on data classes compares all contents, but in Java, * typically you'll implement Object#equals, and use it to compare object contents. */ override fun areContentsTheSame(oldItem: Cheese, newItem: Cheese): Boolean = oldItem == newItem } } }