From 8beaf61a08415c82ad3f204a94b4f112a2ced10f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 2 Dec 2020 16:13:54 +0600 Subject: [PATCH 1/4] start 0.4.9 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbf9adf9703..d7cc1af30e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.4.9 + ## 0.4.8 * `Versions`: diff --git a/gradle.properties b/gradle.properties index daa63b9159d..f73e0a8f482 100644 --- a/gradle.properties +++ b/gradle.properties @@ -40,5 +40,5 @@ dokka_version=1.4.10.2 # Project data group=dev.inmo -version=0.4.8 -android_code_version=12 +version=0.4.9 +android_code_version=13 From 490c318d1c4c2d16c67ffc423ee7d2a68b446cec Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 2 Dec 2020 16:21:31 +0600 Subject: [PATCH 2/4] update ktor --- CHANGELOG.md | 3 +++ defaultAndroidSettings | 2 ++ gradle.properties | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7cc1af30e1..5a5a73e9baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.4.9 +* `Versions`: + * `Ktor`: `1.4.2` -> `1.4.3` + ## 0.4.8 * `Versions`: diff --git a/defaultAndroidSettings b/defaultAndroidSettings index 99e258a1470..79f821a0b49 100644 --- a/defaultAndroidSettings +++ b/defaultAndroidSettings @@ -1,3 +1,5 @@ +apply plugin: 'com.getkeepsafe.dexcount' + android { compileSdkVersion "$android_compileSdkVersion".toInteger() buildToolsVersion "$android_buildToolsVersion" diff --git a/gradle.properties b/gradle.properties index f73e0a8f482..769b1dfb7eb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ kotlin_coroutines_version=1.4.2 kotlin_serialisation_core_version=1.0.1 kotlin_exposed_version=0.28.1 -ktor_version=1.4.2 +ktor_version=1.4.3 klockVersion=2.0.0 @@ -28,7 +28,7 @@ appcompat_version=1.2.0 android_minSdkVersion=19 android_compileSdkVersion=30 android_buildToolsVersion=30.0.2 -dexcount_version=2.0.0-RC1 +dexcount_version=2.0.0 junit_version=4.12 test_ext_junit_version=1.1.2 espresso_core=3.3.0 From 88f2c16c82341f2aced8605a89b95af243c50dd6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 2 Dec 2020 16:25:37 +0600 Subject: [PATCH 3/4] crud exposed realization open fun asObject --- CHANGELOG.md | 3 +++ .../exposed/AbstractExposedWriteCRUDRepo.kt | 22 ++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a5a73e9baf..9628f3c83a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ * `Versions`: * `Ktor`: `1.4.2` -> `1.4.3` +* `Repo` + * `Exposed` + * `asObject` open fun has been added in CRUD realization ## 0.4.8 diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt index 869a8a2c50c..bd4c1265c1e 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt @@ -25,8 +25,10 @@ abstract class AbstractExposedWriteCRUDRepo( override val updatedObjectsFlow: Flow = updateObjectsChannel.asSharedFlow() override val deletedObjectsIdsFlow: Flow = deleteObjectsIdsChannel.asSharedFlow() + @Deprecated("Will be removed in near major update. Override open fun with the same name instead") abstract val InsertStatement.asObject: ObjectType - abstract val selectByIds: SqlExpressionBuilder.(List) -> Op + protected open fun InsertStatement.asObject(value: InputValueType): ObjectType = asObject + abstract val selectByIds: SqlExpressionBuilder.(List) -> Op protected abstract fun insert(value: InputValueType, it: InsertStatement) protected abstract fun update(id: IdType, value: InputValueType, it: UpdateStatement) @@ -34,7 +36,7 @@ abstract class AbstractExposedWriteCRUDRepo( protected open suspend fun onBeforeCreate(value: List) {} private fun createWithoutNotification(value: InputValueType): ObjectType { return transaction(database) { - insert { insert(value, it) }.asObject + insert { insert(value, it) }.asObject(value) } } @@ -42,10 +44,8 @@ abstract class AbstractExposedWriteCRUDRepo( onBeforeCreate(values) return transaction(db = database) { values.map { value -> createWithoutNotification(value) } - }.also { - it.forEach { - newObjectsChannel.emit(it) - } + }.onEach { + newObjectsChannel.emit(it) } } @@ -83,13 +83,9 @@ abstract class AbstractExposedWriteCRUDRepo( return ( transaction(db = database) { values.map { (id, value) -> updateWithoutNotification(id, value) } - }.filter { - it != null - } as List - ).also { - it.forEach { - updateObjectsChannel.emit(it) - } + }.filterNotNull() + ).onEach { + updateObjectsChannel.emit(it) } } protected open suspend fun onBeforeDelete(ids: List) {} From 2d5304a77050849c08ecc481664d26b63f2a9bdb Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 2 Dec 2020 16:38:07 +0600 Subject: [PATCH 4/4] BroadcastChannel -> MutableSharedFlow in repos --- CHANGELOG.md | 2 ++ .../crud/AbstractMutableAndroidCRUDRepo.kt | 24 +++++++++---------- .../repos/keyvalue/KeyValueStore.kt | 17 ++++++------- .../AndroidSQLStandardVersionsRepoProxy.kt | 14 +++++------ .../exposed/AbstractExposedWriteCRUDRepo.kt | 1 - 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9628f3c83a2..4763091a4a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * `Versions`: * `Ktor`: `1.4.2` -> `1.4.3` * `Repo` + * `Common` + * In repos different usages of `BroadcastChannel`s has been replaced with `MutableSharedFlow` * `Exposed` * `asObject` open fun has been added in CRUD realization diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/crud/AbstractMutableAndroidCRUDRepo.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/crud/AbstractMutableAndroidCRUDRepo.kt index 83bab7ad2b9..3da89678146 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/crud/AbstractMutableAndroidCRUDRepo.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/crud/AbstractMutableAndroidCRUDRepo.kt @@ -3,20 +3,18 @@ package dev.inmo.micro_utils.repos.crud import android.content.ContentValues import dev.inmo.micro_utils.common.mapNotNullA import dev.inmo.micro_utils.repos.* -import kotlinx.coroutines.channels.BroadcastChannel -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.asFlow +import kotlinx.coroutines.flow.* abstract class AbstractMutableAndroidCRUDRepo( helper: StandardSQLHelper ) : WriteStandardCRUDRepo, AbstractAndroidCRUDRepo(helper) { - protected val newObjectsChannel = BroadcastChannel(64) - protected val updateObjectsChannel = BroadcastChannel(64) - protected val deleteObjectsIdsChannel = BroadcastChannel(64) - override val newObjectsFlow: Flow = newObjectsChannel.asFlow() - override val updatedObjectsFlow: Flow = updateObjectsChannel.asFlow() - override val deletedObjectsIdsFlow: Flow = deleteObjectsIdsChannel.asFlow() + protected val newObjectsChannel = MutableSharedFlow(64) + protected val updateObjectsChannel = MutableSharedFlow(64) + protected val deleteObjectsIdsChannel = MutableSharedFlow(64) + override val newObjectsFlow: Flow = newObjectsChannel.asSharedFlow() + override val updatedObjectsFlow: Flow = updateObjectsChannel.asSharedFlow() + override val deletedObjectsIdsFlow: Flow = deleteObjectsIdsChannel.asSharedFlow() protected abstract suspend fun InputValueType.asContentValues(id: IdType? = null): ContentValues @@ -42,7 +40,7 @@ abstract class AbstractMutableAndroidCRUDRepo>() @@ -37,11 +34,11 @@ class KeyValueStore internal constructor ( null } - private val onNewValueChannel = BroadcastChannel>(Channel.BUFFERED) - private val onValueRemovedChannel = BroadcastChannel(Channel.BUFFERED) + private val onNewValueChannel = MutableSharedFlow>() + private val onValueRemovedChannel = MutableSharedFlow() - override val onNewValue: Flow> = onNewValueChannel.asFlow() - override val onValueRemoved: Flow = onValueRemovedChannel.asFlow() + override val onNewValue: Flow> = onNewValueChannel.asSharedFlow() + override val onValueRemoved: Flow = onValueRemovedChannel.asSharedFlow() init { cachedData ?.let { @@ -131,7 +128,7 @@ class KeyValueStore internal constructor ( } } toSet.forEach { (k, v) -> - onNewValueChannel.send(k to v) + onNewValueChannel.emit(k to v) } } @@ -139,6 +136,6 @@ class KeyValueStore internal constructor ( sharedPreferences.edit { toUnset.forEach { remove(it) } } - toUnset.forEach { onValueRemovedChannel.send(it) } + toUnset.forEach { onValueRemovedChannel.emit(it) } } } diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/versions/AndroidSQLStandardVersionsRepoProxy.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/versions/AndroidSQLStandardVersionsRepoProxy.kt index d52d9e9ddad..f565147e09b 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/versions/AndroidSQLStandardVersionsRepoProxy.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/versions/AndroidSQLStandardVersionsRepoProxy.kt @@ -32,11 +32,11 @@ class AndroidSQLStandardVersionsRepoProxy( } } - override suspend fun getTableVersion(table: String): Int? = database.writableTransaction { + override suspend fun getTableVersion(tableName: String): Int? = database.writableTransaction { select( - tableName, + this@AndroidSQLStandardVersionsRepoProxy.tableName, selection = "$tableNameColumnName=?", - selectionArgs = arrayOf(table), + selectionArgs = arrayOf(tableName), limit = limitClause(1) ).use { if (it.moveToFirst()) { @@ -47,16 +47,16 @@ class AndroidSQLStandardVersionsRepoProxy( } } - override suspend fun updateTableVersion(table: String, version: Int) { + override suspend fun updateTableVersion(tableName: String, version: Int) { database.writableTransaction { val updated = update( - tableName, + this@AndroidSQLStandardVersionsRepoProxy.tableName, contentValuesOf(tableVersionColumnName to version), "$tableNameColumnName=?", - arrayOf(table) + arrayOf(tableName) ) > 0 if (!updated) { - insert(tableName, null, contentValuesOf(tableNameColumnName to table, tableVersionColumnName to version)) + insert(this@AndroidSQLStandardVersionsRepoProxy.tableName, null, contentValuesOf(tableNameColumnName to tableName, tableVersionColumnName to version)) } } } diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt index bd4c1265c1e..ffbd69f2e5a 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt @@ -2,7 +2,6 @@ package dev.inmo.micro_utils.repos.exposed import dev.inmo.micro_utils.repos.UpdatedValuePair import dev.inmo.micro_utils.repos.WriteStandardCRUDRepo -import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.flow.* import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.statements.InsertStatement