DataSource.Factory
public abstract class DataSource.Factory<Key extends Object, Value extends Object>
Factory for DataSources.
Data-loading systems of an application or library can implement this interface to allow LiveData<PagedList>s to be created. For example, Room can provide a DataSource.Factory for a given SQL query:
@Dao
interface UserDao {
@Query("SELECT * FROM user ORDER BY lastName ASC")
public abstract DataSource.Factory<Integer, User> usersByLastName();
}
In the above sample, Integer is used because it is the Key type of PositionalDataSource. Currently, Room uses the LIMIT/OFFSET SQL keywords to page a large query with a PositionalDataSource.
| Parameters | |
|---|---|
<Key extends Object> |
Key identifying items in DataSource. |
<Value extends Object> |
Type of items in the list loaded by the DataSources. |
Summary
Public methods |
|
|---|---|
final @NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> |
asPagingSourceFactory(@NonNull CoroutineDispatcher fetchDispatcher) |
abstract @NonNull DataSource<@NonNull Key, @NonNull Value> |
create()Create a |
@NonNull DataSource.Factory<@NonNull Key, @NonNull ToValue> |
Applies the given function to each value emitted by DataSources produced by this Factory. |
@NonNull DataSource.Factory<@NonNull Key, @NonNull ToValue> |
<ToValue extends Object> mapByPage(Applies the given function to each value emitted by DataSources produced by this Factory. |
Extension functions |
|
|---|---|
final @NonNull LiveData<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> LivePagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull LiveData<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> LivePagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull Flowable<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> RxPagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull Flowable<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> RxPagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull Flowable<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> RxPagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull Flowable<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> RxPagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull Observable<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> RxPagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull Observable<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> RxPagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull Observable<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> RxPagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
final @NonNull Observable<@NonNull PagedList<@NonNull Value>> |
<Key extends Object, Value extends Object> RxPagedListKt.This method is deprecated. PagedList is deprecated and has been replaced by PagingData |
Public constructors
Public methods
asPagingSourceFactory
public final @NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>> asPagingSourceFactory(@NonNull CoroutineDispatcher fetchDispatcher)
create
public abstract @NonNull DataSource<@NonNull Key, @NonNull Value> create()
Create a DataSource.
The DataSource should invalidate itself if the snapshot is no longer valid. If a DataSource becomes invalid, the only way to query more data is to create a new DataSource from the Factory.
androidx.paging.LivePagedListBuilder for example will construct a new PagedList and DataSource when the current DataSource is invalidated, and pass the new PagedList through the LiveData<PagedList> to observers.
| Returns | |
|---|---|
@NonNull DataSource<@NonNull Key, @NonNull Value> |
the new DataSource. |
map
public @NonNull DataSource.Factory<@NonNull Key, @NonNull ToValue> <ToValue extends Object> map(
@NonNull Function<@NonNull Value, @NonNull ToValue> function
)
Applies the given function to each value emitted by DataSources produced by this Factory.
Same as mapByPage, but operates on individual items.
| Parameters | |
|---|---|
<ToValue extends Object> |
Type of items produced by the new |
@NonNull Function<@NonNull Value, @NonNull ToValue> function |
Function that runs on each loaded item, returning items of a potentially new type. |
| Returns | |
|---|---|
@NonNull DataSource.Factory<@NonNull Key, @NonNull ToValue> |
A new |
mapByPage
public @NonNull DataSource.Factory<@NonNull Key, @NonNull ToValue> <ToValue extends Object> mapByPage(
@NonNull Function<@NonNull List<@NonNull Value>, @NonNull List<@NonNull ToValue>> function
)
Applies the given function to each value emitted by DataSources produced by this Factory.
Same as map, but allows for batch conversions.
| Parameters | |
|---|---|
<ToValue extends Object> |
Type of items produced by the new |
@NonNull Function<@NonNull List<@NonNull Value>, @NonNull List<@NonNull ToValue>> function |
Function that runs on each loaded page, returning items of a potentially new type. |
| Returns | |
|---|---|
@NonNull DataSource.Factory<@NonNull Key, @NonNull ToValue> |
A new |
Extension functions
LivePagedListKt.toLiveData
public final @NonNull LiveData<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> LivePagedListKt.toLiveData(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
@NonNull PagedList.Config config,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
@NonNull Executor fetchExecutor
)
Constructs a LiveData<PagedList>, from this DataSource.Factory, convenience for LivePagedListBuilder.
No work (such as loading) is done immediately, the creation of the first PagedList is deferred until the LiveData is observed.
| Parameters | |
|---|---|
@NonNull PagedList.Config config |
Paging configuration. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to |
@NonNull Executor fetchExecutor |
|
| See also | |
|---|---|
LivePagedListBuilder |
LivePagedListKt.toLiveData
public final @NonNull LiveData<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> LivePagedListKt.toLiveData(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
int pageSize,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
@NonNull Executor fetchExecutor
)
Constructs a LiveData<PagedList>, from this DataSource.Factory, convenience for LivePagedListBuilder.
No work (such as loading) is done immediately, the creation of the first PagedList is deferred until the LiveData is observed.
| Parameters | |
|---|---|
int pageSize |
Page size. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to |
@NonNull Executor fetchExecutor |
Executor for fetching data from DataSources. |
| See also | |
|---|---|
LivePagedListBuilder |
RxPagedListKt.toFlowable
public final @NonNull Flowable<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> RxPagedListKt.toFlowable(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
@NonNull PagedList.Config config,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
Scheduler fetchScheduler,
Scheduler notifyScheduler,
@NonNull BackpressureStrategy backpressureStrategy
)
Constructs a Flowable<PagedList>, from this DataSource.Factory, convenience for RxPagedListBuilder.
The returned Flowable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.
| Parameters | |
|---|---|
@NonNull PagedList.Config config |
Paging configuration. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to |
Scheduler fetchScheduler |
|
Scheduler notifyScheduler |
|
@NonNull BackpressureStrategy backpressureStrategy |
|
| See also | |
|---|---|
RxPagedListBuilder |
|
toObservable |
RxPagedListKt.toFlowable
public final @NonNull Flowable<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> RxPagedListKt.toFlowable(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
@NonNull PagedList.Config config,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
Scheduler fetchScheduler,
Scheduler notifyScheduler,
@NonNull BackpressureStrategy backpressureStrategy
)
Constructs a Flowable<PagedList>, from this DataSource.Factory, convenience for RxPagedListBuilder.
The returned Flowable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.
| Parameters | |
|---|---|
@NonNull PagedList.Config config |
Paging configuration. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to |
Scheduler fetchScheduler |
|
Scheduler notifyScheduler |
|
@NonNull BackpressureStrategy backpressureStrategy |
|
| See also | |
|---|---|
RxPagedListBuilder |
|
toObservable |
RxPagedListKt.toFlowable
public final @NonNull Flowable<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> RxPagedListKt.toFlowable(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
int pageSize,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
Scheduler fetchScheduler,
Scheduler notifyScheduler,
@NonNull BackpressureStrategy backpressureStrategy
)
Constructs a Flowable<PagedList>, from this DataSource.Factory, convenience for RxPagedListBuilder.
The returned Flowable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.
| Parameters | |
|---|---|
int pageSize |
Page size. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to |
Scheduler fetchScheduler |
|
Scheduler notifyScheduler |
|
@NonNull BackpressureStrategy backpressureStrategy |
|
| See also | |
|---|---|
RxPagedListBuilder |
|
toObservable |
RxPagedListKt.toFlowable
public final @NonNull Flowable<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> RxPagedListKt.toFlowable(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
int pageSize,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
Scheduler fetchScheduler,
Scheduler notifyScheduler,
@NonNull BackpressureStrategy backpressureStrategy
)
Constructs a Flowable<PagedList>, from this DataSource.Factory, convenience for RxPagedListBuilder.
The returned Flowable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.
| Parameters | |
|---|---|
int pageSize |
Page size. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to |
Scheduler fetchScheduler |
|
Scheduler notifyScheduler |
|
@NonNull BackpressureStrategy backpressureStrategy |
|
| See also | |
|---|---|
RxPagedListBuilder |
|
toObservable |
RxPagedListKt.toObservable
public final @NonNull Observable<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> RxPagedListKt.toObservable(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
@NonNull PagedList.Config config,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
Scheduler fetchScheduler,
Scheduler notifyScheduler
)
Constructs a Observable<PagedList> from this DataSource.Factory, convenience for RxPagedListBuilder.
The returned Observable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.
| Parameters | |
|---|---|
@NonNull PagedList.Config config |
Paging configuration. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to PagedList load state. |
Scheduler fetchScheduler |
|
Scheduler notifyScheduler |
|
| See also | |
|---|---|
RxPagedListBuilder |
|
toFlowable |
RxPagedListKt.toObservable
public final @NonNull Observable<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> RxPagedListKt.toObservable(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
@NonNull PagedList.Config config,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
Scheduler fetchScheduler,
Scheduler notifyScheduler
)
Constructs a Observable<PagedList> from this DataSource.Factory, convenience for RxPagedListBuilder.
The returned Observable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.
| Parameters | |
|---|---|
@NonNull PagedList.Config config |
Paging configuration. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to PagedList load state. |
Scheduler fetchScheduler |
|
Scheduler notifyScheduler |
|
| See also | |
|---|---|
RxPagedListBuilder |
|
toFlowable |
RxPagedListKt.toObservable
public final @NonNull Observable<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> RxPagedListKt.toObservable(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
int pageSize,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
Scheduler fetchScheduler,
Scheduler notifyScheduler
)
Constructs a Observable<PagedList> from this DataSource.Factory, convenience for RxPagedListBuilder.
The returned Observable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.
| Parameters | |
|---|---|
int pageSize |
Size of pages to load. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to |
Scheduler fetchScheduler |
|
Scheduler notifyScheduler |
|
| See also | |
|---|---|
RxPagedListBuilder |
|
toFlowable |
RxPagedListKt.toObservable
public final @NonNull Observable<@NonNull PagedList<@NonNull Value>> <Key extends Object, Value extends Object> RxPagedListKt.toObservable(
@NonNull DataSource.Factory<@NonNull Key, @NonNull Value> receiver,
int pageSize,
Key initialLoadKey,
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback,
Scheduler fetchScheduler,
Scheduler notifyScheduler
)
Constructs a Observable<PagedList> from this DataSource.Factory, convenience for RxPagedListBuilder.
The returned Observable will already be subscribed on the fetchScheduler, and will perform all loading on that scheduler. It will already be observed on notifyScheduler, and will dispatch new PagedLists, as well as their updates to that scheduler.
| Parameters | |
|---|---|
int pageSize |
Size of pages to load. |
Key initialLoadKey |
Initial load key passed to the first |
PagedList.BoundaryCallback<@NonNull Value> boundaryCallback |
The boundary callback for listening to |
Scheduler fetchScheduler |
|
Scheduler notifyScheduler |
|
| See also | |
|---|---|
RxPagedListBuilder |
|
toFlowable |