Continuous

class Continuous<T : Any>(val load: suspend (continuation: String?) -> Page<T>) : PagedData<T>

A class representing a continuous page of data.

This class is used to load data in chunks. It takes a function that loads a page of data, with the given continuation token and returns a Page with the next continuation token.

If next continuation token is null, it means there is no more data to load. The initial call to load will have a null continuation token.

Example for using with an API that uses Strings as continuation tokens:

val data = PagedData.Continuous { continuation ->
val (tracks, nextCont) = api.loadTracks(continuation)
Page(tracks, nextCont)
}

Example for using with an API that uses Integers as continuation tokens:

val totalTracks = api.getTotalTracks()
val data = PagedData.Continuous { continuation ->
val contInt = continuation?.toIntOrNull() ?: 0
val tracks = api.loadTracks(contInt)
val nextContinuation = contInt + 10
if (nextContinuation >= totalTracks) Page(tracks, null)
else Page(tracks, nextContinuation)
}

Parameters

load

The function to load a Page for a given continuation token

Constructors

Link copied to clipboard
constructor(load: suspend (continuation: String?) -> Page<T>)

Properties

Link copied to clipboard
val load: suspend (continuation: String?) -> Page<T>

Functions

Link copied to clipboard
open override fun clear(): <Error class: unknown class>

To clear all the cache of paged data

Link copied to clipboard
open override fun invalidate(continuation: String?)
Link copied to clipboard
suspend fun loadAll(): List<T>

To load all the data

Link copied to clipboard
open suspend override fun loadAllInternal(): List<T>
Link copied to clipboard
open suspend override fun loadListInternal(continuation: String?): Page<T>
Link copied to clipboard
suspend fun loadPage(continuation: String?): Page<T>
Link copied to clipboard
open override fun <R : Any> map(block: suspend (<Error class: unknown class><List<T>>) -> List<R>): PagedData<R>
Link copied to clipboard
fun <T : Any> PagedData<T>.toFeed(buttons: Feed.Buttons? = null, background: ImageHolder? = null): Feed<T>

Convenience function to create a Feed from a PagedData of T items.

Link copied to clipboard
fun <T : Any> PagedData<T>.toFeedData(buttons: Feed.Buttons? = null, background: ImageHolder? = null): Feed.Data<T>

Convenience function to convert a PagedData to a Feed.Data.