PaginationResult#objectsCount

This commit is contained in:
InsanusMokrassar 2022-07-25 13:31:15 +06:00
parent 324832a189
commit eea645c865
5 changed files with 30 additions and 54 deletions

View File

@ -2,6 +2,9 @@
## 0.11.14 ## 0.11.14
* `Pagination`:
* `PaginationResult` got new field `objectsCount` which by default is a times between `pagesNumber` and `size`
## 0.11.13 ## 0.11.13
* `Versions`: * `Versions`:

View File

@ -7,7 +7,8 @@ data class PaginationResult<T>(
override val page: Int, override val page: Int,
val pagesNumber: Int, val pagesNumber: Int,
val results: List<T>, val results: List<T>,
override val size: Int override val size: Int,
val objectsCount: Long = pagesNumber * size.toLong()
) : Pagination ) : Pagination
fun <T> emptyPaginationResult() = PaginationResult<T>(0, 0, emptyList(), 0) fun <T> emptyPaginationResult() = PaginationResult<T>(0, 0, emptyList(), 0)
@ -38,7 +39,8 @@ fun <T> List<T>.createPaginationResult(
pagination.size pagination.size
), ),
this, this,
pagination.size pagination.size,
commonObjectsNumber
) )
fun <T> List<T>.createPaginationResult( fun <T> List<T>.createPaginationResult(
@ -51,7 +53,8 @@ fun <T> List<T>.createPaginationResult(
size size
), ),
this, this,
size size,
commonObjectsNumber
) )
fun <T> Pair<Long, List<T>>.createPaginationResult( fun <T> Pair<Long, List<T>>.createPaginationResult(

View File

@ -1,7 +1,6 @@
package dev.inmo.micro_utils.repos.mappers package dev.inmo.micro_utils.repos.mappers
import dev.inmo.micro_utils.pagination.Pagination import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
@ -23,11 +22,8 @@ open class MapperReadKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
pagination, pagination,
reversed reversed
).let { ).let {
PaginationResult( it.changeResultsUnchecked(
it.page, it.results.map { it.toInnerValue() }
it.pagesNumber,
it.results.map { it.toInnerValue() },
it.size
) )
} }
@ -38,11 +34,8 @@ open class MapperReadKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
pagination, pagination,
reversed reversed
).let { ).let {
PaginationResult( it.changeResultsUnchecked(
it.page, it.results.map { it.toInnerKey() }
it.pagesNumber,
it.results.map { it.toInnerKey() },
it.size
) )
} }
@ -55,11 +48,8 @@ open class MapperReadKeyValueRepo<FromKey, FromValue, ToKey, ToValue>(
pagination, pagination,
reversed reversed
).let { ).let {
PaginationResult( it.changeResultsUnchecked(
it.page, it.results.map { it.toInnerKey() }
it.pagesNumber,
it.results.map { it.toInnerKey() },
it.size
) )
} }

View File

@ -1,7 +1,6 @@
package dev.inmo.micro_utils.repos.mappers package dev.inmo.micro_utils.repos.mappers
import dev.inmo.micro_utils.pagination.Pagination import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
@ -21,11 +20,8 @@ open class MapperReadKeyValuesRepo<FromKey, FromValue, ToKey, ToValue>(
pagination, pagination,
reversed reversed
).let { ).let {
PaginationResult( it.changeResultsUnchecked(
it.page, it.results.map { it.toInnerValue() }
it.pagesNumber,
it.results.map { it.toInnerValue() },
it.size
) )
} }
@ -36,11 +32,8 @@ open class MapperReadKeyValuesRepo<FromKey, FromValue, ToKey, ToValue>(
pagination, pagination,
reversed reversed
).let { ).let {
PaginationResult( it.changeResultsUnchecked(
it.page, it.results.map { it.toInnerKey() }
it.pagesNumber,
it.results.map { it.toInnerKey() },
it.size
) )
} }
@ -53,11 +46,8 @@ open class MapperReadKeyValuesRepo<FromKey, FromValue, ToKey, ToValue>(
pagination, pagination,
reversed reversed
).let { ).let {
PaginationResult( it.changeResultsUnchecked(
it.page, it.results.map { it.toInnerKey() }
it.pagesNumber,
it.results.map { it.toInnerKey() },
it.size
) )
} }

View File

@ -3,8 +3,7 @@ package dev.inmo.micro_utils.repos.keyvalue
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import androidx.core.content.edit import androidx.core.content.edit
import dev.inmo.micro_utils.pagination.Pagination import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.pagination.utils.paginate import dev.inmo.micro_utils.pagination.utils.paginate
import dev.inmo.micro_utils.pagination.utils.reverse import dev.inmo.micro_utils.pagination.utils.reverse
import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.micro_utils.repos.KeyValueRepo
@ -72,14 +71,11 @@ class KeyValueStore<T : Any> internal constructor (
return sharedPreferences.all.values.paginate( return sharedPreferences.all.values.paginate(
resultPagination resultPagination
).let { ).let {
PaginationResult( it.changeResultsUnchecked(
it.page,
it.pagesNumber,
it.results.map { it.results.map {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
it as T it as T
}.let { if (reversed) it.reversed() else it }, }.let { if (reversed) it.reversed() else it }
it.size
) )
} }
} }
@ -89,11 +85,8 @@ class KeyValueStore<T : Any> internal constructor (
return sharedPreferences.all.keys.paginate( return sharedPreferences.all.keys.paginate(
resultPagination resultPagination
).let { ).let {
PaginationResult( it.changeResultsUnchecked(
it.page, it.results.let { if (reversed) it.reversed() else it }
it.pagesNumber,
it.results.let { if (reversed) it.reversed() else it },
it.size
) )
} }
} }
@ -103,11 +96,8 @@ class KeyValueStore<T : Any> internal constructor (
return sharedPreferences.all.mapNotNull { (k, value) -> if (value == v) k else null }.paginate( return sharedPreferences.all.mapNotNull { (k, value) -> if (value == v) k else null }.paginate(
resultPagination resultPagination
).let { ).let {
PaginationResult( it.changeResultsUnchecked(
it.page, it.results.let { if (reversed) it.reversed() else it }
it.pagesNumber,
it.results.let { if (reversed) it.reversed() else it },
it.size
) )
} }
} }