LivePagedListBuilder
public final class LivePagedListBuilder<Key extends Object, Value extends Object>
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 extends Object> |
Type of input valued used to load data from the |
<Value extends Object> |
Item type being presented. |
See also | |
---|---|
toLiveData |
Summary
Public constructors |
---|
<Key extends Object, Value extends Object> This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
<Key extends Object, Value extends Object> This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
<Key extends Object, Value extends Object> This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
<Key extends Object, Value extends Object> This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
Public methods |
|
---|---|
final @NonNull LiveData<@NonNull PagedList<@NonNull Value>> |
This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value> |
This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value> |
This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value> |
This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value> |
This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
Public constructors
LivePagedListBuilder
public <Key extends Object, Value extends Object>LivePagedListBuilder(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> dataSourceFactory,
@NonNull PagedList.Config config
)
Creates a LivePagedListBuilder
with required parameters.
Parameters | |
---|---|
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> dataSourceFactory |
|
@NonNull PagedList.Config config |
Paging configuration. |
LivePagedListBuilder
public <Key extends Object, Value extends Object>LivePagedListBuilder(
@NonNull DataSource.Factory<@NonNull Key, @NonNull 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 | |
---|---|
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> dataSourceFactory |
|
int pageSize |
Size of pages to load. |
LivePagedListBuilder
public <Key extends Object, Value extends Object>LivePagedListBuilder(
@NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory,
@NonNull PagedList.Config config
)
Creates a LivePagedListBuilder
with required parameters.
Parameters | |
---|---|
@NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory |
The returned
|
@NonNull PagedList.Config config |
Paging configuration. |
LivePagedListBuilder
public <Key extends Object, Value extends Object>LivePagedListBuilder(
@NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory,
int pageSize
)
Creates a LivePagedListBuilder
with required parameters.
This method is a convenience for:
LivePagedListBuilder(pagingSourceFactory,
new PagedList.Config.Builder().setPageSize(pageSize).build())
Parameters | |
---|---|
@NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory |
The returned
|
int pageSize |
Size of pages to load. |
Public methods
public final @NonNull LiveData<@NonNull PagedList<@NonNull Value>>build()
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.
public final @NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value>setBoundaryCallback(
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback
)
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 | |
---|---|
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to PagedList load state. |
Returns | |
---|---|
@NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value> |
this |
public final @NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value>setCoroutineScope(@NonNull CoroutineScope coroutineScope)
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 | |
---|---|
@NonNull CoroutineScope coroutineScope |
Returns | |
---|---|
@NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value> |
this |
public final @NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value>setFetchExecutor(@NonNull Executor fetchExecutor)
Sets Executor
used for background fetching of PagedList
s, 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 | |
---|---|
@NonNull Executor fetchExecutor |
|
Returns | |
---|---|
@NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value> |
this |
public final @NonNull LivePagedListBuilder<@NonNull Key, @NonNull 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 | |
---|---|
@NonNull LivePagedListBuilder<@NonNull Key, @NonNull Value> |
this |