RxPagedListBuilder

public final class RxPagedListBuilder<Key extends Object, Value extends Object>


Builder for Observable<PagedList> or Flowable<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).

The returned observable/flowable will already be subscribed on the setFetchScheduler, and will perform all loading on that scheduler. It will already be observed on setNotifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.

Parameters
<Key extends Object>

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

<Value extends Object>

Item type being presented.

Summary

Public constructors

<Key extends Object, Value extends Object> RxPagedListBuilder(
    @NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory,
    @NonNull PagedList.Config config
)

Creates a RxPagedListBuilder with required parameters.

<Key extends Object, Value extends Object> RxPagedListBuilder(
    @NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory,
    int pageSize
)

Creates a RxPagedListBuilder with required parameters.

<Key extends Object, Value extends Object> RxPagedListBuilder(
    @NonNull DataSource.Factory<@NonNull Key, @NonNull Value> dataSourceFactory,
    @NonNull PagedList.Config config
)

Creates a RxPagedListBuilder with required parameters.

<Key extends Object, Value extends Object> RxPagedListBuilder(
    @NonNull DataSource.Factory<@NonNull Key, @NonNull Value> dataSourceFactory,
    int pageSize
)

Creates a RxPagedListBuilder with required parameters.

Public methods

final @NonNull Flowable<@NonNull PagedList<@NonNull Value>>

Constructs a Flowable<PagedList>.

final @NonNull Observable<@NonNull PagedList<@NonNull Value>>

Constructs a Observable<PagedList>.

final @NonNull RxPagedListBuilder<@NonNull Key, @NonNull Value>

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

final @NonNull RxPagedListBuilder<@NonNull Key, @NonNull Value>

Sets scheduler which will be used for background fetching of PagedLists, as well as on-demand fetching of pages inside.

final @NonNull RxPagedListBuilder<@NonNull Key, @NonNull Value>

First loading key passed to the first PagedList/DataSource.

final @NonNull RxPagedListBuilder<@NonNull Key, @NonNull Value>

Sets scheduler which will be used for observing new PagedLists, as well as loading updates within the PagedLists.

Public constructors

RxPagedListBuilder

public final <Key extends Object, Value extends Object> RxPagedListBuilder(
    @NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory,
    @NonNull PagedList.Config config
)

Creates a RxPagedListBuilder with required parameters.

Parameters
@NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory

DataSource factory providing DataSource generations.

@NonNull PagedList.Config config

Paging configuration.

RxPagedListBuilder

public final <Key extends Object, Value extends Object> RxPagedListBuilder(
    @NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory,
    int pageSize
)

Creates a RxPagedListBuilder with required parameters.

This method is a convenience for:

RxPagedListBuilder(
pagingSourceFactory,
PagedList.Config.Builder().setPageSize(pageSize).build()
)
Parameters
@NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> pagingSourceFactory

PagingSource factory providing PagingSource generations.

int pageSize

Size of pages to load.

RxPagedListBuilder

public final <Key extends Object, Value extends Object> RxPagedListBuilder(
    @NonNull DataSource.Factory<@NonNull Key, @NonNull Value> dataSourceFactory,
    @NonNull PagedList.Config config
)

Creates a RxPagedListBuilder with required parameters.

Parameters
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> dataSourceFactory

DataSource factory providing DataSource generations.

@NonNull PagedList.Config config

Paging configuration.

RxPagedListBuilder

public final <Key extends Object, Value extends Object> RxPagedListBuilder(
    @NonNull DataSource.Factory<@NonNull Key, @NonNull Value> dataSourceFactory,
    int pageSize
)

Creates a RxPagedListBuilder with required parameters.

This method is a convenience for:

RxPagedListBuilder(
dataSourceFactory,
PagedList.Config.Builder().setPageSize(pageSize).build()
)
Parameters
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> dataSourceFactory

DataSource.Factory providing DataSource generations.

int pageSize

Size of pages to load.

Public methods

buildFlowable

@NonNull
public final Flowable<@NonNull PagedList<@NonNull Value>> buildFlowable(@NonNull BackpressureStrategy backpressureStrategy)

Constructs a Flowable<PagedList>.

The returned Observable will already be observed on the notifyScheduler, and subscribed on the fetchScheduler.

Parameters
@NonNull BackpressureStrategy backpressureStrategy

BackpressureStrategy for the Flowable to use.

Returns
Flowable<@NonNull PagedList<@NonNull Value>>

The Flowable of PagedLists

buildObservable

@NonNull
public final Observable<@NonNull PagedList<@NonNull Value>> buildObservable()

Constructs a Observable<PagedList>.

The returned Observable will already be observed on the notifyScheduler, and subscribed on the fetchScheduler.

Returns
Observable<@NonNull PagedList<@NonNull Value>>

The Observable of PagedLists

setBoundaryCallback

@NonNull
public final RxPagedListBuilder<@NonNull Key, @NonNull Value> setBoundaryCallback(
    @Nullable 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 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 Observable<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
@Nullable PagedList.BoundaryCallback<@NonNull Value> boundaryCallback

The boundary callback for listening to PagedList load state.

Returns
RxPagedListBuilder<@NonNull Key, @NonNull Value>

this

setFetchScheduler

@NonNull
public final RxPagedListBuilder<@NonNull Key, @NonNull Value> setFetchScheduler(@NonNull Scheduler scheduler)

Sets scheduler which will be used for background fetching of PagedLists, as well as on-demand fetching of pages inside.

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

The built Observable / Flowable will be subscribed on this scheduler.

Parameters
@NonNull Scheduler scheduler

Scheduler used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading.

Returns
RxPagedListBuilder<@NonNull Key, @NonNull Value>

this

setInitialLoadKey

@NonNull
public final RxPagedListBuilder<@NonNull Key, @NonNull Value> setInitialLoadKey(@Nullable 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
@Nullable Key key

Initial load key passed to the first PagedList/DataSource.

Returns
RxPagedListBuilder<@NonNull Key, @NonNull Value>

this

setNotifyScheduler

@NonNull
public final RxPagedListBuilder<@NonNull Key, @NonNull Value> setNotifyScheduler(@NonNull Scheduler scheduler)

Sets scheduler which will be used for observing new PagedLists, as well as loading updates within the PagedLists.

If not set, defaults to the UI thread.

The built Observable / Flowable will be observed on this scheduler, so that the thread receiving PagedLists will also receive the internal updates to the PagedList.

Parameters
@NonNull Scheduler scheduler

Scheduler that receives PagedList updates, and where PagedList.Callback calls are dispatched. Generally, this is the UI/main thread.

Returns
RxPagedListBuilder<@NonNull Key, @NonNull Value>

this