diff --git a/CHANGELOG.md b/CHANGELOG.md index 591beb46753..b8ddee40a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.9.20 + +* `Repos`: + * `Common`: + * Fixes in `OneToManyAndroidRepo` + * New `CursorIterator` + ## 0.9.19 * `Versions`: diff --git a/gradle.properties b/gradle.properties index c9570b66ce6..fc33e33ef90 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.9.19 -android_code_version=109 +version=0.9.20 +android_code_version=110 diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginationReversing.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginationReversing.kt index a1b58660f1d..0609369ba25 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginationReversing.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/PaginationReversing.kt @@ -6,7 +6,7 @@ import dev.inmo.micro_utils.pagination.* * Example: * * * `|__f__l_______________________|` will be transformed to `|_______________________f__l__|` - * * `|__f__l_|` will be transformed to `|__f__l_|` + * * `|__f__l_|` will be transformed to `|_f__l__|` * * @return Reversed version of this [Pagination] */ diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/CursorIterator.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/CursorIterator.kt new file mode 100644 index 00000000000..9c7d21fcbcd --- /dev/null +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/CursorIterator.kt @@ -0,0 +1,27 @@ +package dev.inmo.micro_utils.repos + +import android.database.Cursor + +class CursorIterator( + private val c: Cursor +) : Iterator { + private var i = 0 + + init { + c.moveToFirst() + } + override fun hasNext(): Boolean { + return i < c.count + } + + override fun next(): Cursor { + i++ + return if (c.moveToNext()) { + c + } else { + throw NoSuchElementException() + } + } +} + +operator fun Cursor.iterator(): CursorIterator = CursorIterator(this) diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt index 1cc184fc2b4..31abcac4e61 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt @@ -143,7 +143,12 @@ class OneToManyAndroidRepo( }.toLong() override suspend fun count(k: Key): Long = helper.blockingReadableTransaction { - selectDistinct(tableName, columns = valueColumnArray, selection = "$idColumnName=?", selectionArgs = arrayOf(k.keyAsString()), limit = FirstPagePagination(1).limitClause()).use { + selectDistinct( + tableName, + columns = valueColumnArray, + selection = "$idColumnName=?", + selectionArgs = arrayOf(k.keyAsString()) + ).use { it.count } }.toLong()