public abstract class DiffUtilCallback<M>
extends DiffUtil.Callback
Modifier | Constructor and Description |
---|---|
protected |
DiffUtilCallback(java.util.List<M> oldList,
java.util.List<M> newList) |
Modifier and Type | Method and Description |
---|---|
boolean |
areContentsTheSame(int oldItemPosition,
int newItemPosition) |
abstract boolean |
areContentsTheSame(M oldItem,
M newItem)
Called by the DiffUtil when it wants to check whether two items have the same data.
|
boolean |
areItemsTheSame(int oldItemPosition,
int newItemPosition) |
abstract boolean |
areItemsTheSame(M oldItem,
M newItem)
Called by the DiffUtil to decide whether two object represent the same Item.
|
java.lang.Object |
getChangePayload(int oldItemPosition,
int newItemPosition) |
abstract java.lang.Object |
getChangePayload(M oldItem,
M newItem)
When
areItemsTheSame(int, int) returns true for two items and
areContentsTheSame(int, int) returns false for them, DiffUtil
calls this method to get a payload about the change. |
int |
getNewListSize() |
int |
getOldListSize() |
public int getOldListSize()
public int getNewListSize()
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition)
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition)
public java.lang.Object getChangePayload(int oldItemPosition, int newItemPosition)
public abstract boolean areItemsTheSame(M oldItem, M newItem)
For example, if your items have unique ids, this method should check their id equality.
oldItem
- The item in the old listnewItem
- The item in the new list which replaces the oldItempublic abstract boolean areContentsTheSame(M oldItem, M newItem)
DiffUtil uses this method to check equality instead of Object.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(int, int)
returns
true
for these items.
oldItem
- The item in the old listnewItem
- The item in the new list which replaces the oldItempublic abstract java.lang.Object getChangePayload(M oldItem, M newItem)
areItemsTheSame(int, int)
returns true
for two items and
areContentsTheSame(int, int)
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
.
oldItem
- The item in the old listnewItem
- The item in the new list