LegacyPagingSource

class LegacyPagingSource<Key : Any, Value : Any> : PagingSource<Key, Value>
kotlin.Any
   ↳ androidx.paging.PagingSource<Key, Value>
   ↳ androidx.paging.LegacyPagingSource

A wrapper around DataSource which adapts it to the PagingSource API.

Summary

Public constructors
LegacyPagingSource(fetchDispatcher: CoroutineDispatcher, dataSource: DataSource<Key, Value>)

A wrapper around DataSource which adapts it to the PagingSource API.

Public methods
Key?
getRefreshKey(state: PagingState<Key, Value>)

Provide a Key used for the initial load for the next PagingSource due to invalidation of this PagingSource.

suspend PagingSource.LoadResult<Key, Value>

Loading API for PagingSource.

Unit
setPageSize(pageSize: Int)

Inherited functions
Properties
Boolean

true if this PagingSource supports jumping, false otherwise.

Inherited properties

Public constructors

LegacyPagingSource

LegacyPagingSource(
    fetchDispatcher: CoroutineDispatcher,
    dataSource: DataSource<Key, Value>)

A wrapper around DataSource which adapts it to the PagingSource API.

Public methods

getRefreshKey

fun getRefreshKey(state: PagingState<Key, Value>): Key?

Provide a Key used for the initial load for the next PagingSource due to invalidation of this PagingSource. The Key is provided to load via LoadParams.key.

The Key returned by this method should cause load to load enough items to fill the viewport around the last accessed position, allowing the next generation to transparently animate in. The last accessed position can be retrieved via state.anchorPosition, which is typically the top-most or bottom-most item in the viewport due to access being triggered by binding items as they scroll into view.

For example, if items are loaded based on integer position keys, you can return state.anchorPosition.

Alternately, if items contain a key used to load, get the key from the item in the page at index state.anchorPosition.

Parameters
state: PagingState<Key, Value> PagingState of the currently fetched data, which includes the most recently accessed position in the list via PagingState.anchorPosition.
Return
Key passed to load after invalidation used for initial load of the next generation. The Key returned by getRefreshKey should load pages centered around user's current viewport. If the correct Key cannot be determined, null can be returned to allow load decide what default key to use.

load

suspend fun load(params: PagingSource.LoadParams<Key>): PagingSource.LoadResult<Key, Value>

Loading API for PagingSource.

Implement this method to trigger your async load (e.g. from database or network).

setPageSize

fun setPageSize(pageSize: Int): Unit

Properties

jumpingSupported

val jumpingSupported: Boolean

true if this PagingSource supports jumping, false otherwise.

Override this to true if pseudo-fast scrolling via jumps is supported.

A jump occurs when a RecyclerView scrolls through a number of placeholders defined by PagingConfig.jumpThreshold and triggers a load with LoadType.

PagingSources that support jumps should override getRefreshKey to return a Key that would load data fulfilling the viewport given a user's current PagingState.anchorPosition.