PagedData

sealed class PagedData<T : Any>

A class that represents a paginated data. Used to load data in chunks.

If the data is continuous, use Continuous.

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

If the data is not continuous, you can just use Single.

val data = PagedData.Single { api.loadTracks() }

If you want to concatenate multiple paged data, use Concat.

val data = PagedData.Concat(
PagedData.Single { api.loadTracks() },
PagedData.Continuous { api.loadTracksPage(it) }
// Add more sources here
)

Parameters

T

The type of data

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class Concat<T : Any>(sources: PagedData<T>) : PagedData<T>

A class representing a concatenation of multiple data sources.

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

A class representing a continuous page of data.

Link copied to clipboard
class Single<T : Any>(val load: suspend () -> List<T>) : PagedData<T>

A class representing a single page of data.

Link copied to clipboard
class Suspend<T : Any>(getter: suspend () -> PagedData<T>) : PagedData<T>

Functions

Link copied to clipboard
abstract fun clear()

To clear all the cache of paged data

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

To load all the data

Link copied to clipboard
abstract suspend fun loadAllInternal(): List<T>
Link copied to clipboard
abstract suspend fun loadListInternal(continuation: String?): Page<T>
Link copied to clipboard
suspend fun loadPage(continuation: String?): Page<T>
Link copied to clipboard
abstract 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.