From 27186059870765b169d0e1e9a5e5c8fe86efbbd6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Dec 2024 22:24:03 +0600 Subject: [PATCH 1/4] start 0.24.0 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80b426c541b..cbdc514e88e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.24.0 + ## 0.23.2 * `Versions`: diff --git a/gradle.properties b/gradle.properties index 61af5fa3836..7a023ced23f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,5 +15,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.23.2 -android_code_version=278 +version=0.24.0 +android_code_version=279 From e8273ab80cff49f43206554ce7aa4cf1bc14114b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Dec 2024 22:34:28 +0600 Subject: [PATCH 2/4] Progress -> Percentage --- CHANGELOG.md | 4 + .../common/{Progress.kt => Percentage.kt} | 13 +-- .../common/PercentageOperations.kt | 80 +++++++++++++++++++ .../micro_utils/common/ProgressOperations.kt | 80 ------------------- .../micro_utils/common/PercentageTests.kt | 29 +++++++ 5 files changed, 121 insertions(+), 85 deletions(-) rename common/src/commonMain/kotlin/dev/inmo/micro_utils/common/{Progress.kt => Percentage.kt} (60%) create mode 100644 common/src/commonMain/kotlin/dev/inmo/micro_utils/common/PercentageOperations.kt delete mode 100644 common/src/commonMain/kotlin/dev/inmo/micro_utils/common/ProgressOperations.kt create mode 100644 common/src/commonTest/kotlin/dev/inmo/micro_utils/common/PercentageTests.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index cbdc514e88e..838d5fa1a6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.24.0 +* `Common`: + * Rename `Progress` to more common `Percentage`. `Progress` now is typealias + * Fix of `Progress.compareTo` extension + ## 0.23.2 * `Versions`: diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Progress.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Percentage.kt similarity index 60% rename from common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Progress.kt rename to common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Percentage.kt index dbce92508f0..607ac9b2b33 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Progress.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Percentage.kt @@ -5,7 +5,7 @@ import kotlin.jvm.JvmInline @Serializable @JvmInline -value class Progress private constructor( +value class Percentage private constructor( val of1: Double ) { val of1Float @@ -26,12 +26,15 @@ value class Progress private constructor( companion object { val rangeOfValues = 0.0 .. 1.0 - val START = Progress(rangeOfValues.start) - val COMPLETED = Progress(rangeOfValues.endInclusive) + val START = Percentage(rangeOfValues.start) + val COMPLETED = Percentage(rangeOfValues.endInclusive) - operator fun invoke(of1: Double) = Progress(of1.coerceIn(rangeOfValues)) - operator fun invoke(part: Number, total: Number) = Progress( + operator fun invoke(of1: Double) = Percentage(of1.coerceIn(rangeOfValues)) + operator fun invoke(part: Number, total: Number) = Percentage( part.toDouble() / total.toDouble() ) + fun of100(of100: Double) = Percentage(of1 = of100 / 100) } } + +typealias Progress = Percentage diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/PercentageOperations.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/PercentageOperations.kt new file mode 100644 index 00000000000..f12051aa371 --- /dev/null +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/PercentageOperations.kt @@ -0,0 +1,80 @@ +@file:Suppress( + "RemoveRedundantCallsOfConversionMethods", + "RedundantVisibilityModifier", +) + +package dev.inmo.micro_utils.common + +import kotlin.Byte +import kotlin.Double +import kotlin.Float +import kotlin.Int +import kotlin.Long +import kotlin.Short +import kotlin.Suppress + +public operator fun Percentage.plus(other: Percentage): Percentage = Percentage(of1 + other.of1) + +public operator fun Percentage.minus(other: Percentage): Percentage = Percentage(of1 - other.of1) + +public operator fun Percentage.plus(i: Byte): Percentage = Percentage((of1 + i).toDouble()) + +public operator fun Percentage.minus(i: Byte): Percentage = Percentage((of1 - i).toDouble()) + +public operator fun Percentage.times(i: Byte): Percentage = Percentage((of1 * i).toDouble()) + +public operator fun Percentage.div(i: Byte): Percentage = Percentage((of1 / i).toDouble()) + +public operator fun Percentage.rem(i: Byte): Percentage = Percentage((of1 % i).toDouble()) + +public operator fun Percentage.plus(i: Short): Percentage = Percentage((of1 + i).toDouble()) + +public operator fun Percentage.minus(i: Short): Percentage = Percentage((of1 - i).toDouble()) + +public operator fun Percentage.times(i: Short): Percentage = Percentage((of1 * i).toDouble()) + +public operator fun Percentage.div(i: Short): Percentage = Percentage((of1 / i).toDouble()) + +public operator fun Percentage.rem(i: Short): Percentage = Percentage((of1 % i).toDouble()) + +public operator fun Percentage.plus(i: Int): Percentage = Percentage((of1 + i).toDouble()) + +public operator fun Percentage.minus(i: Int): Percentage = Percentage((of1 - i).toDouble()) + +public operator fun Percentage.times(i: Int): Percentage = Percentage((of1 * i).toDouble()) + +public operator fun Percentage.div(i: Int): Percentage = Percentage((of1 / i).toDouble()) + +public operator fun Percentage.rem(i: Int): Percentage = Percentage((of1 % i).toDouble()) + +public operator fun Percentage.plus(i: Long): Percentage = Percentage((of1 + i).toDouble()) + +public operator fun Percentage.minus(i: Long): Percentage = Percentage((of1 - i).toDouble()) + +public operator fun Percentage.times(i: Long): Percentage = Percentage((of1 * i).toDouble()) + +public operator fun Percentage.div(i: Long): Percentage = Percentage((of1 / i).toDouble()) + +public operator fun Percentage.rem(i: Long): Percentage = Percentage((of1 % i).toDouble()) + +public operator fun Percentage.plus(i: Float): Percentage = Percentage((of1 + i).toDouble()) + +public operator fun Percentage.minus(i: Float): Percentage = Percentage((of1 - i).toDouble()) + +public operator fun Percentage.times(i: Float): Percentage = Percentage((of1 * i).toDouble()) + +public operator fun Percentage.div(i: Float): Percentage = Percentage((of1 / i).toDouble()) + +public operator fun Percentage.rem(i: Float): Percentage = Percentage((of1 % i).toDouble()) + +public operator fun Percentage.plus(i: Double): Percentage = Percentage((of1 + i).toDouble()) + +public operator fun Percentage.minus(i: Double): Percentage = Percentage((of1 - i).toDouble()) + +public operator fun Percentage.times(i: Double): Percentage = Percentage((of1 * i).toDouble()) + +public operator fun Percentage.div(i: Double): Percentage = Percentage((of1 / i).toDouble()) + +public operator fun Percentage.rem(i: Double): Percentage = Percentage((of1 % i).toDouble()) + +public operator fun Percentage.compareTo(other: Percentage): Int = (of1.compareTo(other.of1)) diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/ProgressOperations.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/ProgressOperations.kt deleted file mode 100644 index 0d71c3325cc..00000000000 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/ProgressOperations.kt +++ /dev/null @@ -1,80 +0,0 @@ -@file:Suppress( - "RemoveRedundantCallsOfConversionMethods", - "RedundantVisibilityModifier", -) - -package dev.inmo.micro_utils.common - -import kotlin.Byte -import kotlin.Double -import kotlin.Float -import kotlin.Int -import kotlin.Long -import kotlin.Short -import kotlin.Suppress - -public operator fun Progress.plus(other: Progress): Progress = Progress(of1 + other.of1) - -public operator fun Progress.minus(other: Progress): Progress = Progress(of1 - other.of1) - -public operator fun Progress.plus(i: Byte): Progress = Progress((of1 + i).toDouble()) - -public operator fun Progress.minus(i: Byte): Progress = Progress((of1 - i).toDouble()) - -public operator fun Progress.times(i: Byte): Progress = Progress((of1 * i).toDouble()) - -public operator fun Progress.div(i: Byte): Progress = Progress((of1 / i).toDouble()) - -public operator fun Progress.rem(i: Byte): Progress = Progress((of1 % i).toDouble()) - -public operator fun Progress.plus(i: Short): Progress = Progress((of1 + i).toDouble()) - -public operator fun Progress.minus(i: Short): Progress = Progress((of1 - i).toDouble()) - -public operator fun Progress.times(i: Short): Progress = Progress((of1 * i).toDouble()) - -public operator fun Progress.div(i: Short): Progress = Progress((of1 / i).toDouble()) - -public operator fun Progress.rem(i: Short): Progress = Progress((of1 % i).toDouble()) - -public operator fun Progress.plus(i: Int): Progress = Progress((of1 + i).toDouble()) - -public operator fun Progress.minus(i: Int): Progress = Progress((of1 - i).toDouble()) - -public operator fun Progress.times(i: Int): Progress = Progress((of1 * i).toDouble()) - -public operator fun Progress.div(i: Int): Progress = Progress((of1 / i).toDouble()) - -public operator fun Progress.rem(i: Int): Progress = Progress((of1 % i).toDouble()) - -public operator fun Progress.plus(i: Long): Progress = Progress((of1 + i).toDouble()) - -public operator fun Progress.minus(i: Long): Progress = Progress((of1 - i).toDouble()) - -public operator fun Progress.times(i: Long): Progress = Progress((of1 * i).toDouble()) - -public operator fun Progress.div(i: Long): Progress = Progress((of1 / i).toDouble()) - -public operator fun Progress.rem(i: Long): Progress = Progress((of1 % i).toDouble()) - -public operator fun Progress.plus(i: Float): Progress = Progress((of1 + i).toDouble()) - -public operator fun Progress.minus(i: Float): Progress = Progress((of1 - i).toDouble()) - -public operator fun Progress.times(i: Float): Progress = Progress((of1 * i).toDouble()) - -public operator fun Progress.div(i: Float): Progress = Progress((of1 / i).toDouble()) - -public operator fun Progress.rem(i: Float): Progress = Progress((of1 % i).toDouble()) - -public operator fun Progress.plus(i: Double): Progress = Progress((of1 + i).toDouble()) - -public operator fun Progress.minus(i: Double): Progress = Progress((of1 - i).toDouble()) - -public operator fun Progress.times(i: Double): Progress = Progress((of1 * i).toDouble()) - -public operator fun Progress.div(i: Double): Progress = Progress((of1 / i).toDouble()) - -public operator fun Progress.rem(i: Double): Progress = Progress((of1 % i).toDouble()) - -public operator fun Progress.compareTo(other: Progress): Int = (of1 - other.of1).toInt() diff --git a/common/src/commonTest/kotlin/dev/inmo/micro_utils/common/PercentageTests.kt b/common/src/commonTest/kotlin/dev/inmo/micro_utils/common/PercentageTests.kt new file mode 100644 index 00000000000..f3ec98ebb89 --- /dev/null +++ b/common/src/commonTest/kotlin/dev/inmo/micro_utils/common/PercentageTests.kt @@ -0,0 +1,29 @@ +package dev.inmo.micro_utils.common + +import kotlin.test.Test +import kotlin.test.assertEquals + +class PercentageTests { + @Test + fun testCompareTo() { + val step = 0.01 + + var i = Percentage.START.of1 + while (i <= Percentage.COMPLETED.of1) { + val percentageI = Percentage(i) + + var j = Percentage.START.of1 + while (j <= Percentage.COMPLETED.of1) { + val percentageJ = Percentage(j) + + assertEquals(percentageI.of1.compareTo(percentageJ.of1), percentageI.compareTo(percentageJ)) + assertEquals(percentageI.of1 > percentageJ.of1, percentageI > percentageJ) + assertEquals(percentageI.of1 < percentageJ.of1, percentageI < percentageJ) + + j += step + } + + i += step + } + } +} \ No newline at end of file From 8718c5e3104b92c95a771d8b3c8e9600ef73ba5a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 21 Dec 2024 09:02:31 +0600 Subject: [PATCH 3/4] update dependencies and add kdocs for percentage --- CHANGELOG.md | 5 ++ .../dev/inmo/micro_utils/common/Percentage.kt | 48 ++++++++++++++++--- gradle/libs.versions.toml | 8 ++-- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 838d5fa1a6b..64e1e21a4b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## 0.24.0 +* `Versions`: + * `Coroutines`: `1.9.0` -> `1.10.1` + * `KSLog`: `1.3.6` -> `1.4.0` + * `Compose`: `1.7.1` -> `1.7.3` + * `Ktor`: `3.0.2` -> `3.0.3` * `Common`: * Rename `Progress` to more common `Percentage`. `Progress` now is typealias * Fix of `Progress.compareTo` extension diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Percentage.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Percentage.kt index 607ac9b2b33..5fe8f035faf 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Percentage.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Percentage.kt @@ -3,26 +3,45 @@ package dev.inmo.micro_utils.common import kotlinx.serialization.Serializable import kotlin.jvm.JvmInline +/** + * Contains [of1] as main value, where 100% of percentage is when of1 == 1 + * + * @see invoke + * @see partOfTotal + * @see of100 + */ @Serializable @JvmInline value class Percentage private constructor( + /** + * Value of percentage. When it equals to 1, means 100% + */ val of1: Double ) { + /** + * Same as [of1], but float (using [Double.toFloat]) + */ val of1Float get() = of1.toFloat() + + /** + * Represent this percentage as common percentage where 100% is 100% + */ val of100 get() = of1 * 100 + + /** + * Same as [of100], but float (using [Double.toFloat]) + */ val of100Float get() = of100.toFloat() + + /** + * Same as [of100], but int (using [Double.toInt]) + */ val of100Int get() = of100.toInt() - init { - require(of1 in rangeOfValues) { - "Progress main value should be in $rangeOfValues, but incoming value is $of1" - } - } - companion object { val rangeOfValues = 0.0 .. 1.0 @@ -33,8 +52,25 @@ value class Percentage private constructor( operator fun invoke(part: Number, total: Number) = Percentage( part.toDouble() / total.toDouble() ) + fun of1(of1: Double) = Percentage(of1 = of1) fun of100(of100: Double) = Percentage(of1 = of100 / 100) + fun partOfTotal(part: Number, total: Number) = Percentage(part = part, total = total) } } typealias Progress = Percentage + +/** + * Will return [this] [Progress] if [Percentage.of1] in `0 .. 1` range + */ +fun Progress.ensureStrictOrNull(): Progress? = if (of1 in Percentage.rangeOfValues) this else null +/** + * Will return [this] [Progress] if [Percentage.of1] in `0 .. 1` range. Otherwise, will throw error + * [IllegalArgumentException] due to [require] failure + */ +fun Progress.ensureStrictOrThrow(): Progress { + require(of1 in Percentage.rangeOfValues) { + "For strict checks value of percentage must be in ${Percentage.rangeOfValues}, but actual value is $of1" + } + return this +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5c0cb6139cb..8d2b8087ac9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,11 +2,11 @@ kt = "2.1.0" kt-serialization = "1.7.3" -kt-coroutines = "1.9.0" +kt-coroutines = "1.10.1" -kslog = "1.3.6" +kslog = "1.4.0" -jb-compose = "1.7.1" +jb-compose = "1.7.3" jb-exposed = "0.57.0" jb-dokka = "1.9.20" @@ -15,7 +15,7 @@ sqlite = "3.47.1.0" korlibs = "5.4.0" uuid = "0.8.4" -ktor = "3.0.2" +ktor = "3.0.3" gh-release = "2.5.2" From d62f67bd887132120822d47e9d1c4bcb1cb4c70b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 21 Dec 2024 09:13:10 +0600 Subject: [PATCH 4/4] update dokka --- 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 8d2b8087ac9..2a587b27321 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,7 +8,7 @@ kslog = "1.4.0" jb-compose = "1.7.3" jb-exposed = "0.57.0" -jb-dokka = "1.9.20" +jb-dokka = "2.0.0" sqlite = "3.47.1.0"