RealmTiledDataSource

class RealmTiledDataSource<T : RealmModel, R : Any> : TiledDataSource<R>

Paging DataSource implementation that uses RealmQuery produced by realmQueryBuilder to fetch matching results and transform to transform the source RealmModel to any custom type represented by R.

Implementation notes: The data source relies on TiledDataSource callbacks TiledDataSource.loadRange to load RealmResults produced by the query at any position. In order to confirm to Realm's threading model, RealmDispatcher is expected to be used when converting this DataSource to Paging 3 factory using DataSource.Factory.asPagingSourceFactory. Thread safety/stability is not guaranteed when any other dispatcher is passed.

loadRange is called on the provided Dispatcher thread and RealmResults are immediately cached. Further load range requests simply copy the results from previously fetched RealmResults. Changes are observed on the RealmResults and upon any change, the data source is invalidated to force initial loading on RealmResults.

Thread safety for further transformation of fetched RealmResults is guaranteed only when provided transform returns non-managed instances. For sample implementation, see RealmCopyTransform

For a safe default, consider using asPagingItems which manages dispatcher lifecyle and transforms

See also

Parameters

realmQueryBuilder

The builder function that will be used to construct RealmQuery instanced. Will be called on loading thread.

transform

The transformation function that will be used to map live managed RealmModel instances to type R. The R should be unmanaged RealmModel objects or custom types. If managed instances are returned, then thread safety is not guaranteed.

Types

Factory
Link copied to clipboard
class Factory<T : RealmModel, R : Any>(realmQueryBuilder: RealmQueryBuilder<T>, transform: RealmModelTransform<T, R>) : DataSource.Factory<Int, R>
DataSource.Factory implementation to construct RealmTiledDataSource

Functions

addInvalidatedCallback
Link copied to clipboard
open fun addInvalidatedCallback(onInvalidatedCallback: DataSource.InvalidatedCallback)
countItems
Link copied to clipboard
open override fun countItems(): Int
invalidate
Link copied to clipboard
open fun invalidate()
loadInitial
Link copied to clipboard
open override fun loadInitial(params: PositionalDataSource.LoadInitialParams, callback: PositionalDataSource.LoadInitialCallback<R>)
loadRange
Link copied to clipboard
open override fun loadRange(startPosition: Int, count: Int): List<R>
open override fun loadRange(params: PositionalDataSource.LoadRangeParams, callback: PositionalDataSource.LoadRangeCallback<R>)
map
Link copied to clipboard
override fun <V : Any> map(function: Function<R, V>): PositionalDataSource<V>
override fun <V : Any> map(function: (R) -> V): PositionalDataSource<V>
mapByPage
Link copied to clipboard
override fun <V : Any> mapByPage(function: Function<List<R>, List<V>>): PositionalDataSource<V>
override fun <V : Any> mapByPage(function: (List<R>) -> List<V>): PositionalDataSource<V>
removeInvalidatedCallback
Link copied to clipboard
open fun removeInvalidatedCallback(onInvalidatedCallback: DataSource.InvalidatedCallback)

Properties

isInvalid
Link copied to clipboard
open val isInvalid: Boolean