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( |
Public methods |
|
|---|---|
final Value |
closestItemAroundPosition(Coerces |
final Value |
closestItemToPosition(int anchorPosition)Coerces |
final PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value> |
closestPageToPosition(int anchorPosition)Coerces an index in the list, including placeholders, to closest loaded page in |
boolean |
|
final Value |
|
final Integer |
Most recently accessed index in the list, including placeholders. |
final @NonNull PagingConfig |
|
final @NonNull List<@NonNull PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value>> |
getPages()Loaded pages of data in the list. |
int |
hashCode() |
final boolean |
isEmpty() |
final Value |
|
@NonNull String |
toString() |
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
closestItemAroundPosition
public final Value closestItemAroundPosition(
int anchorPosition,
@NonNull Function1<@NonNull value, @NonNull Boolean> predicate
)
Coerces anchorPosition to closest loaded value in pages that matches predicate.
This function can be called with anchorPosition to fetch the loaded item that is closest to the last accessed index in the list.
This function searches for the matching predicate amongst items that are positioned both before and after the anchorPosition with this order of priority:
-
item closest to anchorPosition
-
item before anchorPosition
This means that given an anchorPosition of item10, if item8 and item11 both match the predicate, then item11 will be returned since it is closer to item10. If two matching items have the same proximity, then the item that comes first will be returned. So given an anchorPosition of item10, if item9 and item11 both match the predicate, then item9 will be returned since it comes before item11.
This method should be avoided if possible if used on Lists that do not support random access, otherwise performance will take a big hit.
closestItemToPosition
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 |
closestPageToPosition
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 |
firstItemOrNull
public final Value firstItemOrNull()
| Returns | |
|---|---|
Value |
The first loaded item in the list or |
getAnchorPosition
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
public final @NonNull PagingConfig getConfig()
PagingConfig that was given when initializing the PagingData stream.
getPages
public final @NonNull List<@NonNull PagingSource.LoadResult.Page<@NonNull Key, @NonNull Value>> getPages()
Loaded pages of data in the list.
isEmpty
public final boolean isEmpty()
| Returns | |
|---|---|
boolean |
|
lastItemOrNull
public final Value lastItemOrNull()
| Returns | |
|---|---|
Value |
The last loaded item in the list or |