API reference
API reference
Select your platform
No SDKs available
No versions available

PagedResults Class

Provides access to paginated information from a backend.

Signature

abstract class PagedResults<T>

Properties

pages : Flow<Page<T>>
[Get]
Cold flow of paged data updates.
Signature
val <T> PagedResults<T>.pages: Flow<Page<T>>

Functions

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 ()
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.
As an exception to the above rule, if fetchInitialPage() is called while another 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
initialPage ()
Signature
suspend fun <T> PagedResults<T>.initialPage()
nextPage ()
Signature
suspend fun <T> PagedResults<T>.nextPage(): Boolean
Returns
Boolean
previousPage ()
Signature
suspend fun <T> PagedResults<T>.previousPage(): Boolean
Returns
Boolean
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.