From b90cab318e9b563818d2e5d2ecd4e76c38934a70 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 5 Jun 2021 20:12:41 +0600 Subject: [PATCH 1/6] start 0.5.7 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9120f045a2d..74f029becb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.5.7 + ## 0.5.6 * `Versions` diff --git a/gradle.properties b/gradle.properties index 5d03522015e..70bf502ed43 100644 --- a/gradle.properties +++ b/gradle.properties @@ -45,5 +45,5 @@ dokka_version=1.4.32 # Project data group=dev.inmo -version=0.5.6 -android_code_version=47 +version=0.5.7 +android_code_version=48 From e0d5eb45b72a4758a4da18c61acf7965626ea785 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 5 Jun 2021 20:29:59 +0600 Subject: [PATCH 2/6] separate cache repos to read and read/write --- CHANGELOG.md | 4 +++ .../micro_utils/repos/cache/CRUDCacheRepo.kt | 26 +++++++++++++------ .../repos/cache/KeyValueCacheRepo.kt | 19 +++++++++----- .../repos/cache/KeyValuesCacheRepo.kt | 23 +++++++++------- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74f029becb4..ec5d940a2b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.5.7 +* `Repos` + * `Cache` + * All standard cache repos have been separated to read and read/write repos + ## 0.5.6 * `Versions` diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt index 22ffbb489c9..13289e997e3 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt @@ -6,19 +6,29 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -open class CRUDCacheRepo( - protected val parentRepo: CRUDRepo, +open class ReadCRUDCacheRepo( + protected val parentRepo: ReadCRUDRepo, protected val kvCache: KVCache, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default), protected val idGetter: (ObjectType) -> IdType -) : CRUDRepo by parentRepo { - protected val onNewJob = parentRepo.newObjectsFlow.onEach { kvCache.set(idGetter(it), it) }.launchIn(scope) - protected val onUpdatedJob = parentRepo.updatedObjectsFlow.onEach { kvCache.set(idGetter(it), it) }.launchIn(scope) - protected val onRemoveJob = parentRepo.deletedObjectsIdsFlow.onEach { kvCache.unset(it) }.launchIn(scope) - +) : ReadCRUDRepo by parentRepo { override suspend fun getById(id: IdType): ObjectType? = kvCache.get(id) ?: (parentRepo.getById(id) ?.also { kvCache.set(id, it) }) override suspend fun contains(id: IdType): Boolean = kvCache.contains(id) || parentRepo.contains(id) } + +open class CRUDCacheRepo( + parentRepo: CRUDRepo, + kvCache: KVCache, + scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + idGetter: (ObjectType) -> IdType +) : ReadCRUDCacheRepo( + parentRepo, + kvCache, + idGetter +), CRUDRepo, WriteCRUDRepo by parentRepo { + protected val onNewJob = parentRepo.newObjectsFlow.onEach { kvCache.set(idGetter(it), it) }.launchIn(scope) + protected val onUpdatedJob = parentRepo.updatedObjectsFlow.onEach { kvCache.set(idGetter(it), it) }.launchIn(scope) + protected val onRemoveJob = parentRepo.deletedObjectsIdsFlow.onEach { kvCache.unset(it) }.launchIn(scope) +} diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt index 86d865afe03..ad1e24ab696 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt @@ -7,14 +7,19 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -open class KeyValueCacheRepo( - protected val parentRepo: KeyValueRepo, +open class ReadKeyValueCacheRepo( + protected val parentRepo: ReadKeyValueRepo, protected val kvCache: KVCache, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default) -) : KeyValueRepo by parentRepo { - protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, it.second) }.launchIn(scope) - protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.unset(it) }.launchIn(scope) - +) : ReadKeyValueRepo by parentRepo { override suspend fun get(k: Key): Value? = kvCache.get(k) ?: parentRepo.get(k) ?.also { kvCache.set(k, it) } override suspend fun contains(key: Key): Boolean = kvCache.contains(key) || parentRepo.contains(key) } + +open class KeyValueCacheRepo( + parentRepo: KeyValueRepo, + kvCache: KVCache, + scope: CoroutineScope = CoroutineScope(Dispatchers.Default) +) : ReadKeyValueCacheRepo(parentRepo, kvCache), KeyValueRepo, WriteKeyValueRepo by parentRepo { + protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, it.second) }.launchIn(scope) + protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.unset(it) }.launchIn(scope) +} diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt index 26b12af4fd2..ff2b36fbf01 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt @@ -11,15 +11,10 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -open class KeyValuesCacheRepo( - protected val parentRepo: KeyValuesRepo, - protected val kvCache: KVCache>, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default) -) : KeyValuesRepo by parentRepo { - protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.plus(it.second) ?: listOf(it.second)) }.launchIn(scope) - protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.minus(it.second) ?: return@onEach) }.launchIn(scope) - protected val onDataClearedJob = parentRepo.onDataCleared.onEach { kvCache.unset(it) }.launchIn(scope) - +open class ReadKeyValuesCacheRepo( + protected val parentRepo: ReadKeyValuesRepo, + protected val kvCache: KVCache> +) : ReadKeyValuesRepo by parentRepo { override suspend fun get(k: Key, pagination: Pagination, reversed: Boolean): PaginationResult { return kvCache.get(k) ?.paginate( pagination.let { if (reversed) it.reverse(count(k)) else it } @@ -35,3 +30,13 @@ open class KeyValuesCacheRepo( override suspend fun contains(k: Key, v: Value): Boolean = kvCache.get(k) ?.contains(v) ?: parentRepo.contains(k, v) override suspend fun contains(k: Key): Boolean = kvCache.contains(k) || parentRepo.contains(k) } + +open class KeyValuesCacheRepo( + parentRepo: KeyValuesRepo, + kvCache: KVCache>, + scope: CoroutineScope = CoroutineScope(Dispatchers.Default) +) : ReadKeyValuesCacheRepo(parentRepo, kvCache), KeyValuesRepo, WriteKeyValuesRepo by parentRepo { + protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.plus(it.second) ?: listOf(it.second)) }.launchIn(scope) + protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.minus(it.second) ?: return@onEach) }.launchIn(scope) + protected val onDataClearedJob = parentRepo.onDataCleared.onEach { kvCache.unset(it) }.launchIn(scope) +} From 04a95867e2e08bf78984592805caf4693716c88a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Jun 2021 01:46:33 +0600 Subject: [PATCH 3/6] fixes --- CHANGELOG.md | 8 ++++++ .../alerts/common/ProgressBarAlertDialog.kt | 27 +++++++++++++++++++ .../res/layout/alert_dialog_progress_bar.xml | 20 ++++++++++++++ .../pagination/ServerPaginationHelpers.kt | 4 +-- 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt create mode 100644 android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index ec5d940a2b3..25859e1bb38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## 0.5.7 +* `Android` + * `Alerts` + * `Common` + * New extension `progressBarAlertDialog` +* `Pagination` + * `Ktor` + * `Server` + * Fixes in extension `extractPagination` * `Repos` * `Cache` * All standard cache repos have been separated to read and read/write repos diff --git a/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt b/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt new file mode 100644 index 00000000000..990a7e58f26 --- /dev/null +++ b/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt @@ -0,0 +1,27 @@ +package dev.inmo.micro_utils.android.alerts.common + +import android.content.Context +import android.view.LayoutInflater +import android.widget.TextView +import androidx.annotation.StringRes + +fun Context.createProgressBarAlertDialog( + text: String? = null, + onClick: (() -> Unit)? = null +) = createCustomViewAlertDialog { + (it.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater).inflate( + R.layout.alert_dialog_progress_bar, null, false + ).apply { + onClick ?.let { + setOnClickListener { onClick() } + } ?: setOnClickListener { /* do nothing */ } + text ?.let { + findViewById(R.id.alertDialogProgressBarTitle).text = it + } + } +} + +fun Context.createProgressBarAlertDialog( + @StringRes textRes: Int, + onClick: (() -> Unit)? = null +) = createProgressBarAlertDialog(getString(textRes), onClick) diff --git a/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml b/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml new file mode 100644 index 00000000000..b9a1476bf94 --- /dev/null +++ b/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml @@ -0,0 +1,20 @@ + + + + + + + + diff --git a/pagination/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/pagination/ServerPaginationHelpers.kt b/pagination/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/pagination/ServerPaginationHelpers.kt index 744cc4e39dc..7c68d913a5a 100644 --- a/pagination/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/pagination/ServerPaginationHelpers.kt +++ b/pagination/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/pagination/ServerPaginationHelpers.kt @@ -5,8 +5,8 @@ import io.ktor.http.Parameters val Parameters.extractPagination: Pagination get() = SimplePagination( - get("page") ?.toIntOrNull() ?: 0, - get("size") ?.toIntOrNull() ?: defaultPaginationPageSize + get(paginationPageKey) ?.toIntOrNull() ?: 0, + get(paginationSizeKey) ?.toIntOrNull() ?: defaultPaginationPageSize ) val ApplicationCall.extractPagination: Pagination From 597e14bc7e652a696f33b6090fc6c5de0ffe3175 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Jun 2021 02:04:21 +0600 Subject: [PATCH 4/6] fix of alert dialog with progress bar background --- .../common/src/main/res/layout/alert_dialog_progress_bar.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml b/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml index b9a1476bf94..734ff777c3b 100644 --- a/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml +++ b/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml @@ -4,7 +4,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - android:gravity="center"> + android:gravity="center" + android:background="@android:color/transparent"> Date: Sun, 6 Jun 2021 02:10:48 +0600 Subject: [PATCH 5/6] upfix --- .../android/alerts/common/ProgressBarAlertDialog.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt b/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt index 990a7e58f26..d844a0d1cab 100644 --- a/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt +++ b/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt @@ -1,6 +1,8 @@ package dev.inmo.micro_utils.android.alerts.common import android.content.Context +import android.graphics.Color +import android.graphics.drawable.ColorDrawable import android.view.LayoutInflater import android.widget.TextView import androidx.annotation.StringRes @@ -19,6 +21,10 @@ fun Context.createProgressBarAlertDialog( findViewById(R.id.alertDialogProgressBarTitle).text = it } } +}.apply { + window ?.apply { + setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) + } } fun Context.createProgressBarAlertDialog( From af78f01682a797e4880964524bc42ddab941104a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Jun 2021 10:43:42 +0600 Subject: [PATCH 6/6] remove progressbar alert dialog --- CHANGELOG.md | 4 --- .../alerts/common/ProgressBarAlertDialog.kt | 33 ------------------- .../res/layout/alert_dialog_progress_bar.xml | 21 ------------ 3 files changed, 58 deletions(-) delete mode 100644 android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt delete mode 100644 android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 25859e1bb38..3c9c34c0ed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,6 @@ ## 0.5.7 -* `Android` - * `Alerts` - * `Common` - * New extension `progressBarAlertDialog` * `Pagination` * `Ktor` * `Server` diff --git a/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt b/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt deleted file mode 100644 index d844a0d1cab..00000000000 --- a/android/alerts/common/src/main/kotlin/dev/inmo/micro_utils/android/alerts/common/ProgressBarAlertDialog.kt +++ /dev/null @@ -1,33 +0,0 @@ -package dev.inmo.micro_utils.android.alerts.common - -import android.content.Context -import android.graphics.Color -import android.graphics.drawable.ColorDrawable -import android.view.LayoutInflater -import android.widget.TextView -import androidx.annotation.StringRes - -fun Context.createProgressBarAlertDialog( - text: String? = null, - onClick: (() -> Unit)? = null -) = createCustomViewAlertDialog { - (it.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater).inflate( - R.layout.alert_dialog_progress_bar, null, false - ).apply { - onClick ?.let { - setOnClickListener { onClick() } - } ?: setOnClickListener { /* do nothing */ } - text ?.let { - findViewById(R.id.alertDialogProgressBarTitle).text = it - } - } -}.apply { - window ?.apply { - setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) - } -} - -fun Context.createProgressBarAlertDialog( - @StringRes textRes: Int, - onClick: (() -> Unit)? = null -) = createProgressBarAlertDialog(getString(textRes), onClick) diff --git a/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml b/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml deleted file mode 100644 index 734ff777c3b..00000000000 --- a/android/alerts/common/src/main/res/layout/alert_dialog_progress_bar.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - -