All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.fr.haan.bipak.PagingData.kt Maven / Gradle / Ivy

There is a newer version: 0.9.2
Show newest version
package fr.haan.bipak

/**
 * Contain current paged data (in [list]) and current load state (in [state])
 */
public data class PagingData(
    /**
     * The list of currently fetched data
     */
    public val list: List,
    /**
     * The current state of fetching operation
     */
    public val state: LoadState,
    /**
     * The total item count, if reported in [PagingDataSource.LoadResult.Page]
     */
    public val totalCount: Int?,
) {
    /**
     * Model of load state.
     */
    public sealed class LoadState {
        /**
         * No fetching operation in progress. No further data has been requested or the end of the list has
         * been reached
         */
        public object NotLoading : LoadState()

        /**
         * A page is currently being fetched. This value can be used in the UI layer to show a list loader
         */
        public object Loading : LoadState()

        /**
         * The last fetching operation has failed. his value can be used in the UI layer to show an error message.
         * Operation can be retried by using [PagingEventEmitter.retry]
         */
        public class Error(public val error: Throwable) : LoadState()
    }

    public companion object {
        /**
         * Return an empty [PagingData]. This can be used as an initial state to prevent using nullable value.
         */
        public fun  empty(): PagingData = PagingData(
            emptyList(),
            LoadState.NotLoading,
            0,
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy