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

androidx.paging

Interfaces

AsyncPagedListDiffer.PagedListListener

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

DataSource.InvalidatedCallback

Invalidation callback for DataSource.

Logger
PagingSourceFactory

Interface for a factory that generates PagingSource.

Classes

AdjacentItems

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

AsyncPagedListDiffer

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

AsyncPagingDataDiffer

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

CombinedLoadStates

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

DataSource

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

DataSource.Factory

Factory for DataSources.

InvalidatingPagingSourceFactory

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

ItemKeyedDataSource

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

ItemKeyedDataSource.LoadCallback

Callback for ItemKeyedDataSource loadBefore and loadAfter to return data.

ItemKeyedDataSource.LoadInitialCallback

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

ItemKeyedDataSource.LoadInitialParams

Holder object for inputs to loadInitial.

ItemKeyedDataSource.LoadParams

Holder object for inputs to loadBefore and loadAfter.

ItemSnapshotList

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

ListenableFuturePagingSource

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

ListenableFutureRemoteMediator

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

LivePagedListBuilder

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

LoadState

LoadState of a PagedList load - associated with a LoadType

LoadState.Error

Loading hit an error.

LoadState.NotLoading

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

LoadStateAdapter

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

LoadStates

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

PageKeyedDataSource

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

PageKeyedDataSource.LoadCallback

Callback for loadBefore and loadAfter to return data.

PageKeyedDataSource.LoadInitialCallback

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

PageKeyedDataSource.LoadInitialParams

Holder object for inputs to loadInitial.

PageKeyedDataSource.LoadParams

Holder object for inputs to loadBefore and loadAfter.

PagedList

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

PagedList.BoundaryCallback

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

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.

PagedList.Callback

Callback signaling when content is loaded into the list.

PagedList.Config

Configures how a PagedList loads content from its PagingSource.

PagedList.Config.Builder

Builder class for PagedList.Config.

PagedListAdapter

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

Pager

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

PagingConfig

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

PagingData

Container for Paged data from a single generation of loads.

PagingDataAdapter

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

PagingSource

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

PagingSource.LoadParams

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

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.

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.

PagingSource.LoadParams.Refresh

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

PagingSource.LoadResult

Result of a load request from PagingSource.load.

PagingSource.LoadResult.Error

Error result object for PagingSource.load.

PagingSource.LoadResult.Invalid

Invalid result object for PagingSource.load

PagingSource.LoadResult.Page

Success result object for PagingSource.load.

PagingState

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

PositionalDataSource

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

PositionalDataSource.LoadInitialCallback

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

PositionalDataSource.LoadInitialParams

Holder object for inputs to loadInitial.

PositionalDataSource.LoadRangeCallback

Callback for PositionalDataSource loadRange to return data.

PositionalDataSource.LoadRangeParams

Holder object for inputs to loadRange.

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.

RemoteMediator.MediatorResult

Return type of load, which determines LoadState.

RemoteMediator.MediatorResult.Error

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

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.

RxPagedListBuilder

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

Objects

LoadState.Loading

Loading is in progress.

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.

Enums

LoadType

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

RemoteMediator.InitializeAction

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

TerminalSeparatorType

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

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.

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

Extension functions summary

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

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

Flow<PagingData<T>>

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

LiveData<PagingData<T>>

Operator which caches a LiveData of PagingData within a CoroutineScope.

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

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

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

Returns a PagingData containing only elements matching the given predicate

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

Returns a PagingData containing only elements matching the given predicate.

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

Returns a PagingData containing only elements matching the given predicate.

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.

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.

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.

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.

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.

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).

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).

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).

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.

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.

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.

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

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

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

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

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

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

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

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

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

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

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

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

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.

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

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.

flatMap

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 PagedList.Config.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 PagedList.Config.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().toUpperCase().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().toUpperCase())
            } 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 = 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 = 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().toUpperCase().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().toUpperCase())
                        } 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.

See also
RxPagedListBuilder
toObservable

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.

See also
RxPagedListBuilder
toObservable

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.

See also
RxPagedListBuilder
toObservable

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.

See also
RxPagedListBuilder
toObservable

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.

See also
LivePagedListBuilder

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.

See also
LivePagedListBuilder

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.

See also
LivePagedListBuilder

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.

See also
LivePagedListBuilder

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.

See also
RxPagedListBuilder
toFlowable

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.

See also
RxPagedListBuilder
toFlowable

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.

See also
RxPagedListBuilder
toFlowable

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.

See also
RxPagedListBuilder
toFlowable

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.