Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.sceyt.chatuikit.data.models
sealed interface PaginationResponse {
/**
* @param data is items from database.
* @param offset is the normalized offset, which has been set in in request.
* @param hasNext shows, are items in database or not, to load next page.
* @param query is the search query, which has been set in request.
* */
data class DBResponse(
val data: List,
val loadKey: LoadKeyData?,
val offset: Int,
val hasNext: Boolean = false,
val hasPrev: Boolean = false,
val loadType: LoadType = LoadType.LoadNext,
val query: String = "",
) : PaginationResponse
/**
* @param data is items from server.
* @param cacheData is items from database or from cache, include elements from start.
* @param loadKey is the the helper key, which has been set when request started.
* @param offset is the offset, which has been set when request started.
* @param hasDiff is the difference between database/cache items and server items.
* @param hasNext shows, are items in server/database or not, to load next page.
* @param hasPrev shows, are items in server/database or not, to load prev page.
* @param loadType is pointed which type of request is was current request.
* @param ignoredDb shows was loaded items from database or not, before server request is received.
* @param query is the search query, which has been set in request.
*
* */
data class ServerResponse(
val data: SceytResponse>,
val cacheData: List,
val loadKey: LoadKeyData?,
val offset: Int,
val hasDiff: Boolean,
val hasNext: Boolean,
val hasPrev: Boolean,
val loadType: LoadType,
val ignoredDb: Boolean,
val dbResultWasEmpty: Boolean = false,
val query: String = "",
) : PaginationResponse
/** Default value */
class Nothing : PaginationResponse
enum class LoadType {
LoadPrev, LoadNext, LoadNear, LoadNewest
}
}
data class LoadKeyData(
val key: Long = -1,
val value: Long = -1,
val data: Any? = null
)
fun PaginationResponse<*>.getLoadKey(): LoadKeyData? {
return when (this) {
is PaginationResponse.DBResponse -> loadKey
is PaginationResponse.ServerResponse -> loadKey
else -> null
}
}
fun PaginationResponse<*>.getOffset(): Int {
return when (this) {
is PaginationResponse.DBResponse -> offset
is PaginationResponse.ServerResponse -> offset
else -> 0
}
}