PagingState


public final class PagingState<Key extends Object, Value extends Object>


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

Summary

Public constructors

<Key extends Object, Value extends Object> PagingState(
    @NonNull List<@NonNull PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value>> pages,
    Integer anchorPosition,
    @NonNull PagingConfig config,
    @IntRange(from = 0) int leadingPlaceholderCount
)

Public methods

final Value
closestItemToPosition(int anchorPosition)

Coerces anchorPosition to closest loaded value in pages.

final PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value>
closestPageToPosition(int anchorPosition)

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

boolean
equals(Object other)
final Value
final Integer

Most recently accessed index in the list, including placeholders.

final @NonNull PagingConfig

PagingConfig that was given when initializing the PagingData stream.

final @NonNull List<@NonNull PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value>>

Loaded pages of data in the list.

int
final boolean
final Value
@NonNull String

Public constructors

PagingState

public <Key extends Object, Value extends Object> PagingState(
    @NonNull List<@NonNull PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value>> pages,
    Integer anchorPosition,
    @NonNull PagingConfig config,
    @IntRange(from = 0) int leadingPlaceholderCount
)

Public methods

closestItemToPosition

Added in 3.0.0
public final Value closestItemToPosition(int anchorPosition)

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
int anchorPosition

Index in the list, including placeholders.

Returns
Value

The closest loaded Value in pages to the provided anchorPosition. null if all loaded pages are empty.

closestPageToPosition

Added in 3.0.0
public final PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value> closestPageToPosition(int anchorPosition)

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
int anchorPosition

Index in the list, including placeholders.

Returns
PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value>

The closest loaded Value in pages to the provided anchorPosition. null if all loaded pages are empty.

equals

public boolean equals(Object other)

firstItemOrNull

Added in 3.0.0
public final Value firstItemOrNull()
Returns
Value

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.

getAnchorPosition

Added in 3.0.0
public final Integer getAnchorPosition()

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.

getConfig

Added in 3.0.0
public final @NonNull PagingConfig getConfig()

PagingConfig that was given when initializing the PagingData stream.

getPages

Added in 3.0.0
public final @NonNull List<@NonNull PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value>> getPages()

Loaded pages of data in the list.

hashCode

public int hashCode()

isEmpty

Added in 3.0.0
public final boolean isEmpty()
Returns
boolean

true if all loaded pages are empty or no pages were loaded when this PagingState was created, false otherwise.

lastItemOrNull

Added in 3.0.0
public final Value lastItemOrNull()
Returns
Value

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

public @NonNull String toString()