blob: 5176e6f77385e2f34f0514d8ff0d6abeec8f902a [file] [log] [blame]
<html devsite="true">
<head>
<title>ListenableFuturePagingSource</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<div id="metadata-info-block"></div>
<h1>ListenableFuturePagingSource</h1>
<p>
<pre>public abstract class <a href="/reference/androidx/paging/ListenableFuturePagingSource.html">ListenableFuturePagingSource</a>&lt;Key&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>,&nbsp;Value&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; extends <a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></pre>
</p>
<div class="devsite-table-wrapper">
<table class="jd-inheritance-table">
<tbody>
<tr>
<td colspan="3"><a href="https://developer.android.com/reference/java/lang/Object.html">java.lang.Object</a></td>
</tr>
<tr>
<td class="jd-inheritance-space">&nbsp;&nbsp;&nbsp;↳</td>
<td colspan="2"><a href="/reference/androidx/paging/PagingSource.html">androidx.paging.PagingSource</a></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="jd-inheritance-space">&nbsp;&nbsp;&nbsp;↳</td>
<td colspan="1"><a href="/reference/androidx/paging/ListenableFuturePagingSource.html">androidx.paging.ListenableFuturePagingSource</a></td>
</tr>
</tbody>
</table>
</div>
<hr>
<p><code><a href="https://guava.dev/releases/18.0/api/docs/package-list/com/google/common/util/concurrent/ListenableFuture.html">ListenableFuture</a></code>-based compatibility wrapper around <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>'s suspending APIs.</p>
<pre class="prettyprint">class MyListenableFuturePagingSource(
val myBackend: GuavaBackendService,
val searchTerm: String
) : ListenableFuturePagingSource&lt;String, Item&gt;() {
override fun loadFuture(
params: LoadParams&lt;String&gt;
): ListenableFuture&lt;LoadResult&lt;String, Item&gt;&gt; {
return myBackend
.searchUsers(
searchTerm = searchTerm,
pageKey = params.key
)
.transform&lt;LoadResult&lt;String, Item&gt;&gt;(
{ response -&gt;
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? -&gt; LoadResult.Error(t!!) },
networkExecutor
)
.catching(
HttpException::class.java,
{ t: HttpException? -&gt; LoadResult.Error(t!!) },
networkExecutor
)
}
override fun getRefreshKey(state: PagingState&lt;String, Item&gt;): String? {
return state.anchorPosition?.let { state.closestItemToPosition(it)?.id }
}
}</pre>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="100%"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td>
<div><code>&lt;Key&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>,&nbsp;Value&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/ListenableFuturePagingSource.html#ListenableFuturePagingSource()">ListenableFuturePagingSource</a>()</code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="100%"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value&gt;</code></td>
<td>
<div><code><a href="/reference/androidx/paging/ListenableFuturePagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key&gt;&nbsp;params)</code></div>
<p>Loading API for <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
</td>
</tr>
<tr>
<td width="40%"><code>abstract @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://guava.dev/releases/18.0/api/docs/package-list/com/google/common/util/concurrent/ListenableFuture.html">ListenableFuture</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value&gt;&gt;</code></td>
<td>
<div><code><a href="/reference/androidx/paging/ListenableFuturePagingSource.html#loadFuture(androidx.paging.PagingSource.LoadParams)">loadFuture</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key&gt;&nbsp;params)</code></div>
<p>Loading API for <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive" id="inhmethods">
<thead>
<tr>
<th colspan="100%"><h3>Inherited fields</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><devsite-expandable><span class="expand-control">From <a href="/reference/androidx/paging/PagingSource.html">androidx.paging.PagingSource</a></span>
<div class="devsite-table-wrapper">
<table class="responsive">
<tbody class="list">
<tr>
<td width="40%"><code>final boolean</code></td>
<td>
<div><code><a href="/reference/androidx/paging/PagingSource.html#invalid()">invalid</a></code></div>
<p>Whether this <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> has been invalidated, which should happen when the data this <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> represents changes since it was first instantiated.</p>
</td>
</tr>
<tr>
<td width="40%"><code>boolean</code></td>
<td>
<div><code><a href="/reference/androidx/paging/PagingSource.html#jumpingSupported()">jumpingSupported</a></code></div>
<p><code>true</code> if this <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> supports jumping, <code>false</code> otherwise.</p>
</td>
</tr>
<tr>
<td width="40%"><code>boolean</code></td>
<td>
<div><code><a href="/reference/androidx/paging/PagingSource.html#keyReuseSupported()">keyReuseSupported</a></code></div>
<p><code>true</code> if this <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> expects to re-use keys to load distinct pages without a call to <code><a href="/reference/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code>, <code>false</code> otherwise.</p>
</td>
</tr>
</tbody>
</table>
</div>
</devsite-expandable> </td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive" id="inhmethods">
<thead>
<tr>
<th colspan="100%"><h3>Inherited methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><devsite-expandable><span class="expand-control">From <a href="/reference/androidx/paging/PagingSource.html">androidx.paging.PagingSource</a></span>
<div class="devsite-table-wrapper">
<table class="responsive">
<tbody class="list">
<tr>
<td width="40%"><code>abstract Key</code></td>
<td>
<div><code><a href="/reference/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingState.html">PagingState</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value&gt;&nbsp;state)</code></div>
<p>Provide a <code><a href="/reference/androidx/paging/PagingSource.html">Key</a></code> used for the initial <code><a href="/reference/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a></code> for the next <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> due to invalidation of this <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
</td>
</tr>
<tr>
<td width="40%"><code>final void</code></td>
<td>
<div><code><a href="/reference/androidx/paging/PagingSource.html#invalidate()">invalidate</a>()</code></div>
<p>Signal the <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> to stop loading.</p>
</td>
</tr>
<tr>
<td width="40%"><code>final void</code></td>
<td>
<div><code><a href="/reference/androidx/paging/PagingSource.html#registerInvalidatedCallback(kotlin.Function0)">registerInvalidatedCallback</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;onInvalidatedCallback<br>)</code></div>
<p>Add a callback to invoke when the <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> is first invalidated.</p>
</td>
</tr>
<tr>
<td width="40%"><code>final void</code></td>
<td>
<div><code><a href="/reference/androidx/paging/PagingSource.html#unregisterInvalidatedCallback(kotlin.Function0)">unregisterInvalidatedCallback</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>&gt;&nbsp;onInvalidatedCallback<br>)</code></div>
<p>Remove a previously added invalidate callback.</p>
</td>
</tr>
</tbody>
</table>
</div>
</devsite-expandable> </td>
</tr>
</tbody>
</table>
</div>
<h2>Public constructors</h2>
<div><a name="ListenableFuturePagingSource--"></a><a name="listenablefuturepagingsource"></a>
<h3 class="api-name" id="ListenableFuturePagingSource()">ListenableFuturePagingSource</h3>
<pre class="api-signature no-pretty-print">public&nbsp;&lt;Key&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>,&nbsp;Value&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/ListenableFuturePagingSource.html#ListenableFuturePagingSource()">ListenableFuturePagingSource</a>()</pre>
</div>
<h2>Public methods</h2>
<div><a name="load-androidx.paging.PagingSource.LoadParams-"></a><a name="load"></a>
<h3 class="api-name" id="load(androidx.paging.PagingSource.LoadParams)">load</h3>
<pre class="api-signature no-pretty-print">public&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value&gt;&nbsp;<a href="/reference/androidx/paging/ListenableFuturePagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key&gt;&nbsp;params)</pre>
<p>Loading API for <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
<p>Implement this method to trigger your async load (e.g. from database or network).</p>
</div>
<div><a name="loadFuture-androidx.paging.PagingSource.LoadParams-"></a><a name="loadfuture"></a>
<h3 class="api-name" id="loadFuture(androidx.paging.PagingSource.LoadParams)">loadFuture</h3>
<pre class="api-signature no-pretty-print">public&nbsp;abstract&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://guava.dev/releases/18.0/api/docs/package-list/com/google/common/util/concurrent/ListenableFuture.html">ListenableFuture</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value&gt;&gt;&nbsp;<a href="/reference/androidx/paging/ListenableFuturePagingSource.html#loadFuture(androidx.paging.PagingSource.LoadParams)">loadFuture</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key&gt;&nbsp;params)</pre>
<p>Loading API for <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
<p>Implement this method to trigger your async load (e.g. from database or network).</p>
</div>
</body>
</html>