Google は、黒人コミュニティに対する人種平等の促進に取り組んでいます。取り組みを見る

Builder

class Builder<Key : Any, Value : Any>
kotlin.Any
   ↳ androidx.paging.PagedList.Builder

Builder class for PagedList.

pagingSource, config, notifyDispatcher and fetchDispatcher must all be provided.

A PagedList queries initial data from its PagingSource during construction, to avoid empty PagedLists being presented to the UI when possible. It's preferred to present initial data, so that the UI doesn't show an empty list, or placeholders for a few frames, just before showing initial content.

LivePagedListBuilder does this creation on a background thread automatically, if you want to receive a LiveData<PagedList<...>>.

Summary

Public constructors
<init>(dataSource: DataSource<Key, Value>, config: PagedList.Config)

Create a Builder with the provided DataSource and Config.

<init>(dataSource: DataSource<Key, Value>, pageSize: Int)

Create a PagedList.Builder with the provided DataSource and pageSize.

<init>(pagingSource: PagingSource<Key, Value>, initialPage: PagingSource.LoadResult.Page<Key, Value>, config: PagedList.Config)

Create a PagedList.Builder with the provided PagingSource, initial PagingSource.LoadResult.Page, and PagedList.Config.

<init>(pagingSource: PagingSource<Key, Value>, initialPage: PagingSource.LoadResult.Page<Key, Value>, pageSize: Int)

Create a PagedList.Builder with the provided PagingSource, initial PagingSource.LoadResult.Page, and pageSize.

Public methods
PagedList<Value>

Creates a PagedList with the given parameters.

PagedList.Builder<Key, Value>

The BoundaryCallback for out of data events.

PagedList.Builder<Key, Value>

Set the CoroutineScope that page loads should be launched within.

PagedList.Builder<Key, Value>

The CoroutineDispatcher used to fetch additional pages from the PagingSource.

PagedList.Builder<Key, Value>
setFetchExecutor(fetchExecutor: Executor)

The Executor used to fetch additional pages from the PagingSource.

PagedList.Builder<Key, Value>
setInitialKey(initialKey: Key?)

Sets the initial key the PagingSource should load around as part of initialization.

PagedList.Builder<Key, Value>

The CoroutineDispatcher defining where page loading updates are dispatched.

PagedList.Builder<Key, Value>
setNotifyExecutor(notifyExecutor: Executor)

The Executor defining where page loading updates are dispatched.

Public constructors

<init>

Builder(
    dataSource: DataSource<Key, Value>,
    config: PagedList.Config)

Create a Builder with the provided DataSource and Config.

Parameters
dataSource: DataSource<Key, Value> DataSource the PagedList will load from.
config: PagedList.Config PagedList.Config that defines how the PagedList loads data from its DataSource.

<init>

Builder(
    dataSource: DataSource<Key, Value>,
    pageSize: Int)

Create a PagedList.Builder with the provided DataSource and pageSize.

This method is a convenience for:

PagedList.Builder(dataSource,
    new PagedList.Config.Builder().setPageSize(pageSize).build());
Parameters
dataSource: DataSource<Key, Value> DataSource the PagedList will load from.
pageSize: Int Size of loaded pages when the PagedList loads data from its DataSource.

<init>

Builder(
    pagingSource: PagingSource<Key, Value>,
    initialPage: PagingSource.LoadResult.Page<Key, Value>,
    config: PagedList.Config)

Create a PagedList.Builder with the provided PagingSource, initial PagingSource.LoadResult.Page, and PagedList.Config.

Parameters
pagingSource: PagingSource<Key, Value> PagingSource the PagedList will load from.
initialPage: PagingSource.LoadResult.Page<Key, Value> Initial page loaded from the PagingSource.
config: PagedList.Config PagedList.Config that defines how the PagedList loads data from its PagingSource.

<init>

Builder(
    pagingSource: PagingSource<Key, Value>,
    initialPage: PagingSource.LoadResult.Page<Key, Value>,
    pageSize: Int)

Create a PagedList.Builder with the provided PagingSource, initial PagingSource.LoadResult.Page, and pageSize.

This method is a convenience for:

PagedList.Builder(
    pagingSource,
    page,
    PagedList.Config.Builder().setPageSize(pageSize).build()
)
Parameters
pagingSource: PagingSource<Key, Value> PagingSource the PagedList will load from.
initialPage: PagingSource.LoadResult.Page<Key, Value> Initial page loaded from the PagingSource.
pageSize: Int Size of loaded pages when the PagedList loads data from its PagingSource.

Public methods

build

fun build(): PagedList<Value>

Creates a PagedList with the given parameters.

This call will dispatch the androidx.paging.PagingSource's loadInitial method immediately on the current thread, and block the current on the result. This method should always be called on a worker thread to prevent blocking the main thread.

It's fine to create a PagedList with an async PagingSource on the main thread, such as in the constructor of a ViewModel. An async network load won't block the initial call to the Load function. For a synchronous PagingSource such as one created from a Room database, a LiveData<PagedList> can be safely constructed with androidx.paging.LivePagedListBuilder on the main thread, since actual construction work is deferred, and done on a background thread.

While build will always return a PagedList, it's important to note that the PagedList initial load may fail to acquire data from the PagingSource. This can happen for example if the PagingSource is invalidated during its initial load. If this happens, the PagedList will be immediately detached, and you can retry construction (including setting a new PagingSource).

Exceptions
IllegalArgumentException if notifyDispatcher or fetchDispatcher are not set.
Return
The newly constructed PagedList

setBoundaryCallback

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

The BoundaryCallback for out of data events.

Pass a BoundaryCallback to listen to when the PagedList runs out of data to load.

Parameters
boundaryCallback: PagedList.BoundaryCallback<Value>? BoundaryCallback for listening to out-of-data events.
Return
this

setCoroutineScope

fun setCoroutineScope(coroutineScope: CoroutineScope): PagedList.Builder<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
Return
this

setFetchDispatcher

fun setFetchDispatcher(fetchDispatcher: CoroutineDispatcher): PagedList.Builder<Key, Value>

The CoroutineDispatcher used to fetch additional pages from the PagingSource.

Does not affect initial load, which will be done immediately on whichever thread the PagedList is created on.

Parameters
fetchDispatcher: CoroutineDispatcher CoroutineDispatcher used to fetch from PagingSources, generally a background thread pool for e.g. I/O or network loading.
Return
this

setFetchExecutor

fun setFetchExecutor(fetchExecutor: Executor): PagedList.Builder<Key, Value>

Deprecated.

The Executor used to fetch additional pages from the PagingSource.

Does not affect initial load, which will be done immediately on whichever thread the PagedList is created on.

Parameters
fetchExecutor: Executor Executor used to fetch from PagingSources, generally a background thread pool for e.g. I/O or network loading.
Return
this

setInitialKey

fun setInitialKey(initialKey: Key?): PagedList.Builder<Key, Value>

Sets the initial key the PagingSource should load around as part of initialization.

Parameters
initialKey: Key? Key the PagingSource should load around as part of initialization.
Return
this

setNotifyDispatcher

fun setNotifyDispatcher(notifyDispatcher: CoroutineDispatcher): PagedList.Builder<Key, Value>

The CoroutineDispatcher defining where page loading updates are dispatched.

Parameters
notifyDispatcher: CoroutineDispatcher CoroutineDispatcher that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the ui/main thread.
Return
this

setNotifyExecutor

fun setNotifyExecutor(notifyExecutor: Executor): PagedList.Builder<Key, Value>

Deprecated.

The Executor defining where page loading updates are dispatched.

Parameters
notifyExecutor: Executor Executor that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the ui/main thread.
Return
this