| <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><Key extends <a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>, Value extends <a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>> 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"> ↳</td> |
| <td colspan="2"><a href="/reference/androidx/paging/PagingSource.html">androidx.paging.PagingSource</a></td> |
| </tr> |
| <tr> |
| <td> </td> |
| <td class="jd-inheritance-space"> ↳</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<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 } |
| } |
| }</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><Key extends <a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>, Value extends <a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>> <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><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key, @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value></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><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key> 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><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key, @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value>></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><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key> 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><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key, @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value> 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> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0<<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>> 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> @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0<<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>> 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 <Key extends <a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>, Value extends <a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>> <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 @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key, @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value> <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><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key> 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 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><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key, @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value>> <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><@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key> 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> |