BatchedCallback
open class BatchedCallback<T2 : Any!> : SortedList.Callback<T2>
kotlin.Any | ||
↳ | androidx.recyclerview.widget.SortedList.Callback<T2> | |
↳ | androidx.recyclerview.widget.SortedList.BatchedCallback |
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 BatchedCallback#dispatchLastEvent()
to flush all changes to the Callback.
Summary
Public constructors | |
---|---|
<init>(wrappedCallback: SortedList.Callback<T2>!) Creates a new BatchedCallback that wraps the provided Callback. |
Public methods | |
---|---|
open Boolean |
areContentsTheSame(oldItem: T2, newItem: T2) |
open Boolean |
areItemsTheSame(item1: T2, item2: T2) |
open Int |
compare(o1: T2, o2: T2) |
open Unit |
This method dispatches any pending event notifications to the wrapped Callback. |
open Any? |
getChangePayload(item1: T2, item2: T2) |
open Unit | |
open Unit | |
open Unit |
onInserted(position: Int, count: Int) |
open Unit | |
open Unit |
Public constructors
<init>
BatchedCallback(wrappedCallback: SortedList.Callback<T2>!)
Creates a new BatchedCallback that wraps the provided Callback.
Parameters | |
---|---|
wrappedCallback |
SortedList.Callback<T2>!: 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
open fun areContentsTheSame(
oldItem: T2,
newItem: T2
): Boolean
areItemsTheSame
open fun areItemsTheSame(
item1: T2,
item2: T2
): Boolean
compare
open fun compare(
o1: T2,
o2: T2
): Int
dispatchLastEvent
open fun dispatchLastEvent(): Unit
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
@Nullable open fun getChangePayload(
item1: T2,