From d51bdc50866751c3c8aff7566a5af127d013b99e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 18 Jul 2022 13:48:09 +0600 Subject: [PATCH 01/11] Update gradle.properties --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 103c83c8a17..632f70a2d7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.11.12 -android_code_version=136 +version=0.11.13 +android_code_version=137 From 6bf0ce92ba7a7661ea924ee70015136dd304634c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 18 Jul 2022 13:51:00 +0600 Subject: [PATCH 02/11] Update libs.versions.toml --- gradle/libs.versions.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 507963d3133..974f4531901 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,9 +2,9 @@ kt = "1.6.21" kt-serialization = "1.3.3" -kt-coroutines = "1.6.3" +kt-coroutines = "1.6.4" -jb-compose = "1.2.0-alpha01-dev729" +jb-compose = "1.2.0-alpha01-dev745" jb-exposed = "0.38.2" jb-dokka = "1.6.21" From 0e4188882f07905dab7f97824071eaf24df2eb78 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 18 Jul 2022 14:08:23 +0600 Subject: [PATCH 03/11] Update libs.versions.toml --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 974f4531901..031eae77080 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ kt = "1.6.21" kt-serialization = "1.3.3" kt-coroutines = "1.6.4" -jb-compose = "1.2.0-alpha01-dev745" +jb-compose = "1.2.0-alpha01-dev731" jb-exposed = "0.38.2" jb-dokka = "1.6.21" From 70c31966ca1cf33183afe97179231c8e121108e1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 18 Jul 2022 14:33:04 +0600 Subject: [PATCH 04/11] Update gradle-wrapper.properties --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From e3ff1b9609d6c8bed7fdda7856c19542bf2ba144 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 22 Jul 2022 16:31:33 +0600 Subject: [PATCH 05/11] fill changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 591639e8deb..6e72e8b21fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 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`: From 324832a18943ea487a421c5193699802ce884d0f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 25 Jul 2022 13:14:55 +0600 Subject: [PATCH 06/11] start 0.11.14 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e72e8b21fe..a80f1d8721e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.11.14 + ## 0.11.13 * `Versions`: diff --git a/gradle.properties b/gradle.properties index 632f70a2d7b..e32a7c883b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.11.13 -android_code_version=137 +version=0.11.14 +android_code_version=138 From eea645c865718225a2496731dc7044d1b881163f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 25 Jul 2022 13:31:15 +0600 Subject: [PATCH 07/11] PaginationResult#objectsCount --- CHANGELOG.md | 3 +++ .../pagination/PaginationResult.kt | 9 ++++--- .../repos/mappers/KeyValueMappers.kt | 24 ++++++------------- .../repos/mappers/OneToManyKeyValueMappers.kt | 24 ++++++------------- .../repos/keyvalue/KeyValueStore.kt | 24 ++++++------------- 5 files changed, 30 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a80f1d8721e..4ad586b1834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.11.14 +* `Pagination`: + * `PaginationResult` got new field `objectsCount` which by default is a times between `pagesNumber` and `size` + ## 0.11.13 * `Versions`: 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..a24053294bd 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 @@ -7,7 +7,8 @@ data class PaginationResult( override val page: Int, val pagesNumber: Int, val results: List, - override val size: Int + override val size: Int, + val objectsCount: Long = pagesNumber * size.toLong() ) : Pagination fun emptyPaginationResult() = PaginationResult(0, 0, emptyList(), 0) @@ -38,7 +39,8 @@ fun List.createPaginationResult( pagination.size ), this, - pagination.size + pagination.size, + commonObjectsNumber ) fun List.createPaginationResult( @@ -51,7 +53,8 @@ fun List.createPaginationResult( size ), this, - size + size, + commonObjectsNumber ) fun Pair>.createPaginationResult( 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 4df2b614f6e..dfabde93e95 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 @@ -23,11 +22,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() } ) } @@ -38,11 +34,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() } ) } @@ -55,11 +48,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 f74b81d9149..809f7ae340c 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 @@ -21,11 +20,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() } ) } @@ -36,11 +32,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() } ) } @@ -53,11 +46,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 } ) } } From 703094c924b4cf4e212caa50ea7d3f09e21c90ba Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 26 Jul 2022 13:56:47 +0600 Subject: [PATCH 08/11] add several additional constructors for the pagination result --- .../pagination/PaginationResult.kt | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) 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 a24053294bd..54cf4a4039e 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,24 +1,50 @@ package dev.inmo.micro_utils.pagination import kotlinx.serialization.Serializable +import kotlin.math.ceil @Serializable data class PaginationResult( override val page: Int, - val pagesNumber: Int, - val results: List, override val size: Int, - val objectsCount: Long = pagesNumber * size.toLong() -) : Pagination + val results: List, + val objectsCount: Long +) : Pagination { + val pagesNumber: Int = ceil(objectsCount / 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, objectsCount) /** * @return New [PaginationResult] with [data] with checking of data sizes equality */ @@ -34,12 +60,8 @@ fun List.createPaginationResult( commonObjectsNumber: Long ) = PaginationResult( pagination.page, - calculatePagesNumber( - commonObjectsNumber, - pagination.size - ), - this, pagination.size, + this, commonObjectsNumber ) @@ -48,12 +70,8 @@ fun List.createPaginationResult( commonObjectsNumber: Long ) = PaginationResult( calculatePage(firstIndex, size), - calculatePagesNumber( - commonObjectsNumber, - size - ), - this, size, + this, commonObjectsNumber ) From 087d7452fd176f465990ae962082d10e0e1dd941 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 26 Jul 2022 14:54:52 +0600 Subject: [PATCH 09/11] encode by default pages number --- .../kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 54cf4a4039e..96bb73b66b0 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,6 +1,6 @@ package dev.inmo.micro_utils.pagination -import kotlinx.serialization.Serializable +import kotlinx.serialization.* import kotlin.math.ceil @Serializable @@ -10,6 +10,7 @@ data class PaginationResult( val results: List, val objectsCount: Long ) : Pagination { + @EncodeDefault val pagesNumber: Int = ceil(objectsCount / size.toFloat()).toInt() constructor( From 5213a2ff8e4079e04693d2f1c495f97b82e28188 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 26 Jul 2022 14:58:14 +0600 Subject: [PATCH 10/11] add kdocs for pagination --- .../micro_utils/pagination/PaginationResult.kt | 15 ++++++++++++--- .../micro_utils/pagination/SimplePagination.kt | 4 ++++ 2 files changed, 16 insertions(+), 3 deletions(-) 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 96bb73b66b0..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 @@ -3,15 +3,24 @@ package dev.inmo.micro_utils.pagination 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, override val size: Int, val results: List, - val objectsCount: Long + val objectsNumber: Long ) : Pagination { + /** + * Amount of pages for current pagination + */ @EncodeDefault - val pagesNumber: Int = ceil(objectsCount / size.toFloat()).toInt() + val pagesNumber: Int = ceil(objectsNumber / size.toFloat()).toInt() constructor( page: Int, @@ -45,7 +54,7 @@ fun emptyPaginationResult() = PaginationResult(0, 0, emptyList(), 0L) */ fun PaginationResult.changeResultsUnchecked( data: List -): PaginationResult = PaginationResult(page, size, data, objectsCount) +): PaginationResult = PaginationResult(page, size, data, objectsNumber) /** * @return New [PaginationResult] with [data] with checking of data sizes equality */ 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, From 6331f13e9a0436c594c7458a138b4222c449d85d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 26 Jul 2022 14:58:28 +0600 Subject: [PATCH 11/11] actualize changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ad586b1834..5408893777b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 0.11.14 * `Pagination`: - * `PaginationResult` got new field `objectsCount` which by default is a times between `pagesNumber` and `size` + * `PaginationResult` got new field `objectsNumber` which by default is a times between `pagesNumber` and `size` ## 0.11.13