androidx.paging


Interfaces

AsyncPagedListDiffer.PagedListListener

This interface is deprecated. PagedList is deprecated and has been replaced by PagingData

android
DataSource.InvalidatedCallback

Invalidation callback for DataSource.

android
Logger

This interface is deprecated. Logger interface is no longer supported.

android
PagingSourceFactory

Interface for a factory that generates PagingSource.

Cmn
PlaceholderPaddedList

Interface to paged list that could contain placeholders.

Cmn

Classes

AdjacentItems

Represents a pair of adjacent items, null values are used to signal boundary conditions.

android
AsyncPagedListDiffer

This class is deprecated. AsyncPagedListDiffer is deprecated and has been replaced by AsyncPagingDataDiffer

android
AsyncPagingDataDiffer

Helper class for mapping a PagingData into a RecyclerView.Adapter.

android
CombinedLoadStates

Collection of pagination LoadStates for both a PagingSource, and RemoteMediator.

Cmn
DataSource

Base class for loading pages of snapshot data into a PagedList.

android
DataSource.Factory

Factory for DataSources.

android
InvalidatingPagingSourceFactory

Wrapper class for a PagingSource factory intended for usage in Pager construction.

Cmn
ItemKeyedDataSource

This class is deprecated. ItemKeyedDataSource is deprecated and has been replaced by PagingSource

android
ItemKeyedDataSource.LoadCallback

Callback for ItemKeyedDataSource loadBefore and loadAfter to return data.

android
ItemKeyedDataSource.LoadInitialCallback

Callback for loadInitial to return data and, optionally, position/count information.

android
ItemKeyedDataSource.LoadInitialParams

Holder object for inputs to loadInitial.

android
ItemKeyedDataSource.LoadParams

Holder object for inputs to loadBefore and loadAfter.

android
ItemSnapshotList

Snapshot of data being presented by a androidx.pagingAsyncPagingDataDiffer or a androidx.paging.PagingDataAdapter.

Cmn
ListenableFuturePagingSource

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

android
ListenableFutureRemoteMediator

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

android
LivePagedListBuilder

This class is deprecated. PagedList is deprecated and has been replaced by PagingData

android
LoadState

LoadState of a PagedList load - associated with a LoadType

Cmn
LoadState.Error

Loading hit an error.

Cmn
LoadState.NotLoading

Indicates the PagingData is not currently loading, and no error currently observed.

Cmn
LoadStateAdapter

Adapter for displaying a RecyclerView item based on LoadState, such as a loading spinner, or a retry error button.

android
LoadStates

Collection of pagination LoadStates - refresh, prepend, and append.

Cmn
PageKeyedDataSource

This class is deprecated. PageKeyedDataSource is deprecated and has been replaced by PagingSource

android
PageKeyedDataSource.LoadCallback

Callback for loadBefore and loadAfter to return data.

android
PageKeyedDataSource.LoadInitialCallback

Callback for loadInitial to return data and, optionally, position/count information.

android
PageKeyedDataSource.LoadInitialParams

Holder object for inputs to loadInitial.

android
PageKeyedDataSource.LoadParams

Holder object for inputs to loadBefore and loadAfter.

android
PagedList

This class is deprecated. PagedList is deprecated and has been replaced by PagingData

android
PagedList.BoundaryCallback

Signals when a PagedList has reached the end of available data.

android
PagedList.Builder

This class is deprecated. PagedList is deprecated and has been replaced by PagingData, which no longer supports constructing snapshots of loaded data manually.

android
PagedList.Callback

Callback signaling when content is loaded into the list.

android
PagedList.Config

Configures how a PagedList loads content from its PagingSource.

android
PagedList.Config.Builder

Builder class for PagedList.Config.

android
PagedListAdapter

This class is deprecated. PagedListAdapter is deprecated and has been replaced by PagingDataAdapter

android
Pager

Primary entry point into Paging; constructor for a reactive stream of PagingData.

Cmn
PagingConfig

An object used to configure loading behavior within a Pager, as it loads content from a PagingSource.

Cmn
PagingData

Container for Paged data from a single generation of loads.

Cmn
PagingDataAdapter

RecyclerView.Adapter base class for presenting paged data from PagingDatas in a RecyclerView.

android
PagingDataEvent

Events captured from a PagingData that was submitted to the PagingDataPresenter

Cmn
PagingDataEvent.Append

An append load event

Cmn
PagingDataEvent.DropAppend

A drop event from the end of the list

Cmn
PagingDataEvent.DropPrepend

A drop event from the front of the list

Cmn
PagingDataEvent.Prepend

A prepend load event

Cmn
PagingDataEvent.Refresh

A refresh load event

Cmn
PagingDataPresenter

The class that connects the UI layer to the underlying Paging operations.

Cmn
PagingSource

Base class for an abstraction of pageable static data from some source, where loading pages of data is typically an expensive operation.

Cmn
PagingSource.LoadParams

Params for a load request on a PagingSource from PagingSource.load.

Cmn
PagingSource.LoadParams.Append

Params to load a page of data from a PagingSource via PagingSource.load to be appended to the end of the list.

Cmn
PagingSource.LoadParams.Prepend

Params to load a page of data from a PagingSource via PagingSource.load to be prepended to the start of the list.

Cmn
PagingSource.LoadParams.Refresh

Params for an initial load request on a PagingSource from PagingSource.load or a refresh triggered by invalidate.

Cmn
PagingSource.LoadResult

Result of a load request from PagingSource.load.

Cmn
PagingSource.LoadResult.Error

Error result object for PagingSource.load.

Cmn
PagingSource.LoadResult.Invalid

Invalid result object for PagingSource.load

Cmn
PagingSource.LoadResult.Page

Success result object for PagingSource.load.

Cmn
PagingState

Snapshot state of Paging system including the loaded pages, the last accessed anchorPosition, and the config used.

Cmn
PositionalDataSource

This class is deprecated. PositionalDataSource is deprecated and has been replaced by PagingSource

android
PositionalDataSource.LoadInitialCallback

Callback for loadInitial to return data, position, and count.

android
PositionalDataSource.LoadInitialParams

Holder object for inputs to loadInitial.

android
PositionalDataSource.LoadRangeCallback

Callback for PositionalDataSource loadRange to return data.

android
PositionalDataSource.LoadRangeParams

Holder object for inputs to loadRange.

android
RemoteMediator

Defines a set of callbacks used to incrementally load data from a remote source into a local source wrapped by a PagingSource, e.g., loading data from network into a local db cache.

Cmn
RemoteMediator.MediatorResult

Return type of load, which determines LoadState.

Cmn
RemoteMediator.MediatorResult.Error

Recoverable error that can be retried, sets the LoadState to LoadState.Error.

Cmn
RemoteMediator.MediatorResult.Success

Success signaling that LoadState should be set to LoadState.NotLoading if endOfPaginationReached is true, otherwise LoadState is kept at LoadState.Loading to await invalidation.

Cmn
RxPagedListBuilder

This class is deprecated. PagedList is deprecated and has been replaced by PagingData

android

Objects

LoadState.Loading

Loading is in progress.

Cmn

Annotations

ExperimentalPagingApi

Marks experimental Paging APIs, which may have known issues that would likely be solved by a source-incompatible change in newer versions of the artifact that supplies it.

Cmn

Enums

LoadType

Type of load a PagingData can trigger a PagingSource to perform.

Cmn
RemoteMediator.InitializeAction

Return type of initialize, which signals the action to take after initialize completes.

Cmn
TerminalSeparatorType

Mode for configuring when terminal separators (header and footer) would be displayed by the insertSeparators, insertHeaderItem or insertFooterItem operators on PagingData.

Cmn

Top-level functions summary

PagedList.Config
Config(
    pageSize: Int,
    prefetchDistance: Int,
    enablePlaceholders: Boolean,
    initialLoadSizeHint: Int,
    maxSize: Int
)

Constructs a PagedList.Config, convenience for PagedList.Config.Builder.

android
PagedList<Value>
<Key : Any, Value : Any> PagedList(
    dataSource: DataSource<Key, Value>,
    config: PagedList.Config,
    notifyExecutor: Executor,
    fetchExecutor: Executor,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    initialKey: Key?
)

This function is deprecated. DataSource is deprecated and has been replaced by PagingSource

android

Extension functions summary

suspend CombinedLoadStates?

Function to wait on a Flow until a load has completed.

Cmn
LiveData<PagingData<T>>
<T : Any> LiveData<PagingData<T>>.cachedIn(lifecycle: Lifecycle)

Operator which caches a LiveData of PagingData within the scope of a Lifecycle.

android
Flow<PagingData<T>>

Caches the PagingData such that any downstream collection from this flow will share the same PagingData.

Cmn
LiveData<PagingData<T>>

Operator which caches a LiveData of PagingData within a CoroutineScope.

android
LiveData<PagingData<T>>
<T : Any> LiveData<PagingData<T>>.cachedIn(viewModel: ViewModel)

Operator which caches a LiveData of PagingData within the scope of a ViewModel.

android
PagingData<T>
<T : Any> PagingData<T>.filter(predicate: suspend (T) -> Boolean)

Returns a PagingData containing only elements matching the given predicate

Cmn
PagingData<T>
<T : Any> PagingData<T>.filter(executor: Executor, predicate: (T) -> Boolean)

Returns a PagingData containing only elements matching the given predicate.

android
PagingData<T>
<T : Any> PagingData<T>.filterAsync(
    predicate: AsyncFunction<T, Boolean>,
    executor: Executor
)

Returns a PagingData containing only elements matching the given predicate.

android
PagingData<R>
<T : Any, R : Any> PagingData<T>.flatMap(transform: suspend (T) -> Iterable<R>)

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

Cmn
PagingData<R>
<T : Any, R : Any> PagingData<T>.flatMap(
    executor: Executor,
    transform: (T) -> Iterable<R>
)

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

android
PagingData<R>
<T : Any, R : Any> PagingData<T>.flatMapAsync(
    transform: AsyncFunction<T, Iterable<R>>,
    executor: Executor
)

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

android
PagingData<T>
<T : Any> PagingData<T>.insertFooterItem(
    terminalSeparatorType: TerminalSeparatorType,
    item: T
)

Returns a PagingData containing each original element, with the passed footer item added to the end of the list.

Cmn
PagingData<T>
<T : Any> PagingData<T>.insertHeaderItem(
    terminalSeparatorType: TerminalSeparatorType,
    item: T
)

Returns a PagingData containing each original element, with the passed header item added to the start of the list.

Cmn
PagingData<R>
<T : R, R : Any> PagingData<T>.insertSeparators(
    terminalSeparatorType: TerminalSeparatorType,
    generator: suspend (T?, T?) -> R?
)

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

Cmn
PagingData<R>
<R : Any, T : R> PagingData<T>.insertSeparators(
    terminalSeparatorType: TerminalSeparatorType,
    executor: Executor,
    generator: (T?, T?) -> R?
)

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

android
PagingData<R>
<T : R, R : Any> PagingData<T>.insertSeparatorsAsync(
    generator: AsyncFunction<AdjacentItems<T>, R?>,
    executor: Executor
)

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

android
PagingData<R>
<T : Any, R : Any> PagingData<T>.map(transform: suspend (T) -> R)

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

Cmn
PagingData<R>
<T : Any, R : Any> PagingData<T>.map(executor: Executor, transform: (T) -> R)

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

android
PagingData<R>
<T : Any, R : Any> PagingData<T>.mapAsync(
    transform: AsyncFunction<T, R>,
    executor: Executor
)

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

android
Flowable<PagedList<Value>>
<Key : Any, Value : Any> DataSource.Factory<Key, Value>.toFlowable(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?,
    backpressureStrategy: BackpressureStrategy
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Flowable<PagedList<Value>>
<Key : Any, Value : Any> () -> PagingSource<Key, Value>.toFlowable(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?,
    backpressureStrategy: BackpressureStrategy
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Flowable<PagedList<Value>>
<Key : Any, Value : Any> DataSource.Factory<Key, Value>.toFlowable(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?,
    backpressureStrategy: BackpressureStrategy
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Flowable<PagedList<Value>>
<Key : Any, Value : Any> () -> PagingSource<Key, Value>.toFlowable(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?,
    backpressureStrategy: BackpressureStrategy
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
LiveData<PagedList<Value>>
<Key : Any, Value : Any> DataSource.Factory<Key, Value>.toLiveData(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchExecutor: Executor
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
LiveData<PagedList<Value>>
<Key : Any, Value : Any> DataSource.Factory<Key, Value>.toLiveData(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchExecutor: Executor
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
LiveData<PagedList<Value>>
<Key : Any, Value : Any> () -> PagingSource<Key, Value>.toLiveData(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    coroutineScope: CoroutineScope,
    fetchDispatcher: CoroutineDispatcher
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
LiveData<PagedList<Value>>
<Key : Any, Value : Any> () -> PagingSource<Key, Value>.toLiveData(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    coroutineScope: CoroutineScope,
    fetchDispatcher: CoroutineDispatcher
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Observable<PagedList<Value>>
<Key : Any, Value : Any> DataSource.Factory<Key, Value>.toObservable(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Observable<PagedList<Value>>
<Key : Any, Value : Any> () -> PagingSource<Key, Value>.toObservable(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Observable<PagedList<Value>>
<Key : Any, Value : Any> DataSource.Factory<Key, Value>.toObservable(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Observable<PagedList<Value>>
<Key : Any, Value : Any> () -> PagingSource<Key, Value>.toObservable(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback<Value>?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android

Extension properties summary

LiveData<PagingData<Value>>
Pager<Key, Value>.liveData

A LiveData of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as a LiveData.

android

Top-level functions

Config

fun Config(
    pageSize: Int,
    prefetchDistance: Int = pageSize,
    enablePlaceholders: Boolean = true,
    initialLoadSizeHint: Int = pageSize * PagedList.Config.Builder.DEFAULT_INITIAL_PAGE_MULTIPLIER,
    maxSize: Int = PagedList.Config.MAX_SIZE_UNBOUNDED
): PagedList.Config

Constructs a PagedList.Config, convenience for PagedList.Config.Builder.

Parameters
pageSize: Int

Number of items loaded at once from the DataSource.

prefetchDistance: Int = pageSize

Distance the PagedList should prefetch.

enablePlaceholders: Boolean = true

False if null placeholders should be disabled.

initialLoadSizeHint: Int = pageSize * PagedList.Config.Builder.DEFAULT_INITIAL_PAGE_MULTIPLIER

Number of items to load while initializing the PagedList.

maxSize: Int = PagedList.Config.MAX_SIZE_UNBOUNDED

Maximum number of items to keep in memory, or PagedList.Config.MAX_SIZE_UNBOUNDED to disable page dropping.

PagedList

fun <Key : Any, Value : Any> PagedList(
    dataSource: DataSource<Key, Value>,
    config: PagedList.Config,
    notifyExecutor: Executor,
    fetchExecutor: Executor,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    initialKey: Key? = null
): PagedList<Value>

Constructs a PagedList, convenience for PagedList.Builder.

Parameters
<Key : Any>

Type of key used to load data from the DataSource.

<Value : Any>

Type of items held and loaded by the PagedList.

dataSource: DataSource<Key, Value>

DataSource the PagedList will load from.

config: PagedList.Config

Config that defines how the PagedList loads data from its DataSource.

notifyExecutor: Executor

Executor that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI/main thread.

fetchExecutor: Executor

Executor used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

PagedList.BoundaryCallback for listening to out-of-data events.

initialKey: Key? = null

Key the DataSource should load around as part of initialization.

Extension functions

awaitNotLoading

suspend fun Flow<CombinedLoadStates>.awaitNotLoading(): CombinedLoadStates?

Function to wait on a Flow until a load has completed.

It collects on the Flow and suspends until it collects and returns the firstOrNull CombinedLoadStates where all LoadStates have settled into a non-loading state i.e. LoadState.NotLoading or LoadState.Error.

A use case could be scrolling to a position after refresh has completed:

override fun onCreate(savedInstanceState: Bundle?) {
...
refreshButton.setOnClickListener {
pagingAdapter.refresh()
lifecycleScope.launch {
// wait for refresh to complete
pagingAdapter.loadStateFlow.awaitNotLoading()
// do work after refresh
recyclerView.scrollToPosition(position)
}
}
}

cachedIn

fun <T : Any> LiveData<PagingData<T>>.cachedIn(lifecycle: Lifecycle): LiveData<PagingData<T>>

Operator which caches a LiveData of PagingData within the scope of a Lifecycle.

cachedIn multicasts pages loaded and transformed by a PagingData, allowing multiple observers on the same instance of PagingData to receive the same events, avoiding redundant work, but comes at the cost of buffering those pages in memory.

Calling cachedIn is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of PagingData emitted by Pager or any of its transformed derivatives, as reloading data from scratch on the same generation of PagingData is an unsupported operation.

Parameters
lifecycle: Lifecycle

The Lifecycle where the page cache will be kept alive.

cachedIn

fun <T : Any> Flow<PagingData<T>>.cachedIn(scope: CoroutineScope): Flow<PagingData<T>>

Caches the PagingData such that any downstream collection from this flow will share the same PagingData.

The flow is kept active as long as the given scope is active. To avoid leaks, make sure to use a scope that is already managed (like a ViewModel scope) or manually cancel it when you don't need paging anymore.

A common use case for this caching is to cache PagingData in a ViewModel. This can ensure that, upon configuration change (e.g. rotation), then new Activity will receive the existing data immediately rather than fetching it from scratch.

Calling cachedIn is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of PagingData emitted by Pager or any of its transformed derivatives, as reloading data from scratch on the same generation of PagingData is an unsupported operation.

Note that this does not turn the Flow<PagingData> into a hot stream. It won't execute any unnecessary code unless it is being collected.

import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.cachedIn
import androidx.paging.map

class MyViewModel : ViewModel() {
    val flow = Pager(
        config = PagingConfig(pageSize = 40),
        pagingSourceFactory = pagingSourceFactory
    ).flow
        // Loads and transformations before the cachedIn operation will be cached, so that
        // multiple observers get the same data. This is true either for simultaneous
        // observers, or e.g. an Activity re-subscribing after being recreated
        .cachedIn(viewModelScope)
}

class MyActivity : AppCompatActivity() {
    val pagingAdapter = MyPagingAdapter()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val viewModel by viewModels<MyViewModel>()

        lifecycleScope.launch {
            viewModel.flow
                // Any transformations after the ViewModel's cachedIn step will not be cached,
                // and will instead by re-run immediately on Activity re-creation.
                .map { pagingData ->
                    // example un-cached transformation
                    pagingData.map { UiModel(it) }
                }
                .collectLatest {
                    pagingAdapter.submitData(it)
                }
        }
    }
}
Parameters
scope: CoroutineScope

The coroutine scope where this page cache will be kept alive.

cachedIn

fun <T : Any> LiveData<PagingData<T>>.cachedIn(scope: CoroutineScope): LiveData<PagingData<T>>

Operator which caches a LiveData of PagingData within a CoroutineScope.

cachedIn multicasts pages loaded and transformed by a PagingData, allowing multiple observers on the same instance of PagingData to receive the same events, avoiding redundant work, but comes at the cost of buffering those pages in memory.

Calling cachedIn is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of PagingData emitted by Pager or any of its transformed derivatives, as reloading data from scratch on the same generation of PagingData is an unsupported operation.

Parameters
scope: CoroutineScope

The CoroutineScope where the page cache will be kept alive. Typically this would be a managed scope such as ViewModel.viewModelScope, which automatically cancels after the PagingData stream is no longer needed. Otherwise, the provided CoroutineScope must be manually cancelled to avoid memory leaks.

cachedIn

fun <T : Any> LiveData<PagingData<T>>.cachedIn(viewModel: ViewModel): LiveData<PagingData<T>>

Operator which caches a LiveData of PagingData within the scope of a ViewModel.

cachedIn multicasts pages loaded and transformed by a PagingData, allowing multiple observers on the same instance of PagingData to receive the same events, avoiding redundant work, but comes at the cost of buffering those pages in memory.

Calling cachedIn is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of PagingData emitted by Pager or any of its transformed derivatives, as reloading data from scratch on the same generation of PagingData is an unsupported operation.

Parameters
viewModel: ViewModel

The ViewModel whose viewModelScope will dictate how long the page cache will be kept alive.

filter

fun <T : Any> PagingData<T>.filter(predicate: suspend (T) -> Boolean): PagingData<T>

Returns a PagingData containing only elements matching the given predicate

filter

fun <T : Any> PagingData<T>.filter(executor: Executor, predicate: (T) -> Boolean): PagingData<T>

Returns a PagingData containing only elements matching the given predicate.

See also
filter

filterAsync

fun <T : Any> PagingData<T>.filterAsync(
    predicate: AsyncFunction<T, Boolean>,
    executor: Executor
): PagingData<T>

Returns a PagingData containing only elements matching the given predicate.

Parameters
predicate: AsyncFunction<T, Boolean>

AsyncFunction returning false for unmatched items which should be filtered.

executor: Executor

Executor to run the AsyncFunction in.

fun <T : Any, R : Any> PagingData<T>.flatMap(transform: suspend (T) -> Iterable<R>): PagingData<R>

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

flatMap

fun <T : Any, R : Any> PagingData<T>.flatMap(
    executor: Executor,
    transform: (T) -> Iterable<R>
): PagingData<R>

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

See also
flatMap

flatMapAsync

fun <T : Any, R : Any> PagingData<T>.flatMapAsync(
    transform: AsyncFunction<T, Iterable<R>>,
    executor: Executor
): PagingData<R>

Returns a PagingData of all elements returned from applying the given transform to each element, as it is loaded.

Parameters
transform: AsyncFunction<T, Iterable<R>>

AsyncFunction to transform an item of type T a list of items of type R.

executor: Executor

Executor to run the AsyncFunction in.

insertFooterItem

fun <T : Any> PagingData<T>.insertFooterItem(
    terminalSeparatorType: TerminalSeparatorType = FULLY_COMPLETE,
    item: T
): PagingData<T>

Returns a PagingData containing each original element, with the passed footer item added to the end of the list.

The footer item is added to a loaded page which marks the end of the data stream in the LoadType.APPEND direction, either by returning null in PagingSource.LoadResult.Page.nextKey. It will be removed if the last page in the list is dropped, which can happen in the case of loaded pages exceeding PagingConfig.maxSize.

Note: This operation is not idempotent, calling it multiple times will continually add more footers to the end of the list, which can be useful if multiple footer items are required.

Parameters
terminalSeparatorType: TerminalSeparatorType = FULLY_COMPLETE

TerminalSeparatorType used to configure when the header and footer are added.

item: T

The footer to add to the end of the list once it is fully loaded in the LoadType.APPEND direction.

See also
insertHeaderItem

insertHeaderItem

fun <T : Any> PagingData<T>.insertHeaderItem(
    terminalSeparatorType: TerminalSeparatorType = FULLY_COMPLETE,
    item: T
): PagingData<T>

Returns a PagingData containing each original element, with the passed header item added to the start of the list.

The header item is added to a loaded page which marks the end of the data stream in the LoadType.PREPEND direction by returning null in PagingSource.LoadResult.Page.prevKey. It will be removed if the first page in the list is dropped, which can happen in the case of loaded pages exceeding PagingConfig.maxSize.

Note: This operation is not idempotent, calling it multiple times will continually add more headers to the start of the list, which can be useful if multiple header items are required.

Parameters
terminalSeparatorType: TerminalSeparatorType = FULLY_COMPLETE

TerminalSeparatorType used to configure when the header and footer are added.

item: T

The header to add to the front of the list once it is fully loaded in the LoadType.PREPEND direction.

See also
insertFooterItem

insertSeparators

fun <T : R, R : Any> PagingData<T>.insertSeparators(
    terminalSeparatorType: TerminalSeparatorType = FULLY_COMPLETE,
    generator: suspend (T?, T?) -> R?
): PagingData<R>

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

Note that this transform is applied asynchronously, as pages are loaded. Potential separators between pages are only computed once both pages are loaded.

import androidx.paging.insertSeparators

/*
 * Create letter separators in an alphabetically sorted list.
 *
 * For example, if the input is:
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData.insertSeparators { before: String?, after: String? ->
        if (after != null && before?.first() != after.first()) {
            // separator - after is first item that starts with its first letter
            after.first().uppercaseChar().toString()
        } else {
            // no separator - either end of list, or first letters of before/after are the same
            null
        }
    }
}
import androidx.paging.insertSeparators
import androidx.paging.map

open class UiModel
data class ItemUiModel(val item: Item) : UiModel()
data class SeparatorUiModel(val char: Char) : UiModel()

/*
 * Create letter separators in an alphabetically sorted list of Items, with UiModel objects.
 *
 * For example, if the input is (each an `Item`):
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output a list of UiModels corresponding to:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData
        .map { item ->
            ItemUiModel(item) // convert items in stream to ItemUiModel
        }
        .insertSeparators<ItemUiModel, UiModel> { before: ItemUiModel?, after: ItemUiModel? ->
            if (after != null && before?.item?.label?.first() != after.item.label.first()) {
                // separator - after is first item that starts with its first letter
                SeparatorUiModel(after.item.label.first().uppercaseChar())
            } else {
                // no separator - either end of list, or first letters of before/after are the same
                null
            }
        }
}
Parameters
terminalSeparatorType: TerminalSeparatorType = FULLY_COMPLETE

TerminalSeparatorType used to configure when the header and footer are added.

generator: suspend (T?, T?) -> R?

Generator function used to construct a separator item given the item before and the item after. For terminal separators (header and footer), the arguments passed to the generator, before and after, will be null respectively. In cases where the fully paginated list is empty, a single separator will be added where both before and after items are null.

insertSeparators

fun <R : Any, T : R> PagingData<T>.insertSeparators(
    terminalSeparatorType: TerminalSeparatorType = TerminalSeparatorType.FULLY_COMPLETE,
    executor: Executor,
    generator: (T?, T?) -> R?
): PagingData<R>

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

Note that this transform is applied asynchronously, as pages are loaded. Potential separators between pages are only computed once both pages are loaded.

Kotlin callers should instead use the suspending extension function variant of insertSeparators

/*
* Create letter separators in an alphabetically sorted list.
*
* For example, if the input is:
* "apple", "apricot", "banana", "carrot"
*
* The operator would output:
* "A", "apple", "apricot", "B", "banana", "C", "carrot"
*/
pagingDataStream.map(pagingData ->
// map outer stream, so we can perform transformations on each paging generation
PagingDataTransforms.insertSeparators(pagingData, bgExecutor,
(@Nullable String before, @Nullable String after) -> {
if (after != null && (before == null
|| before.charAt(0) != after.charAt(0))) {
// separator - after is first item that starts with its first
// letter
return Character.toString(
Character.toUpperCase(after.charAt(0)));
} else {
// no separator - either end of list, or first
// letters of items are the same
return null;
}
}));

/*
* Create letter separators in an alphabetically sorted list of Items, with UiModel
* objects.
*
* For example, if the input is (each an `Item`):
* "apple", "apricot", "banana", "carrot"
*
* The operator would output a list of UiModels corresponding to:
* "A", "apple", "apricot", "B", "banana", "C", "carrot"
*/
pagingDataStream.map(itemPagingData -> {
// map outer stream, so we can perform transformations on each paging generation

// first convert items in stream to UiModel.Item
PagingData<UiModel.ItemModel> itemModelPagingData = PagingDataTransforms.map(
itemPagingData, bgExecutor, UiModel.ItemModel::new);

// Now insert UiModel.Separators, which makes the PagingData of generic type UiModel
return PagingDataTransforms.insertSeparators(
itemModelPagingData, bgExecutor,
(@Nullable UiModel.ItemModel before, @Nullable UiModel.ItemModel after) -> {
if (after != null && (before == null
|| before.item.label.charAt(0) != after.item.label.charAt(0))) {
// separator - after is first item that starts with its first letter
return new UiModel.SeparatorModel(
Character.toUpperCase(after.item.label.charAt(0)));
} else {
// no separator - either end of list, or first
// letters of items are the same
return null;
}
});
});

public class UiModel {
static class ItemModel extends UiModel {
public Item item;
ItemModel(Item item) {
this.item = item;
}
}
static class SeparatorModel extends UiModel {
public char character;
SeparatorModel(char character) {
this.character = character;
}
}
}
Parameters
terminalSeparatorType: TerminalSeparatorType = TerminalSeparatorType.FULLY_COMPLETE

TerminalSeparatorType used to configure when the header and footer are added.

executor: Executor

Executor to run the generator function in.

generator: (T?, T?) -> R?

Generator function used to construct a separator item given the item before and the item after. For terminal separators (header and footer), the arguments passed to the generator, before and after, will be null respectively. In cases where the fully paginated list is empty, a single separator will be added where both before and after items are null.

insertSeparatorsAsync

fun <T : R, R : Any> PagingData<T>.insertSeparatorsAsync(
    generator: AsyncFunction<AdjacentItems<T>, R?>,
    executor: Executor
): PagingData<R>

Returns a PagingData containing each original element, with an optional separator generated by generator, given the elements before and after (or null, in boundary conditions).

Note that this transform is applied asynchronously, as pages are loaded. Potential separators between pages are only computed once both pages are loaded.

import androidx.paging.AdjacentItems
import androidx.paging.insertSeparators
import androidx.paging.insertSeparatorsAsync
import androidx.paging.rxjava2.insertSeparatorsAsync

/*
 * Create letter separators in an alphabetically sorted list.
 *
 * For example, if the input is:
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData.insertSeparatorsAsync(
        AsyncFunction<AdjacentItems<String>, String?> {
            Futures.submit(
                Callable<String?> {
                    val (before, after) = it!!
                    if (after != null && before?.first() != after.first()) {
                        // separator - after is first item that starts with its first letter
                        after.first().uppercaseChar().toString()
                    } else {
                        // no separator - either end of list, or first letters of before/after are the same
                        null
                    }
                },
                executor
            )
        },
        executor
    )
}
import androidx.paging.AdjacentItems
import androidx.paging.insertSeparators
import androidx.paging.insertSeparatorsAsync
import androidx.paging.map
import androidx.paging.rxjava2.insertSeparatorsAsync

open class UiModel
data class ItemUiModel(val item: Item) : UiModel()
data class SeparatorUiModel(val char: Char) : UiModel()

/*
 * Create letter separators in an alphabetically sorted list of Items, with UiModel objects.
 *
 * For example, if the input is (each an `Item`):
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output a list of UiModels corresponding to:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData
        .map { item ->
            ItemUiModel(item) // convert items in stream to ItemUiModel
        }
        .insertSeparatorsAsync(
            AsyncFunction<AdjacentItems<ItemUiModel>, UiModel?> {
                Futures.submit(
                    Callable<UiModel> {
                        val (before, after) = it!!
                        if (after != null &&
                            before?.item?.label?.first() != after.item.label.first()
                        ) {
                            // separator - after is first item that starts with its first letter
                            SeparatorUiModel(after.item.label.first().uppercaseChar())
                        } else {
                            // no separator - either end of list, or first letters of before/after are the same
                            null
                        }
                    },
                    executor
                )
            },
            executor
        )
}
Parameters
generator: AsyncFunction<AdjacentItems<T>, R?>

AsyncFunction used to generate separator between two AdjacentItems or the header or footer if either AdjacentItems.before or AdjacentItems.after is null.

executor: Executor

Executor to run the AsyncFunction in.

map

fun <T : Any, R : Any> PagingData<T>.map(transform: suspend (T) -> R): PagingData<R>

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

map

fun <T : Any, R : Any> PagingData<T>.map(executor: Executor, transform: (T) -> R): PagingData<R>

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

See also
map

mapAsync

fun <T : Any, R : Any> PagingData<T>.mapAsync(
    transform: AsyncFunction<T, R>,
    executor: Executor
): PagingData<R>

Returns a PagingData containing the result of applying the given transform to each element, as it is loaded.

Parameters
transform: AsyncFunction<T, R>

AsyncFunction to transform an item of type T to R.

executor: Executor

Executor to run the AsyncFunction in.

toFlowable

fun <Key : Any, Value : Any> DataSource.Factory<Key, Value>.toFlowable(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null,
    backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST
): Flowable<PagedList<Value>>

Constructs a Flowable<PagedList>, from this DataSource.Factory, convenience for RxPagedListBuilder.

The returned Flowable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.

Parameters
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

Scheduler used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.

notifyScheduler: Scheduler? = null

Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI / main thread.

backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST

BackpressureStrategy for the Flowable to use.

toFlowable

fun <Key : Any, Value : Any> () -> PagingSource<Key, Value>.toFlowable(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null,
    backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST
): Flowable<PagedList<Value>>

Constructs a Flowable<PagedList>, from this PagingSource factory, convenience for RxPagedListBuilder.

The returned Flowable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.

Parameters
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

Scheduler used to fetch from PagingSources, generally a background thread pool for e.g. I/O or network loading.

notifyScheduler: Scheduler? = null

Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI / main thread.

backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST

BackpressureStrategy for the Flowable to use.

toFlowable

fun <Key : Any, Value : Any> DataSource.Factory<Key, Value>.toFlowable(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null,
    backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST
): Flowable<PagedList<Value>>

Constructs a Flowable<PagedList>, from this DataSource.Factory, convenience for RxPagedListBuilder.

The returned Flowable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.

Parameters
pageSize: Int

Page size.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

Scheduler used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.

notifyScheduler: Scheduler? = null

Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI / main thread.

backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST

BackpressureStrategy for the Flowable to use.

toFlowable

fun <Key : Any, Value : Any> () -> PagingSource<Key, Value>.toFlowable(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null,
    backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST
): Flowable<PagedList<Value>>

Constructs a Flowable<PagedList>, from this PagingSource factory, convenience for RxPagedListBuilder.

The returned Flowable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.

Parameters
pageSize: Int

Page size.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

Scheduler used to fetch from PagingSources, generally a background thread pool for e.g. I/O or network loading.

notifyScheduler: Scheduler? = null

Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI / main thread.

backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST

BackpressureStrategy for the Flowable to use.

toLiveData

fun <Key : Any, Value : Any> DataSource.Factory<Key, Value>.toLiveData(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor()
): LiveData<PagedList<Value>>

Constructs a LiveData<PagedList>, from this DataSource.Factory, convenience for LivePagedListBuilder.

No work (such as loading) is done immediately, the creation of the first PagedList is deferred until the LiveData is observed.

Parameters
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor()

Executor for fetching data from PagingSources.

toLiveData

fun <Key : Any, Value : Any> DataSource.Factory<Key, Value>.toLiveData(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor()
): LiveData<PagedList<Value>>

Constructs a LiveData<PagedList>, from this DataSource.Factory, convenience for LivePagedListBuilder.

No work (such as loading) is done immediately, the creation of the first PagedList is deferred until the LiveData is observed.

Parameters
pageSize: Int

Page size.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor()

Executor for fetching data from DataSources.

toLiveData

fun <Key : Any, Value : Any> () -> PagingSource<Key, Value>.toLiveData(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    coroutineScope: CoroutineScope = GlobalScope,
    fetchDispatcher: CoroutineDispatcher = ArchTaskExecutor.getIOThreadExecutor() .asCoroutineDispatcher()
): LiveData<PagedList<Value>>

Constructs a LiveData<PagedList>, from this PagingSource factory, convenience for LivePagedListBuilder.

No work (such as loading) is done immediately, the creation of the first PagedList is deferred until the LiveData is observed.

Parameters
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

coroutineScope: CoroutineScope = GlobalScope

Set the CoroutineScope that page loads should be launched within. The set coroutineScope allows a PagingSource to cancel running load operations when the results are no longer needed - for example, when the containing activity is destroyed.

Defaults to GlobalScope.

fetchDispatcher: CoroutineDispatcher = ArchTaskExecutor.getIOThreadExecutor() .asCoroutineDispatcher()

CoroutineDispatcher for fetching data from PagingSources.

toLiveData

fun <Key : Any, Value : Any> () -> PagingSource<Key, Value>.toLiveData(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    coroutineScope: CoroutineScope = GlobalScope,
    fetchDispatcher: CoroutineDispatcher = ArchTaskExecutor.getIOThreadExecutor() .asCoroutineDispatcher()
): LiveData<PagedList<Value>>

Constructs a LiveData<PagedList>, from this PagingSource factory, convenience for LivePagedListBuilder.

No work (such as loading) is done immediately, the creation of the first PagedList is deferred until the LiveData is observed.

Parameters
pageSize: Int

Page size.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

coroutineScope: CoroutineScope = GlobalScope

Set the CoroutineScope that page loads should be launched within. The set coroutineScope allows a PagingSource to cancel running load operations when the results are no longer needed - for example, when the containing activity is destroyed.

Defaults to GlobalScope.

fetchDispatcher: CoroutineDispatcher = ArchTaskExecutor.getIOThreadExecutor() .asCoroutineDispatcher()

CoroutineDispatcher for fetching data from PagingSources.

toObservable

fun <Key : Any, Value : Any> DataSource.Factory<Key, Value>.toObservable(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null
): Observable<PagedList<Value>>

Constructs a Observable<PagedList> from this DataSource.Factory, convenience for RxPagedListBuilder.

The returned Observable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.

Parameters
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

Scheduler used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.

notifyScheduler: Scheduler? = null

Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI / main thread.

toObservable

fun <Key : Any, Value : Any> () -> PagingSource<Key, Value>.toObservable(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null
): Observable<PagedList<Value>>

Constructs a Observable<PagedList> from this PagingSource factory, convenience for RxPagedListBuilder.

The returned Observable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.

Parameters
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

Scheduler used to fetch from PagingSources, generally a background thread pool for e.g. I/O or network loading.

notifyScheduler: Scheduler? = null

Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI / main thread.

toObservable

fun <Key : Any, Value : Any> DataSource.Factory<Key, Value>.toObservable(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null
): Observable<PagedList<Value>>

Constructs a Observable<PagedList> from this DataSource.Factory, convenience for RxPagedListBuilder.

The returned Observable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.

Parameters
pageSize: Int

Size of pages to load.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

Scheduler used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.

notifyScheduler: Scheduler? = null

Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI / main thread.

toObservable

fun <Key : Any, Value : Any> () -> PagingSource<Key, Value>.toObservable(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback<Value>? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null
): Observable<PagedList<Value>>

Constructs a Observable<PagedList> from this PagingSource factory, convenience for RxPagedListBuilder.

The returned Observable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.

Parameters
pageSize: Int

Size of pages to load.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback<Value>? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

Scheduler used to fetch from PagingSources, generally a background thread pool for e.g. I/O or network loading.

notifyScheduler: Scheduler? = null

Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI / main thread.

Extension properties

liveData

val Pager<Key, Value>.liveDataLiveData<PagingData<Value>>

A LiveData of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as a LiveData.

NOTE: Instances of PagingData emitted by this LiveData are not re-usable and cannot be submitted multiple times. This is especially relevant because LiveData will replays the latest value downstream. To ensure you get a new instance of PagingData for each downstream observer, you should use the cachedIn operator which multicasts the LiveData in a way that returns a new instance of PagingData with cached data pre-loaded.