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 dispatchLastEvent to flush all changes to the Callback.

Constructors

Link copied to clipboard
constructor(wrappedCallback: SortedList.Callback<T2>)
Creates a new BatchedCallback that wraps the provided Callback.

Functions

Link copied to clipboard
open fun areContentsTheSame(oldItem: T2, newItem: T2): Boolean
Called by the SortedList when it wants to check whether two items have the same data or not.
Link copied to clipboard
open fun areItemsTheSame(item1: T2, item2: T2): Boolean
Called by the SortedList to decide whether two objects represent the same Item or not.
Link copied to clipboard
open fun compare(o1: T2, o2: T2): Int
Similar to java.util.Comparator#compare(Object, Object), should compare two and return how they should be ordered.
Link copied to clipboard
This method dispatches any pending event notifications to the wrapped Callback.
Link copied to clipboard
open fun getChangePayload(item1: T2, item2: T2): Any
When #areItemsTheSame(T2, T2) returns true} for two items and #areContentsTheSame(T2, T2) returns false for them, calls this method to get a payload about the change.
Link copied to clipboard
open fun onChanged(position: Int, count: Int)
Called by the SortedList when the item at the given position is updated.
open fun onChanged(position: Int, count: Int, payload: Any)
Link copied to clipboard
open fun onInserted(position: Int, count: Int)
Called when count} number of items are inserted at the given position.
Link copied to clipboard
open fun onMoved(fromPosition: Int, toPosition: Int)
Called when an item changes its position in the list.
Link copied to clipboard
open fun onRemoved(position: Int, count: Int)
Called when count} number of items are removed from the given position.