ItemKeyedDataSource

public abstract class ItemKeyedDataSource<Key extends Object, Value extends Object> extends DataSource

Object
   ↳ DataSource
     ↳ ItemKeyedDataSource

Incremental data loader for paging keyed content, where loaded content uses previously loaded items as input to future loads.

Implement a DataSource using ItemKeyedDataSource if you need to use data from item N - 1 to load item N. This is common, for example, in uniquely sorted database queries where attributes of the item such just before the next query define how to execute it.

The InMemoryByItemRepository in the PagingWithNetworkSample shows how to implement a network ItemKeyedDataSource using Retrofit, while handling swipe-to-refresh, network errors, and retry.

Parameters
<Key extends Object>

Type of data used to query Value types out of the DataSource.

<Value extends Object>

Type of items being loaded by the DataSource.

Summary

Nested types

ItemKeyedDataSource.LoadCallback

Callback for ItemKeyedDataSource loadBefore and loadAfter to return data.

ItemKeyedDataSource.LoadInitialCallback

Callback for loadInitial to return data and, optionally, position/count information.

ItemKeyedDataSource.LoadInitialParams

Holder object for inputs to loadInitial.

ItemKeyedDataSource.LoadParams

Holder object for inputs to loadBefore and loadAfter.

Public constructors

<Key extends Object, Value extends Object> ItemKeyedDataSource()

Public methods

abstract @NonNull Key
getKey(Value item)

Return a key associated with the given item.

abstract void
loadAfter(
    ItemKeyedDataSource.LoadParams<Key> params,
    ItemKeyedDataSource.LoadCallback<Value> callback
)

Load list data after the key specified in LoadParams.key.

abstract void
loadBefore(
    ItemKeyedDataSource.LoadParams<Key> params,
    ItemKeyedDataSource.LoadCallback<Value> callback
)

Load list data before the key specified in LoadParams.key.

abstract void

Load initia