diff --git a/CHANGELOG.md b/CHANGELOG.md index cbf9adf9703..4763091a4a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 0.4.9 + +* `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 + ## 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 daa63b9159d..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 @@ -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 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 869a8a2c50c..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 @@ -25,8 +24,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 +35,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 +43,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 +82,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) {}