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(@NonNull Value item)

Return a key associated with the given item.

abstract void

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

abstract void

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

abstract void

Load initial data.

final @NonNull ItemKeyedDataSource<@NonNull Key, @NonNull ToValue>
<ToValue extends Object> map(
    @NonNull Function<@NonNull Value, @NonNull ToValue> function
)

Applies the given function to each value emitted by the DataSource.

final @NonNull ItemKeyedDataSource<@NonNull Key, @NonNull ToValue>
<ToValue extends Object> map(
    @NonNull Function1<@NonNull Value, @NonNull ToValue> function
)

Applies the given function to each value emitted by the DataSource.

final @NonNull ItemKeyedDataSource<@NonNull Key, @NonNull ToValue>
<ToValue extends Object> mapByPage(
    @NonNull Function<@NonNull List<@NonNull Value>, @NonNull List<@NonNull ToValue>> function
)

Applies the given function to each value emitted by the DataSource.

final @NonNull ItemKeyedDataSource<@NonNull Key, @NonNull ToValue>
<ToValue extends Object> mapByPage(
    @NonNull Function1<@NonNull List<@NonNull Value>, @NonNull List<@NonNull ToValue>> function
)

Applies the given function to each value emitted by the DataSource.

Inherited methods

From class DataSource
@AnyThread void

Add a callback to invoke when the DataSource is first invalidated.

@AnyThread void

Signal the data source to stop loading, and notify its callback.

@AnyThread void

Remove a previously added invalidate callback.

Public constructors

ItemKeyedDataSource

public final