DataSource.Factory



Factory for DataSources.

Data-loading systems of an application or library can implement this interface to allow LiveDatas 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, 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
Any>

Key identifying items in DataSource.

Any>

Type of items in the list loaded by the DataSources.

Summary

Public constructors

Any, Value : Any> Factory()
android

Public functions

() -> PagingSource
android
abstract DataSource

Create a DataSource.

android
open DataSource.Factory
Any> map(function: Function)

Applies the given function to each value emitted by DataSources produced by this Factory.

android
open DataSource.Factory
Any> map(function: (Value) -> ToValue)

Applies the given function to each value emitted by DataSources produced by this Factory.

android
open DataSource.Factory
Any> mapByPage(function: Function<ListList>)

Applies the given function to each value emitted by DataSources produced by this Factory.

android
open DataSource.Factory
Any> mapByPage(function: (List) -> List)

Applies the given function to each value emitted by DataSources produced by this Factory.

android

Extension functions

LiveData<PagedList>
Any, Value : Any> DataSource.Factory.toLiveData(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchExecutor: Executor
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
LiveData<PagedList>
Any, Value : Any> DataSource.Factory.toLiveData(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchExecutor: Executor
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Flowable<PagedList>
Any, Value : Any> DataSource.Factory.toFlowable(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?,
    backpressureStrategy: BackpressureStrategy
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Flowable<PagedList>
Any, Value : Any> DataSource.Factory.toFlowable(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?,
    backpressureStrategy: BackpressureStrategy
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Flowable<PagedList>
Any, Value : Any> DataSource.Factory.toFlowable(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?,
    backpressureStrategy: BackpressureStrategy
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Flowable<PagedList>
Any, Value : Any> DataSource.Factory.toFlowable(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?,
    backpressureStrategy: BackpressureStrategy
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Observable<PagedList>
Any, Value : Any> DataSource.Factory.toObservable(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Observable<PagedList>
Any, Value : Any> DataSource.Factory.toObservable(
    config: PagedList.Config,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Observable<PagedList>
Any, Value : Any> DataSource.Factory.toObservable(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android
Observable<PagedList>
Any, Value : Any> DataSource.Factory.toObservable(
    pageSize: Int,
    initialLoadKey: Key?,
    boundaryCallback: PagedList.BoundaryCallback?,
    fetchScheduler: Scheduler?,
    notifyScheduler: Scheduler?
)

This function is deprecated. PagedList is deprecated and has been replaced by PagingData

android

Public constructors

Factory

Any, Value : Any> Factory()
Parameters
Any>

Key identifying items in DataSource.

Any>

Type of items in the list loaded by the DataSources.

Public functions

asPagingSourceFactory

fun asPagingSourceFactory(
    fetchDispatcher: CoroutineDispatcher = Dispatchers.IO
): () -> PagingSource

create

abstract fun create(): DataSource

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 to observers.

Returns
DataSource

the new DataSource.

map

open fun Any> map(function: Function): DataSource.Factory

Applies the given function to each value emitted by DataSources produced by this Factory.

Same as mapByPage, but operates on individual items.

Parameters
Any>

Type of items produced by the new DataSource, from the passed function.

function: Function

Function that runs on each loaded item, returning items of a potentially new type.

Returns
DataSource.Factory

A new DataSource.Factory, which transforms items using the given function.

map

open fun Any> map(function: (Value) -> ToValue): DataSource.Factory

Applies the given function to each value emitted by DataSources produced by this Factory.

An overload of map that accepts a kotlin function type.

Same as mapByPage, but operates on individual items.

Parameters
Any>

Type of items produced by the new DataSource, from the passed function.

function: (Value) -> ToValue

Function that runs on each loaded item, returning items of a potentially new type.

Returns
DataSource.Factory

A new DataSource.Factory, which transforms items using the given function.

mapByPage

open fun Any> mapByPage(function: Function<ListList>): DataSource.Factory

Applies the given function to each value emitted by DataSources produced by this Factory.

Same as map, but allows for batch conversions.

Parameters
Any>

Type of items produced by the new DataSource, from the passed function.

function: Function<ListList>

Function that runs on each loaded page, returning items of a potentially new type.

Returns
DataSource.Factory

A new DataSource.Factory, which transforms items using the given function.

See also
map
map
mapByPage

mapByPage

open fun Any> mapByPage(function: (List) -> List): DataSource.Factory

Applies the given function to each value emitted by DataSources produced by this Factory.

An overload of mapByPage that accepts a kotlin function type.

Same as map, but allows for batch conversions.

Parameters
Any>

Type of items produced by the new DataSource, from the passed function.

function: (List) -> List

Function that runs on each loaded page, returning items of a potentially new type.

Returns
DataSource.Factory

A new DataSource.Factory, which transforms items using the given function.

See also
map
map
mapByPage

Extension functions

toLiveData

fun Any, Value : Any> DataSource.Factory.toLiveData(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor()
): LiveData<PagedList>

Constructs a LiveData, 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
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor()

Executor for fetching data from PagingSources.

toLiveData

fun Any, Value : Any> DataSource.Factory.toLiveData(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor()
): LiveData<PagedList>

Constructs a LiveData, 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
pageSize: Int

Page size.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / PagingSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor()

Executor for fetching data from DataSources.

toFlowable

fun Any, Value : Any> DataSource.Factory.toFlowable(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null,
    backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST
): Flowable<PagedList>

Constructs a Flowable, 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
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

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

notifyScheduler: Scheduler? = null

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

backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST

BackpressureStrategy for the Flowable to use.

toFlowable

fun Any, Value : Any> DataSource.Factory.toFlowable(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null,
    backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST
): Flowable<PagedList>

Constructs a Flowable, 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
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

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

notifyScheduler: Scheduler? = null

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

backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST

BackpressureStrategy for the Flowable to use.

toFlowable

fun Any, Value : Any> DataSource.Factory.toFlowable(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null,
    backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST
): Flowable<PagedList>

Constructs a Flowable, 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
pageSize: Int

Page size.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

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

notifyScheduler: Scheduler? = null

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

backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST

BackpressureStrategy for the Flowable to use.

toFlowable

fun Any, Value : Any> DataSource.Factory.toFlowable(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null,
    backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST
): Flowable<PagedList>

Constructs a Flowable, 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
pageSize: Int

Page size.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

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

notifyScheduler: Scheduler? = null

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

backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST

BackpressureStrategy for the Flowable to use.

toObservable

fun Any, Value : Any> DataSource.Factory.toObservable(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null
): Observable<PagedList>

Constructs a Observable 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
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

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

notifyScheduler: Scheduler? = null

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

toObservable

fun Any, Value : Any> DataSource.Factory.toObservable(
    config: PagedList.Config,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null
): Observable<PagedList>

Constructs a Observable 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
config: PagedList.Config

Paging configuration.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

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

notifyScheduler: Scheduler? = null

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

toObservable

fun Any, Value : Any> DataSource.Factory.toObservable(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null
): Observable<PagedList>

Constructs a Observable 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
pageSize: Int

Size of pages to load.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

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

notifyScheduler: Scheduler? = null

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

toObservable

fun Any, Value : Any> DataSource.Factory.toObservable(
    pageSize: Int,
    initialLoadKey: Key? = null,
    boundaryCallback: PagedList.BoundaryCallback? = null,
    fetchScheduler: Scheduler? = null,
    notifyScheduler: Scheduler? = null
): Observable<PagedList>

Constructs a Observable 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
pageSize: Int

Size of pages to load.

initialLoadKey: Key? = null

Initial load key passed to the first PagedList / DataSource.

boundaryCallback: PagedList.BoundaryCallback? = null

The boundary callback for listening to PagedList load state.

fetchScheduler: Scheduler? = null

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

notifyScheduler: Scheduler? = null

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