API reference

PagedResults Class

Provides access to paginated information from a backend.

Signature

abstract class PagedResults<T>

Extension Properties

pages : Flow<Page<T>>
[Get]
Cold flow of paged data updates.
Signature
val <T> PagedResults<T>.pages: Flow<Page<T>>
Extension declared in horizon.core.android.common.pagination.ext

Methods

addResultsObserver ( observer )
Add an observer of the currently fetched pages.
Observers update after fetchNextPage() and fetchPreviousPage() complete.
When added, the observer will be called immediately with the current list of fetched pages, if they exist.
Signature
open fun addResultsObserver(observer: PagedResultsObserver<T>)
Parameters
observer: PagedResultsObserver
fetchInitialPage ()
Retrieve the initial page of data.
When the returned Future completes, observers to this object will be guaranteed to receive the fetched page.
if PagedResults.fetchInitialPage is called while another PagedResults.fetchInitialPage is in progress, it will not queue a new fetch, but will instead return a future that completes with the existing fetch. This allows the caller to check the state of the initial fetch (on construction) and handle any exceptions.
If the fetch fails, this future will complete exceptionally. Fetches queued after this fetch will not be affected.
Signature
open fun fetchInitialPage(): CompletableFuture<Void>
Returns
CompletableFuture
fetchNextPage ()
Move to the next page of data.
When the returned Future completes, observers to this object will be guaranteed to receive the fetched page.
If there is no next page, the future completes with a value of false.
If multiple calls to fetch functions happen concurrently, they will run in sequence, and complete in the order they were called.
If the fetch fails, this future will complete exceptionally. Fetches queued after this fetch will not be affected.
Signature
open fun fetchNextPage(): CompletableFuture<Boolean>
Returns
CompletableFuture
fetchPreviousPage ()
Move to the previous page of data.
When the returned Future completes, observers to this object will be guaranteed to receive the fetched page.
If there is no previous page, the future completes with a value of false.
If multiple calls to fetch functions happen concurrently, they will run in sequence, and complete in the order they were called.
If the fetch fails, this future will complete exceptionally. Fetches queued after this fetch will not be affected.
Signature
open fun fetchPreviousPage(): CompletableFuture<Boolean>
Returns
CompletableFuture
getFetchedPages ()
Returns the list of currently fetched pages.
This list is not synchronized. If an initial fetch has failed or is not yet done, this will return an empty list.
Signature
open fun getFetchedPages(): List<Page<T>>
Returns
List
hasNextPage ()
Returns if there is a next page to fetch.
If the initial fetch has not completed, this will return false.
Signature
open fun hasNextPage(): Boolean
Returns
Boolean
hasPreviousPage ()
Returns if there is a previous page to fetch.
If the initial fetch has not completed, this will return false.
Signature
open fun hasPreviousPage(): Boolean
Returns
Boolean
refetchInitialPage ()
Move back to the initial page of data.
When the returned Future completes, observers to this object will be guaranteed to receive the fetched page.
If multiple calls to fetch functions run concurrently, they will run in sequence, and complete in the order they were called. If you intend to avoid multiple calls to retireve the initial page, you can use PagedResults.fetchInitialPage instead.
If the fetch fails, this future will complete exceptionally. Fetches queued after this fetch will not be affected.
Signature
open fun refetchInitialPage(): CompletableFuture<Void>
Returns
CompletableFuture
removeResultsObserver ( observer )
Remove an observer of the currently fetched pages.
Signature
open fun removeResultsObserver(observer: PagedResultsObserver<T>): Boolean
Parameters
observer: PagedResultsObserver
Returns
Boolean  whether the observer was observing this object before removal.

Extension Functions

initialPage ()
Signature
suspend fun <T> PagedResults<T>.initialPage()
Extension declared in horizon.core.android.common.pagination.ext
nextPage ()
Signature
suspend fun <T> PagedResults<T>.nextPage(): Boolean
Extension declared in horizon.core.android.common.pagination.ext
Returns
Boolean
previousPage ()
Signature
suspend fun <T> PagedResults<T>.previousPage(): Boolean
Extension declared in horizon.core.android.common.pagination.ext
Returns
Boolean