AsyncPagingDataDiffer
class AsyncPagingDataDiffer<T : Any>
kotlin.Any | |
↳ | androidx.paging.AsyncPagingDataDiffer |
Helper class for mapping a PagingData into a RecyclerView.Adapter.
For simplicity, PagingDataAdapter can often be used in place of this class. AsyncPagingDataDiffer is exposed for complex cases, and where overriding PagingDataAdapter to support paging isn't convenient.
Summary
Public constructors | |
---|---|
<init>(diffCallback: DiffUtil.ItemCallback<T>, updateCallback: ListUpdateCallback, mainDispatcher: CoroutineDispatcher = Dispatchers.Main, workerDispatcher: CoroutineDispatcher = Dispatchers.Default) Helper class for mapping a PagingData into a RecyclerView.Adapter. |
Public methods | |
---|---|
Unit |
addLoadStateListener(listener: (CombinedLoadStates) -> Unit) Add a CombinedLoadStates listener to observe the loading state of the current PagingData. |
T? |
Get the item from the current PagedList at the specified index. |
T? |
Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads. |
Unit |
refresh() Refresh the data presented by this AsyncPagingDataDiffer. |
Unit |
removeLoadStateListener(listener: (CombinedLoadStates) -> Unit) Remove a previously registered CombinedLoadStates listener. |
Unit |
retry() Retry any failed load requests that would result in a LoadState.Error update to this AsyncPagingDataDiffer. |
ItemSnapshotList<T> |
snapshot() Returns a new ItemSnapshotList representing the currently presented items, including any placeholders if they are enabled. |
suspend Unit |
submitData(pagingData: PagingData<T>) Present a PagingData until it is invalidated by a call to refresh or PagingSource.invalidate. |
Unit |
submitData(lifecycle: Lifecycle, pagingData: PagingData<T>) Present a PagingData until it is either invalidated or another call to submitData is made. |
Properties | |
---|---|
Int |
Get the number of items currently presented by this Differ. |
Flow<CombinedLoadStates> |
A hot Flow of CombinedLoadStates that emits a snapshot whenever the loading state of the current PagingData changes. |
Public constructors
<init>
AsyncPagingDataDiffer(
diffCallback: DiffUtil.ItemCallback<T>,
updateCallback: ListUpdateCallback,
mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
workerDispatcher: CoroutineDispatcher = Dispatchers.Default)
Helper class for mapping a PagingData into a RecyclerView.Adapter.
For simplicity, PagingDataAdapter can often be used in place of this class. AsyncPagingDataDiffer is exposed for complex cases, and where overriding PagingDataAdapter to support paging isn't convenient.
Public methods
addLoadStateListener
fun addLoadStateListener(listener: (CombinedLoadStates) -> Unit): Unit
Add a CombinedLoadStates listener to observe the loading state of the current PagingData.
As new PagingData generations are submitted and displayed, the listener will be notified to reflect the current CombinedLoadStates.
val adapter = UserPagingAdapter() adapter.addLoadStateListener { // show a retry button outside the list when refresh hits an error retryButton.isVisible = it.refresh is LoadState.Error // swipeRefreshLayout displays whether refresh is occurring swipeRefreshLayout.isRefreshing = it.refresh is LoadState.Loading // show an empty state over the list when loading initially, before items are loaded emptyState.isVisible = it.refresh is LoadState.Loading && adapter.itemCount == 0 }
Parameters | |
---|---|
listener: (CombinedLoadStates) -> Unit | LoadStates listener to receive updates. |
See Also
getItem
fun getItem(@IntRange(0)