callback

inline fun callback(crossinline getOldListSize: () -> Int, crossinline getNewListSize: () -> Int, crossinline areItemsTheSame: (oldItemPosition: Int, newItemPosition: Int) -> Boolean, crossinline areContentsTheSame: (oldItemPosition: Int, newItemPosition: Int) -> Boolean, crossinline getChangePayload: (oldItemPosition: Int, newItemPosition: Int) -> Any? = { _, _ -> null }): DiffUtil.Callback(source)

A Callback class used by DiffUtil while calculating the diff between two lists.

This top-level method allows creating a DiffUtil.Callback without requiring an explicit anonymous object to be created.

Since

0.2.0

Parameters

getOldListSize

Returns the size of the old list.

getNewListSize

Returns the size of the new list.

areItemsTheSame

Called by the DiffUtil to decide whether two object represent the same Item. For example, if your items have unique ids, this method should check their id equality.

areContentsTheSame

Called by the DiffUtil when it wants to check whether two items have the same data. DiffUtil uses this information to detect if the contents of an item has changed.

DiffUtil uses this method to check equality instead of Any.equals so that you can change tts behavior depending on your UI. For example, if you are using DiffUtil with a RecyclerView.Adapter, you should return whether the items' visual representations are the same. This method is called only if areItemsTheSame returns true for these items.

getChangePayload

When areItemsTheSame returns true for two items and areContentsTheSame returns false for them, DiffUtil calls this method to get a payload about the change.

For example, if you are using DiffUtil with RecyclerView, you can return the particular field that changed in the item and your RecyclerView.ItemAnimator can use that information to run the correct animation.

Default implementation returns null.