added in version 22.1.0
belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1

SortedList.BatchedCallback

public static class SortedList.BatchedCallback
extends Callback<T2>

java.lang.Object
   ↳ android.support.v7.util.SortedList.Callback<T2>
     ↳ android.support.v7.util.SortedList.BatchedCallback<T2>


A callback implementation that can batch notify events dispatched by the SortedList.

This class can be useful if you want to do multiple operations on a SortedList but don't want to dispatch each event one by one, which may result in a performance issue.

For example, if you are going to add multiple items to a SortedList, BatchedCallback call convert individual onInserted(index, 1) calls into one onInserted(index, N) if items are added into consecutive indices. This change can help RecyclerView resolve changes much more easily.

If consecutive changes in the SortedList are not suitable for batching, BatchingCallback dispatches them as soon as such case is detected. After your edits on the SortedList is complete, you must always call dispatchLastEvent() to flush all changes to the Callback.

Summary

Public constructors

SortedList.BatchedCallback(Callback<T2> wrappedCallback)

Creates a new BatchedCallback that wraps the provided Callback.

Public methods

boolean areContentsTheSame(T2 oldItem, T2 newItem)

Called by the SortedList when it wants to check whether two items have the same data or not.

boolean areItemsTheSame(T2 item1, T2 item2)

Called by the SortedList to decide whether two objects represent the same Item or not.

int compare(T2 o1, T2 o2)

Similar to compare(Object, Object), should compare two and return how they should be ordered.

void dispatchLastEvent()

This method dispatches any pending event notifications to the wrapped Callback.

Object getChangePayload(T2 item1, T2 item2)

When areItemsTheSame(T2, T2) returns true for two items and areContentsTheSame(T2, T2) returns false for them, SortedList.Callback calls this method to get a payload about the change.

void onChanged(int position, int count, Object payload)

Called when count number of items are updated at the given position.

void onChanged(int position, int count)

Called by the SortedList when the item at the given position is updated.

void onInserted(int position, int count)
void onMoved(int fromPosition, int toPosition)
void onRemoved(int position, int count)

Inherited methods

From class android.support.v7.util.SortedList.Callback
From class java.lang.Object
From interface java.util.Comparator
From interface android.support.v7.util.ListUpdateCallback

Public constructors

SortedList.BatchedCallback

added in version 22.1.0
SortedList.BatchedCallback (Callback<T2> wrappedCallback)

Creates a new BatchedCallback that wraps the provided Callback.

Parameters
wrappedCallback Callback: The Callback which should received the data change callbacks. Other method calls (e.g. compare(Object, Object) from the SortedList are directly forwarded to this Callback.

Public methods

areContentsTheSame

added in version 22.1.0
boolean areContentsTheSame (T2 oldItem, 
                T2 newItem)

Called by the SortedList when it wants to check whether two items have the same data or not. SortedList uses this information to decide whether it should call onChanged(int, int) or not.

SortedList uses this method to check equality instead of equals(Object) so that you can change its behavior depending on your UI.

For example, if you are using SortedList with a RecyclerView.Adapter, you should return whether the items' visual representations are the same or not.

Parameters
oldItem T2: The previous representation of the object.

newItem T2: The new object that replaces the previous one.

Returns
boolean True if the contents of the items are the same or false if they are different.

areItemsTheSame

added in version 22.1.0
boolean areItemsTheSame (T2 item1, 
                T2 item2)

Called by the SortedList to decide whether two objects represent the same Item or not.

For example, if your items have unique ids, this method should check their equality.

Parameters
item1 T2: The first item to check.

item2 T2: The second item to check.

Returns
boolean True if the two items represent the same object or false if they are different.

compare

added in version 22.1.0
int compare (T2 o1, 
                T2 o2)

Similar to compare(Object, Object), should compare two and return how they should be ordered.

Parameters
o1 T2: The first object to compare.

o2 T2: The second object to compare.

Returns
int a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

dispatchLastEvent

added in version 22.1.0
void dispatchLastEvent ()

This method dispatches any pending event notifications to the wrapped Callback. You must always call this method after you are done with editing the SortedList.

getChangePayload

added in version 27.1.0
Object getChangePayload (T2 item1, 
                T2 item2)

When areItemsTheSame(T2, T2) returns true for two items and areContentsTheSame(T2, T2) returns false for them, SortedList.Callback calls this method to get a payload about the change.

For example, if you are using SortedList.Callback 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.

Parameters
item1 T2: The first item to check.

item2 T2: The second item to check.

Returns
Object A payload object that represents the changes between the two items.

onChanged

added in version 25.1.0
void onChanged (int position, 
                int count, 
                Object payload)

Called when count number of items are updated at the given position.

Parameters
position int: The position of the item which has been updated.

count int: The number of items which has changed.

payload Object

onChanged

added in version 22.1.0
void onChanged (int position, 
                int count)

Called by the SortedList when the item at the given position is updated.

Parameters
position int: The position of the item which has been updated.

count int: The number of items which has changed.

onInserted

added in version 22.1.0
void onInserted (int position, 
                int count)

Parameters
position int

count int

onMoved

added in version 22.1.0
void onMoved (int fromPosition, 
                int toPosition)

Parameters
fromPosition int

toPosition int

onRemoved

added in version 22.1.0
void onRemoved (int position, 
                int count)

Parameters
position int

count int