LivePagedListBuilder

Added in 2.0.0
Deprecated in 3.0.0

Builder for LiveData<PagedList> for Java users, given a androidx.paging.DataSource.Factory and a androidx.paging.PagedList.Config.

The required parameters are in the constructor, so you can simply construct and build, or optionally enable extra features (such as initial load key, or BoundaryCallback).

Parameters
<Key : Any>

Type of input valued used to load data from the DataSource. Must be Int if you're using PositionalDataSource.

<Value : Any>

Item type being presented.

See also
toLiveData

Summary

Public constructors

<Key : Any, Value : Any> LivePagedListBuilder(
    dataSourceFactory: DataSource.Factory<Key, Value>,
    config: PagedList.Config
)

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

android
<Key : Any, Value : Any> LivePagedListBuilder(
    dataSourceFactory: DataSource.Factory<Key, Value>,
    pageSize: Int
)

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

android
<Key : Any, Value : Any> LivePagedListBuilder(
    pagingSourceFactory: () -> PagingSource<Key, Value>,
    config: PagedList.Config
)

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

android
<Key : Any, Value : Any> LivePagedListBuilder(
    pagingSourceFactory: () -> PagingSource<Key, Value>,
    pageSize: Int
)

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

android

Public functions

LiveData<PagedList<Value>>

Constructs the LiveData<PagedList>.

android
LivePagedListBuilder<Key, Value>
setBoundaryCallback(
    boundaryCallback: PagedList.BoundaryCallback<Value>?
)

Sets a androidx.paging.PagedList.BoundaryCallback on each PagedList created, typically used to load additional data from network when paging from local storage.

android
LivePagedListBuilder<Key, Value>

Set the CoroutineScope that page loads should be launched within.

android
LivePagedListBuilder<Key, Value>
setFetchExecutor(fetchExecutor: Executor)

Sets Executor used for background fetching of PagedLists, and the pages within.

android
LivePagedListBuilder<Key, Value>
setInitialLoadKey(key: Key?)

First loading key passed to the first PagedList/DataSource.

android

Public constructors

LivePagedListBuilder

<Key : Any, Value : Any> LivePagedListBuilder(
    dataSourceFactory: DataSource.Factory<Key, Value>,
    config: PagedList.Config
)

Creates a LivePagedListBuilder with required parameters.

Parameters
dataSourceFactory: DataSource.Factory<Key, Value>

DataSource factory providing DataSource generations.

config: PagedList.Config

Paging configuration.

LivePagedListBuilder

<Key : Any, Value : Any> LivePagedListBuilder(
    dataSourceFactory: DataSource.Factory<Key, Value>,
    pageSize: Int
)

Creates a LivePagedListBuilder with required parameters.

This method is a convenience for:

LivePagedListBuilder(dataSourceFactory,
new PagedList.Config.Builder().setPageSize(pageSize).build())
Parameters
dataSourceFactory: DataSource.Factory<Key, Value>

DataSource.Factory providing DataSource generations.

pageSize: Int

Size of pages to load.

LivePagedListBuilder

<Key : Any, Value : Any> LivePagedListBuilder(
    pagingSourceFactory: () -> PagingSource<Key, Value>,
    config: PagedList.Config
)

Creates a LivePagedListBuilder with required parameters.

Parameters
pagingSourceFactory: () -> PagingSource<Key, Value>

PagingSource factory providing PagingSource generations.

The returned PagingSource should invalidate itself if the snapshot is no longer valid. If a PagingSource becomes invalid, the only way to query more data is to create a new PagingSource by invoking the supplied pagingSourceFactory.

pagingSourceFactory will invoked to construct a new PagedList and PagingSource when the current PagingSource is invalidated, and pass the new PagedList through the LiveData<PagedList> to observers.

config: PagedList.Config

Paging configuration.

LivePagedListBuilder

<Key : Any, Value : Any> LivePagedListBuilder(
    pagingSourceFactory: () -> PagingSource<Key, Value>,
    pageSize: Int
)

Creates a LivePagedListBuilder with required parameters.

This method is a convenience for:

LivePagedListBuilder(pagingSourceFactory,
new PagedList.Config.Builder().setPageSize(pageSize).build())
Parameters
pagingSourceFactory: () -> PagingSource<Key, Value>

PagingSource factory providing PagingSource generations.

The returned PagingSource should invalidate itself if the snapshot is no longer valid. If a PagingSource becomes invalid, the only way to query more data is to create a new PagingSource by invoking the supplied pagingSourceFactory.

pagingSourceFactory will invoked to construct a new PagedList and PagingSource when the current PagingSource is invalidated, and pass the new PagedList through the LiveData<PagedList> to observers.

pageSize: Int

Size of pages to load.

Public functions

build

fun build(): LiveData<PagedList<Value>>

Constructs the LiveData<PagedList>.

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

Returns
LiveData<PagedList<Value>>

The LiveData of PagedLists

setBoundaryCallback

fun setBoundaryCallback(
    boundaryCallback: PagedList.BoundaryCallback<Value>?
): LivePagedListBuilder<Key, Value>

Sets a androidx.paging.PagedList.BoundaryCallback on each PagedList created, typically used to load additional data from network when paging from local storage.

Pass a PagedList.BoundaryCallback to listen to when the PagedList runs out of data to load. If this method is not called, or null is passed, you will not be notified when each PagingSource runs out of data to provide to its PagedList.

If you are paging from a DataSource.Factory backed by local storage, you can set a BoundaryCallback to know when there is no more information to page from local storage. This is useful to page from the network when local storage is a cache of network data.

Note that when using a BoundaryCallback with a LiveData<PagedList>, method calls on the callback may be dispatched multiple times - one for each PagedList/DataSource pair. If loading network data from a BoundaryCallback, you should prevent multiple dispatches of the same method from triggering multiple simultaneous network loads.

Parameters
boundaryCallback: PagedList.BoundaryCallback<Value>?

The boundary callback for listening to PagedList load state.

Returns
LivePagedListBuilder<Key, Value>

this

setCoroutineScope

fun setCoroutineScope(coroutineScope: CoroutineScope): LivePagedListBuilder<Key, Value>

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.

Parameters
coroutineScope: CoroutineScope
Returns
LivePagedListBuilder<Key, Value>

this

setFetchExecutor

fun setFetchExecutor(fetchExecutor: Executor): LivePagedListBuilder<Key, Value>

Sets Executor used for background fetching of PagedLists, and the pages within.

The library will wrap this as a kotlinx.coroutines.CoroutineDispatcher.

If not set, defaults to a ExecutorCoroutineDispatcher backed by ArchTaskExecutor.getIOThreadExecutor.

Parameters
fetchExecutor: Executor

Executor for fetching data from PagingSources.

Returns
LivePagedListBuilder<Key, Value>

this

setInitialLoadKey

fun setInitialLoadKey(key: Key?): LivePagedListBuilder<Key, Value>

First loading key passed to the first PagedList/DataSource.

When a new PagedList/DataSource pair is created after the first, it acquires a load key from the previous generation so that data is loaded around the position already being observed.

Parameters
key: Key?

Initial load key passed to the first PagedList/DataSource.

Returns
LivePagedListBuilder<Key, Value>

this