{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ListenableFutureRemoteMediator

@ExperimentalPagingApi
abstract class ListenableFutureRemoteMediator<Key : Any, Value : Any> : RemoteMediator

kotlin.Any
   ↳ androidx.paging.RemoteMediator
     ↳ androidx.paging.ListenableFutureRemoteMediator

ListenableFuture-based compatibility wrapper around RemoteMediator's suspending APIs.

Summary

Public constructors

<Key : Any, Value : Any> ListenableFutureRemoteMediator()

Public functions

final suspend RemoteMediator.InitializeAction

Callback fired during initialization of a PagingData stream, before initial load.

open ListenableFuture<RemoteMediator.InitializeAction>

Callback fired during initialization of a PagingData stream, before initial load.

final suspend RemoteMediator.MediatorResult
load(loadType: LoadType, state: PagingState<Key, Value>)

Callback triggered when Paging needs to request more data from a remote source due to any of the following events:

abstract ListenableFuture<RemoteMediator.MediatorResult>
loadFuture(loadType: LoadType, state: PagingState<Key, Value>)

Implement this method to load additional remote data, which will then be stored for the PagingSource to access.

Public constructors

ListenableFutureRemoteMediator

<Key : Any, Value : Any> ListenableFutureRemoteMediator()

Public functions

initialize

final suspend fun initialize(): RemoteMediator.InitializeAction

Callback fired during initialization of a PagingData stream, before initial load.

This function runs to completion before any loading is performed.

Returns
RemoteMediator.InitializeAction

InitializeAction used to control whether load with load type REFRESH will be immediately dispatched when the first PagingData is submitted:

initializeFuture

open fun initializeFuture(): ListenableFuture<RemoteMediator.InitializeAction>

Callback fired during initialization of a PagingData stream, before initial load.

This function runs to completion before any loading is performed.

Returns
ListenableFuture<RemoteMediator.InitializeAction>

InitializeAction indicating the action to take after initialization:

load

final suspend fun load(loadType: LoadType, state: PagingState<Key, Value>): RemoteMediator.MediatorResult

Callback triggered when Paging needs to request more data from a remote source due to any of the following events:

It is the responsibility of this method to update the backing dataset and trigger PagingSource.invalidate to allow androidx.paging.PagingDataAdapter to pick up new items found by load.

The runtime and result of this method defines the remote LoadState behavior sent to the UI via CombinedLoadStates.

This method is never called concurrently unless Pager.flow has multiple collectors. Note that Paging might cancel calls to this function if it is currently executing a PREPEND or APPEND and a REFRESH is requested. In that case, REFRESH has higher priority and will be executed after the previous call is cancelled. If the load call with REFRESH returns an error, Paging will call load with the previously cancelled APPEND or PREPEND request. If REFRESH succeeds, it won't make the APPEND or PREPEND requests unless they are necessary again after the REFRESH is applied to the UI.

Parameters
loadType: LoadType

LoadType of the condition which triggered this callback.

  • PREPEND indicates the end of pagination in the PREPEND direction was reached. This occurs when PagingSource.load returns a LoadResult.Page with LoadResult.Page.prevKey == null.

  • APPEND indicates the end of pagination in the APPEND direction was reached. This occurs when PagingSource.load returns a LoadResult.Page with LoadResult.Page.nextKey == null.

  • REFRESH indicates this method was triggered due to a requested refresh. Generally, this means that a request to load remote data and replace all local data was made. This can happen when:

state: PagingState<Key, Value>

A copy of the state including the list of pages currently held in memory of the currently presented PagingData at the time of starting the load. E.g. for load(loadType = APPEND), you can use the page or item at the end as input for what to load from the network.

Returns
RemoteMediator.MediatorResult

MediatorResult signifying what LoadState to be passed to the UI, and whether there's more data available.

loadFuture

abstract fun loadFuture(loadType: LoadType, state: PagingState<Key, Value>): ListenableFuture<RemoteMediator.MediatorResult>

Implement this method to load additional remote data, which will then be stored for the PagingSource to access. These loads take one of two forms:

The runtime of this method defines loading state behavior in boundary conditions, which affects e.g., LoadState callbacks registered to androidx.paging.PagingDataAdapter.

NOTE: A PagingSource.load request which is fulfilled by a page that hits a boundary condition in either direction will trigger this callback with LoadType.PREPEND or LoadType.APPEND or both. LoadType.REFRESH occurs as a result of initialize.

Parameters
loadType: LoadType

LoadType of the boundary condition which triggered this callback.

state: PagingState<Key, Value>

A copy of the state including the list of pages currently held in memory of the currently presented PagingData at the time of starting the load. E.g. for load(loadType = END), you can use the page or item at the end as input for what to load from the network.

Returns
ListenableFuture<RemoteMediator.MediatorResult>

MediatorResult signifying what LoadState to be passed to the UI, and whether there's more data available.