Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

androidx.paging

Classes

AsyncPagedListDiffer

Helper object for mapping a PagedList into a RecyclerView.Adapter.

DataSource

Base class for loading pages of snapshot data into a PagedList

ItemKeyedDataSource

Incremental data loader for paging keyed content, where loaded content uses previously loaded items as input to future loads.

LivePagedListBuilder

Builder for LiveData<PagedList>, given a DataSource.Factory and a PagedList.Config.

PagedList

Lazy loading list that pages in immutable content from a DataSource.

PagedListAdapter

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

PageKeyedDataSource

Incremental data loader for page-keyed content, where requests return keys for next/previous pages.

PositionalDataSource

Position-based data loader for a fixed-size, countable data set, supporting fixed-size loads at arbitrary page positions.

RxPagedListBuilder

Builder for Observable<PagedList> or Flowable<PagedList>, given a DataSource.Factory and a PagedList.Config.

Top-level functions summary

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

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

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

Constructs a PagedList, convenience for PagedList.Builder.

Extension functions summary

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

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

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

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

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

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

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

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

Flowable<PagedList<Value>>
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)

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

Flowable<PagedList<Value>>
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)

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

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 Number of items loaded at once from the DataSource.
prefetchDistance Distance the PagedList should prefetch.
enablePlaceholders False if null placeholders should be disabled.
initialLoadSizeHint Number of items to load while initializing the PagedList.
maxSize Maximum number of items to keep in memory, or PagedList.Config.MAX_SIZE_UNBOUNDED to disable page dropping.

PagedList

fun <Key, Value> 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 Type of key used to load data from the DataSource.
Value Type of items held and loaded by the PagedList.
dataSource DataSource the PagedList will load from.
config Config that defines how the PagedList loads data from its DataSource.
notifyExecutor Executor that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI/main thread.
fetchExecutor Executor used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.
boundaryCallback BoundaryCallback for listening to out-of-data events.
initialKey Key the DataSource should load around as part of initialization.

Extension functions

toFlowable

fun <Key, Value> 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 Paging configuration.
initialLoadKey Initial load key passed to the first PagedList/DataSource.
boundaryCallback The boundary callback for listening to PagedList load state.
notifyScheduler Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI/main thread.
fetchScheduler Scheduler used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.
backpressureStrategy BackpressureStrategy for the Flowable to use.

toFlowable

fun <Key, Value> 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 Page size.
initialLoadKey Initial load key passed to the first PagedList/DataSource.
boundaryCallback The boundary callback for listening to PagedList load state.
notifyScheduler Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI/main thread.
fetchScheduler Scheduler used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.
backpressureStrategy BackpressureStrategy for the Flowable to use.

toLiveData

fun <Key, Value> 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 is deferred until the LiveData is observed.

Parameters
config Paging configuration.
initialLoadKey Initial load key passed to the first PagedList/DataSource.
boundaryCallback The boundary callback for listening to PagedList load state.
fetchExecutor Executor for fetching data from DataSources.

toLiveData

fun <Key, Value> 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 is deferred until the LiveData is observed.

Parameters
pageSize Page size.
initialLoadKey Initial load key passed to the first PagedList/DataSource.
boundaryCallback The boundary callback for listening to PagedList load state.
fetchExecutor Executor for fetching data from DataSources.

toObservable

fun <Key, Value> 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 Paging configuration.
initialLoadKey Initial load key passed to the first PagedList/DataSource.
boundaryCallback The boundary callback for listening to PagedList load state.
notifyScheduler Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI/main thread.
fetchScheduler Scheduler used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.

toObservable

fun <Key, Value> 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 Size of pages to load.
initialLoadKey Initial load key passed to the first PagedList/DataSource.
boundaryCallback The boundary callback for listening to PagedList load state.
notifyScheduler Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI/main thread.
fetchScheduler Scheduler used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.