diff --git a/CHANGELOG.md b/CHANGELOG.md index 169eae4cc54..2d10a9b3f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,17 @@ * `Ktor`: * All previously standard functions related to work with binary data by default have been deprecated +## 0.11.14 + +* `Pagination`: + * `PaginationResult` got new field `objectsNumber` which by default is a times between `pagesNumber` and `size` + +## 0.11.13 + +* `Versions`: + * `Coroutines`: `1.6.3` -> `1.6.4` + * `Compose`: `1.2.0-alpha01-dev629` -> `1.2.0-alpha01-dev731` + ## 0.11.12 * `Repos`: diff --git a/gradle.properties b/gradle.properties index 12752a9d35c..8b24b628623 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,4 @@ crypto_js_version=4.1.1 group=dev.inmo version=0.12.0 -android_code_version=137 +android_code_version=139 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 00e33edef69..8049c684f04 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt index fbc092069d4..6a62cf5bdfa 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt @@ -1,23 +1,60 @@ package dev.inmo.micro_utils.pagination -import kotlinx.serialization.Serializable +import kotlinx.serialization.* +import kotlin.math.ceil +/** + * @param page Current page number + * @param size Current page size. It can be greater than size of [results] + * @param results Result objects + * @param objectsNumber Count of all objects across all pages + */ @Serializable data class PaginationResult( override val page: Int, - val pagesNumber: Int, + override val size: Int, val results: List, - override val size: Int -) : Pagination + val objectsNumber: Long +) : Pagination { + /** + * Amount of pages for current pagination + */ + @EncodeDefault + val pagesNumber: Int = ceil(objectsNumber / size.toFloat()).toInt() -fun emptyPaginationResult() = PaginationResult(0, 0, emptyList(), 0) + constructor( + page: Int, + results: List, + pagesNumber: Int, + size: Int + ) : this( + page, + size, + results, + (pagesNumber * size).toLong() + ) + @Deprecated("Replace with The other order of incoming parameters or objectsCount parameter") + constructor( + page: Int, + pagesNumber: Int, + results: List, + size: Int + ) : this( + page, + results, + pagesNumber, + size + ) +} + +fun emptyPaginationResult() = PaginationResult(0, 0, emptyList(), 0L) /** * @return New [PaginationResult] with [data] without checking of data sizes equality */ fun PaginationResult.changeResultsUnchecked( data: List -): PaginationResult = PaginationResult(page, pagesNumber, data, size) +): PaginationResult = PaginationResult(page, size, data, objectsNumber) /** * @return New [PaginationResult] with [data] with checking of data sizes equality */ @@ -33,12 +70,9 @@ fun List.createPaginationResult( commonObjectsNumber: Long ) = PaginationResult( pagination.page, - calculatePagesNumber( - commonObjectsNumber, - pagination.size - ), + pagination.size, this, - pagination.size + commonObjectsNumber ) fun List.createPaginationResult( @@ -46,12 +80,9 @@ fun List.createPaginationResult( commonObjectsNumber: Long ) = PaginationResult( calculatePage(firstIndex, size), - calculatePagesNumber( - commonObjectsNumber, - size - ), + size, this, - size + commonObjectsNumber ) fun Pair>.createPaginationResult( diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/SimplePagination.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/SimplePagination.kt index fed71b34d72..11d2d90fbfd 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/SimplePagination.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/SimplePagination.kt @@ -26,6 +26,10 @@ inline fun Pagination.nextPage() = size ) +/** + * @param page Current page number + * @param size Current page size + */ @Serializable data class SimplePagination( override val page: Int, diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/KeyValueMappers.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/KeyValueMappers.kt index bd4c2653917..1afaeb8806f 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/KeyValueMappers.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/KeyValueMappers.kt @@ -1,7 +1,6 @@ package dev.inmo.micro_utils.repos.mappers -import dev.inmo.micro_utils.pagination.Pagination -import dev.inmo.micro_utils.pagination.PaginationResult +import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.repos.* import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map @@ -21,11 +20,8 @@ open class MapperReadKeyValueRepo( pagination, reversed ).let { - PaginationResult( - it.page, - it.pagesNumber, - it.results.map { it.toInnerValue() }, - it.size + it.changeResultsUnchecked( + it.results.map { it.toInnerValue() } ) } @@ -36,11 +32,8 @@ open class MapperReadKeyValueRepo( pagination, reversed ).let { - PaginationResult( - it.page, - it.pagesNumber, - it.results.map { it.toInnerKey() }, - it.size + it.changeResultsUnchecked( + it.results.map { it.toInnerKey() } ) } @@ -53,11 +46,8 @@ open class MapperReadKeyValueRepo( pagination, reversed ).let { - PaginationResult( - it.page, - it.pagesNumber, - it.results.map { it.toInnerKey() }, - it.size + it.changeResultsUnchecked( + it.results.map { it.toInnerKey() } ) } diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/OneToManyKeyValueMappers.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/OneToManyKeyValueMappers.kt index fdf9d989240..93b165e4c58 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/OneToManyKeyValueMappers.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/OneToManyKeyValueMappers.kt @@ -1,7 +1,6 @@ package dev.inmo.micro_utils.repos.mappers -import dev.inmo.micro_utils.pagination.Pagination -import dev.inmo.micro_utils.pagination.PaginationResult +import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.repos.* import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map @@ -19,11 +18,8 @@ open class MapperReadKeyValuesRepo( pagination, reversed ).let { - PaginationResult( - it.page, - it.pagesNumber, - it.results.map { it.toInnerValue() }, - it.size + it.changeResultsUnchecked( + it.results.map { it.toInnerValue() } ) } @@ -34,11 +30,8 @@ open class MapperReadKeyValuesRepo( pagination, reversed ).let { - PaginationResult( - it.page, - it.pagesNumber, - it.results.map { it.toInnerKey() }, - it.size + it.changeResultsUnchecked( + it.results.map { it.toInnerKey() } ) } @@ -51,11 +44,8 @@ open class MapperReadKeyValuesRepo( pagination, reversed ).let { - PaginationResult( - it.page, - it.pagesNumber, - it.results.map { it.toInnerKey() }, - it.size + it.changeResultsUnchecked( + it.results.map { it.toInnerKey() } ) } diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt index dbddcbf52cb..ccbc93fe0b7 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt @@ -3,8 +3,7 @@ package dev.inmo.micro_utils.repos.keyvalue import android.content.Context import android.content.SharedPreferences import androidx.core.content.edit -import dev.inmo.micro_utils.pagination.Pagination -import dev.inmo.micro_utils.pagination.PaginationResult +import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.utils.paginate import dev.inmo.micro_utils.pagination.utils.reverse import dev.inmo.micro_utils.repos.KeyValueRepo @@ -72,14 +71,11 @@ class KeyValueStore internal constructor ( return sharedPreferences.all.values.paginate( resultPagination ).let { - PaginationResult( - it.page, - it.pagesNumber, + it.changeResultsUnchecked( it.results.map { @Suppress("UNCHECKED_CAST") it as T - }.let { if (reversed) it.reversed() else it }, - it.size + }.let { if (reversed) it.reversed() else it } ) } } @@ -89,11 +85,8 @@ class KeyValueStore internal constructor ( return sharedPreferences.all.keys.paginate( resultPagination ).let { - PaginationResult( - it.page, - it.pagesNumber, - it.results.let { if (reversed) it.reversed() else it }, - it.size + it.changeResultsUnchecked( + it.results.let { if (reversed) it.reversed() else it } ) } } @@ -103,11 +96,8 @@ class KeyValueStore internal constructor ( return sharedPreferences.all.mapNotNull { (k, value) -> if (value == v) k else null }.paginate( resultPagination ).let { - PaginationResult( - it.page, - it.pagesNumber, - it.results.let { if (reversed) it.reversed() else it }, - it.size + it.changeResultsUnchecked( + it.results.let { if (reversed) it.reversed() else it } ) } }