public class DiffCallbackImpl<Item extends IItem> extends java.lang.Object implements DiffCallback<Item>
| Constructor and Description |
|---|
DiffCallbackImpl() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
areContentsTheSame(Item oldItem,
Item newItem)
Called by the DiffUtil when it wants to check whether two items have the same data.
|
boolean |
areItemsTheSame(Item oldItem,
Item newItem)
Called by the DiffUtil to decide whether two object represent the same Item.
|
java.lang.Object |
getChangePayload(Item oldItem,
int oldItemPosition,
Item newItem,
int newItemPosition)
When {#areItemsTheSame(Item, Item)} returns
true for two items and
{#areContentsTheSame(Item, Item)} returns false for them, DiffUtil
calls this method to get a payload about the change. |
public boolean areItemsTheSame(Item oldItem, Item newItem)
DiffCallbackareItemsTheSame in interface DiffCallback<Item extends IItem>oldItem - the item in the old listnewItem - the item in the new listpublic boolean areContentsTheSame(Item oldItem, Item newItem)
DiffCallbackObject.equals(Object)
so that you can change its 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(Item, Item) returns
true for these items.areContentsTheSame in interface DiffCallback<Item extends IItem>oldItem - the item in the old listnewItem - the item in the new listpublic java.lang.Object getChangePayload(Item oldItem, int oldItemPosition, Item newItem, int newItemPosition)
DiffCallbacktrue for two items and
{#areContentsTheSame(Item, Item)} 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
ItemAnimator can use that
information to run the correct animation.
Default implementation returns null.getChangePayload in interface DiffCallback<Item extends IItem>oldItemPosition - The position of the item in the old listnewItemPosition - The position of the item in the new list