LivePagedListBuilder

public final class LivePagedListBuilder
extends Object

java.lang.Object
   ↳ android.arch.paging.LivePagedListBuilder<Key, Value>


Builder for LiveData<PagedList>, given a DataSource.Factory and a 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).

Summary

Public constructors

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

Creates a LivePagedListBuilder with required parameters.

LivePagedListBuilder(Factory<Key, Value> dataSourceFactory, int pageSize)

Creates a LivePagedListBuilder with required parameters.

Public methods

LiveData<PagedList<Value>> build()

Constructs the LiveData<PagedList>.

LivePagedListBuilder<Key, Value> setBoundaryCallback(BoundaryCallback<Value> boundaryCallback)

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

LivePagedListBuilder<Key, Value> setFetchExecutor(Executor fetchExecutor)

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

LivePagedListBuilder<Key, Value> setInitialLoadKey(Key key)

First loading key passed to the first PagedList/DataSource.

Inherited methods

Public constructors

LivePagedListBuilder

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

Creates a LivePagedListBuilder with required parameters.

Parameters
dataSourceFactory Factory: DataSource factory providing DataSource generations.

config PagedList.Config: Paging configuration.

LivePagedListBuilder

LivePagedListBuilder (Factory<Key, Value> dataSourceFactory, 
                int pageSize)

Creates a LivePagedListBuilder with required parameters.

This method is a convenience for:

 LivePagedListBuilder(dataSourceFactory,
         new PagedList.Config.Builder().setPageSize(pageSize).build())
 

Parameters
dataSourceFactory Factory: DataSource.Factory providing DataSource generations.

pageSize int: Size of pages to load.

Public methods

build

LiveData<PagedList<Value>> build ()

Constructs the LiveData<PagedList>.

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

Returns
LiveData<PagedList<Value>> The LiveData of PagedLists

setBoundaryCallback

LivePagedListBuilder<Key, Value> setBoundaryCallback (BoundaryCallback<Value> boundaryCallback)

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

Pass a 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 DataSource 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 BoundaryCallback: The boundary callback for listening to PagedList load state.

Returns
LivePagedListBuilder<Key, Value> this

setFetchExecutor

LivePagedListBuilder<Key, Value> setFetchExecutor (Executor fetchExecutor)

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

If not set, defaults to the Arch components I/O thread.

Parameters
fetchExecutor Executor: Executor for fetching data from DataSources.

Returns
LivePagedListBuilder<Key, Value> this

setInitialLoadKey

LivePagedListBuilder<Key, Value> setInitialLoadKey (Key key)

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