{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public abstract class ListenableFuturePagingSource<Key extends Object, Value extends Object> extends PagingSource
ListenableFuture-based compatibility wrapper around PagingSource
's suspending APIs.
class MyListenableFuturePagingSource( val myBackend: GuavaBackendService, val searchTerm: String ) : ListenableFuturePagingSource<String, Item>() { override fun loadFuture( params: LoadParams<String> ): ListenableFuture<LoadResult<String, Item>> { return myBackend .searchUsers( searchTerm = searchTerm, pageKey = params.key ) .transform<LoadResult<String, Item>>( { response -> LoadResult.Page( data = response!!.items, prevKey = response.prev, nextKey = response.next ) }, networkExecutor ) // Retrofit calls that return the body type throw either IOException for // network failures, or HttpException for any non-2xx HTTP status codes. // This code reports all errors to the UI, but you can inspect/wrap the // exceptions to provide more context. .catching( IOException::class.java, { t: IOException? -> LoadResult.Error(t!!) }, networkExecutor ) .catching( HttpException::class.java, { t: HttpException? -> LoadResult.Error(t!!) }, networkExecutor ) } override fun getRefreshKey(state: PagingState<String, Item>): String? { return state.anchorPosition?.let { state.closestItemToPosition(it)?.id } } }
Public fields |
|
---|---|
final boolean |
Whether this |
boolean |
|
boolean |
|
Public constructors |
|
---|---|
<Key extends Object, Value extends Object> ListenableFuturePagingSource() |
Public methods |
|
---|---|
@NonNull PagingSource.LoadResult<@NonNull Key, @NonNull Value> |
load(@NonNull PagingSource.LoadParams<@NonNull Key> params) Loading API for |
abstract @NonNull <ERROR CLASS><@NonNull PagingSource.LoadResult<@NonNull Key, @NonNull Value>> |
loadFuture(@NonNull PagingSource.LoadParams<@NonNull Key> params) Loading API for |
Inherited methods |
||||||||
---|---|---|---|---|---|---|---|---|
|
@NonNull
public final boolean invalid
Whether this PagingSource
has been invalidated, which should happen when the data this PagingSource
represents changes since it was first instantiated.
@NonNull
public boolean jumpingSupported
true
if this PagingSource
supports jumping, false
otherwise.
Override this to true
if pseudo-fast scrolling via jumps is supported.
A jump occurs when a RecyclerView
scrolls through a number of placeholders defined by PagingConfig.jumpThreshold
and triggers a load with LoadType
.
PagingSource
s that support jumps should override getRefreshKey
to return a Key
that would load data fulfilling the viewport given a user's current PagingState.anchorPosition
.
See also | |
---|---|
jumpThreshold |
@NonNull
public boolean keyReuseSupported
true
if this PagingSource
expects to re-use keys to load distinct pages without a call to invalidate
, false
otherwise.
@NonNull
public final <Key extends Object, Value extends Object> ListenableFuturePagingSource()
@NonNull
public PagingSource.LoadResult<@NonNull Key, @NonNull Value> load(@NonNull PagingSource.LoadParams<@NonNull Key> params)
Loading API for PagingSource
.
Implement this method to trigger your async load (e.g. from database or network).
@NonNull
public abstract <ERROR CLASS><@NonNull PagingSource.LoadResult<@NonNull Key, @NonNull Value>> loadFuture(@NonNull PagingSource.LoadParams<@NonNull Key> params)
Loading API for PagingSource
.
Implement this method to trigger your async load (e.g. from database or network).