Google berkomitmen untuk mendorong terwujudnya keadilan ras bagi komunitas Kulit Hitam. Lihat caranya.

PagingDataAdapter

class PagingDataAdapter<T : Any> : ObjectAdapter
kotlin.Any
   ↳ androidx.leanback.widget.ObjectAdapter
   ↳ androidx.leanback.paging.PagingDataAdapter

An ObjectAdapter implemented with an AsyncPagingDataDiffer. It is an analogue of androidx.paging.PagingDataAdapter for leanback widgets.

Summary

Public constructors
<init>(diffCallback: DiffUtil.ItemCallback<T>, mainDispatcher: CoroutineDispatcher = Dispatchers.Main, workerDispatcher: CoroutineDispatcher = Dispatchers.Default)

Constructs an adapter

<init>(presenter: Presenter, diffCallback: DiffUtil.ItemCallback<T>, mainDispatcher: CoroutineDispatcher = Dispatchers.Main, workerDispatcher: CoroutineDispatcher = Dispatchers.Default)

Constructs an adapter

<init>(presenterSelector: PresenterSelector, diffCallback: DiffUtil.ItemCallback<T>, mainDispatcher: CoroutineDispatcher = Dispatchers.Main, workerDispatcher: CoroutineDispatcher = Dispatchers.Default)

Constructs an adapter

Public methods
Unit

Add a CombinedLoadStates listener to observe the loading state of the current PagingData.

T?
get(position: Int)

Returns the item for the given position.

Unit

Refresh the data presented by this PagingDataAdapter.

Unit

Remove a previously registered CombinedLoadStates listener.

Unit

Retry any failed load requests that would result in a LoadState.Error update to this

Int

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.

Inherited functions
Properties
Flow<CombinedLoadStates>

A hot Flow of CombinedLoadStates that emits a snapshot whenever the loading state of the current PagingData changes.

Public constructors

<init>

PagingDataAdapter(
    diffCallback: DiffUtil.ItemCallback<T>,
    mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
    workerDispatcher: CoroutineDispatcher = Dispatchers.Default)

Constructs an adapter

Parameters
diffCallback: DiffUtil.ItemCallback<T> The DiffUtil.ItemCallback instance to compare items in the list.
mainDispatcher: CoroutineDispatcher = Dispatchers.Main The CoroutineDispatcher to be used for foreground operations
workerDispatcher: CoroutineDispatcher = Dispatchers.Default The CoroutineDispatcher to be used for computing diff

<init>

PagingDataAdapter(
    presenter: Presenter,
    diffCallback: DiffUtil.ItemCallback<T>,
    mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
    workerDispatcher: CoroutineDispatcher = Dispatchers.Default)

Constructs an adapter

Parameters
presenter: Presenter Presenter
diffCallback: DiffUtil.ItemCallback<T> The DiffUtil.ItemCallback instance to compare items in the list.
mainDispatcher: CoroutineDispatcher = Dispatchers.Main The CoroutineDispatcher to be used for foreground operations
workerDispatcher: CoroutineDispatcher = Dispatchers.Default The CoroutineDispatcher to be used for computing diff

<init>

PagingDataAdapter(
    presenterSelector: PresenterSelector,
    diffCallback: DiffUtil.ItemCallback<T>,
    mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
    workerDispatcher: CoroutineDispatcher = Dispatchers.Default)

Constructs an adapter

Parameters
presenterSelector: PresenterSelector PresenterSelector
diffCallback: DiffUtil.ItemCallback<T> The DiffUtil.ItemCallback instance to compare items in the list.
mainDispatcher: CoroutineDispatcher = Dispatchers.Main The CoroutineDispatcher to be used for foreground operations
workerDispatcher: CoroutineDispatcher = Dispatchers.Default The CoroutineDispatcher to be used for computing diff

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.

Parameters
listener: (CombinedLoadStates) -> Unit CombinedLoadStates listener to receive updates.

get

fun get(position: Int): T?

Returns the item for the given position. It will return null if placeholders are enabled and data is not yet loaded.

refresh

fun refresh(): Unit

Refresh the data presented by this PagingDataAdapter.

refresh triggers the creation of a new PagingData with a new instance of PagingSource to represent an updated snapshot of the backing dataset. If a RemoteMediator is set, calling refresh will also trigger a call to RemoteMediator.load with LoadType REFRESH] to allow RemoteMediator to check for updates to the dataset backing PagingSource.

Note: This API is intended for UI-driven refresh signals, such as swipe-to-refresh. Invalidation due repository-layer signals, such as DB-updates, should instead use PagingSource.invalidate.

removeLoadStateListener

fun removeLoadStateListener(listener: (CombinedLoadStates) -> Unit): Unit

Remove a previously registered CombinedLoadStates listener.

Parameters
listener: (CombinedLoadStates) -> Unit Previously registered listener.

retry

fun retry(): Unit

Retry any failed load requests that would result in a LoadState.Error update to this

PagingDataAdapter.

LoadState.Error can be generated from two types of load requests: PagingSource.load returning PagingSource.LoadResult.Error returning RemoteMediator.MediatorResult.Error

size

fun size(): Int
Return
Total number of presented items, including placeholders.

submitData

suspend fun submitData(pagingData: PagingData<T>): Unit

Present a PagingData until it is invalidated by a call to refresh or PagingSource.invalidate.

submitData should be called on the same CoroutineDispatcher where updates will be dispatched to UI, typically Dispatchers.Main (this is done for you if you use lifecycleScope.launch {}).

This method is typically used when collecting from a Flow produced by Pager. For RxJava or LiveData support, use the non-suspending overload of submitData, which accepts a Lifecycle.

Note: This method suspends while it is actively presenting page loads from a PagingData, until the PagingData is invalidated. Although cancellation will propagate to this call automatically, collecting from a Pager.flow with the intention of presenting the most up-to-date representation of your backing dataset should typically be done using collectLatest.

See Also

submitData

fun submitData(
    lifecycle: Lifecycle,
    pagingData: PagingData<T>
):