Google is committed to advancing racial equity for Black communities. See how.

PagingState

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

Snapshot state of Paging system including the loaded pages, the last accessed anchorPosition, and the config used.

Summary

Public constructors
<init>(pages: List<PagingSource.LoadResult.Page<Key, Value>>, anchorPosition: Int?, config: PagingConfig, @IntRange(0) leadingPlaceholderCount: Int)

Snapshot state of Paging system including the loaded pages, the last accessed anchorPosition, and the config used.

Public methods
Value?
closestItemToPosition(anchorPosition: Int)

Coerces anchorPosition to closest loaded value in pages.

PagingSource.LoadResult.Page<Key, Value>?
closestPageToPosition(anchorPosition: Int)

Coerces an index in the list, including placeholders, to closest loaded page in pages.

Boolean
equals(other: Any?)

Value?

Int

Boolean

Value?

String

Properties
Int?

Most recently accessed index in the list, including placeholders.

PagingConfig

PagingConfig that was given when initializing the PagingData stream.

List<PagingSource.LoadResult.Page<Key, Value>>

Loaded pages of data in the list.

Public constructors

<init>

PagingState(
    pages: List<PagingSource.LoadResult.Page<Key, Value>>,
    anchorPosition: Int?,
    config: PagingConfig,
    @IntRange(0) leadingPlaceholderCount: Int)

Snapshot state of Paging system including the loaded pages, the last accessed anchorPosition, and the config used.

Public methods

closestItemToPosition

fun closestItemToPosition(anchorPosition: Int): Value?

Coerces anchorPosition to closest loaded value in pages.

This function can be called with anchorPosition to fetch the loaded item that is closest to the last accessed index in the list.

Parameters
anchorPosition: Int Index in the list, including placeholders.
Return
The closest loaded Value in pages to the provided anchorPosition. null if all loaded pages are empty.

closestPageToPosition

fun closestPageToPosition(anchorPosition: Int): PagingSource.LoadResult.Page<Key, Value>?

Coerces an index in the list, including placeholders, to closest loaded page in pages.

This function can be called with anchorPosition to fetch the loaded page that is closest to the last accessed index in the list.

Parameters
anchorPosition: Int Index in the list, including placeholders.
Return
The closest loaded Value in pages to the provided anchorPosition. null if all loaded pages are empty.

equals

fun equals(other: Any?): Boolean

firstItemOrNull

fun firstItemOrNull(): Value?
Return
The first loaded item in the list or null if all loaded pages are empty or no pages were loaded when this PagingState was created.

hashCode

fun hashCode(): Int

isEmpty

fun isEmpty(): Boolean
Return
true if all loaded pages are empty or no pages were loaded when this PagingState was created, false otherwise.

lastItemOrNull

fun lastItemOrNull(): Value?
Return
The last loaded item in the list or null if all loaded pages are empty or no pages were loaded when this PagingState was created.

toString

fun toString(): String

Properties

anchorPosition

val anchorPosition: Int?

Most recently accessed index in the list, including placeholders.

null if no access in the PagingData has been made yet. E.g., if this snapshot was generated before or during the first load.

config

val config: PagingConfig

PagingConfig that was given when initializing the PagingData stream.

pages

val pages: List<PagingSource.LoadResult.Page<Key, Value>>

Loaded pages of data in the list.