From 29aecb3b3dcde01ce46efc1205dce773ce11a570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E7=A9=BA?= <70465933+YuKongA@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:51:14 +0800 Subject: [PATCH] android: Set duration for MiuiStringToast --- composeApp/src/androidMain/kotlin/Toast.android.kt | 6 +++--- .../updater/kmp/misc/miuiStringToast/MiuiStringToast.kt | 3 ++- composeApp/src/commonMain/kotlin/Toast.kt | 2 +- composeApp/src/commonMain/kotlin/misc/MessageUtils.kt | 2 +- composeApp/src/desktopMain/kotlin/Toast.desktop.kt | 2 +- composeApp/src/iosMain/kotlin/Toast.ios.kt | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/Toast.android.kt b/composeApp/src/androidMain/kotlin/Toast.android.kt index 507133e..87e9fcf 100644 --- a/composeApp/src/androidMain/kotlin/Toast.android.kt +++ b/composeApp/src/androidMain/kotlin/Toast.android.kt @@ -10,13 +10,13 @@ import top.yukonga.updater.kmp.misc.miuiStringToast.MiuiStringToast private var lastToast: Toast? = null actual fun useToast(): Boolean = true -actual fun showToast(message: String, duration: Int) { +actual fun showToast(message: String, duration: Long) { val context = AndroidAppContext.getApplicationContext() if ((!isMiPad() && isLandscape()) || !atLeast(Build.VERSION_CODES.TIRAMISU) || !isHyperOS()) { lastToast?.cancel() - lastToast = Toast.makeText(context, message, duration).apply { show() } + lastToast = Toast.makeText(context, message, duration.toInt()).apply { show() } } else { - MiuiStringToast.showStringToast(context!!, message) + MiuiStringToast.showStringToast(context!!, message, duration) } } \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/top/yukonga/updater/kmp/misc/miuiStringToast/MiuiStringToast.kt b/composeApp/src/androidMain/kotlin/top/yukonga/updater/kmp/misc/miuiStringToast/MiuiStringToast.kt index 9f1f93c..df14771 100644 --- a/composeApp/src/androidMain/kotlin/top/yukonga/updater/kmp/misc/miuiStringToast/MiuiStringToast.kt +++ b/composeApp/src/androidMain/kotlin/top/yukonga/updater/kmp/misc/miuiStringToast/MiuiStringToast.kt @@ -16,7 +16,7 @@ import top.yukonga.updater.kmp.misc.miuiStringToast.data.TextParams object MiuiStringToast { @RequiresApi(Build.VERSION_CODES.TIRAMISU) @SuppressLint("WrongConstant") - fun showStringToast(context: Context, text: String) { + fun showStringToast(context: Context, text: String, duration: Long) { val textParams = TextParams(text, Color.parseColor("#FFFFFFFF")) val left = Left(textParams = textParams) val iconParams = IconParams(Category.DRAWABLE, FileType.SVG, "ic_app_icon", 1) @@ -26,6 +26,7 @@ object MiuiStringToast { val bundle = StringToastBundle.Builder() .setPackageName("top.yukonga.updater.kmp") .setStrongToastCategory(StrongToastCategory.TEXT_BITMAP) + .setDuration(duration) .setParam(jsonStr) .onCreate() val service = context.getSystemService(Context.STATUS_BAR_SERVICE) diff --git a/composeApp/src/commonMain/kotlin/Toast.kt b/composeApp/src/commonMain/kotlin/Toast.kt index 0dff6ca..d54739f 100644 --- a/composeApp/src/commonMain/kotlin/Toast.kt +++ b/composeApp/src/commonMain/kotlin/Toast.kt @@ -1,2 +1,2 @@ expect fun useToast(): Boolean -expect fun showToast(message: String, duration: Int) \ No newline at end of file +expect fun showToast(message: String, duration: Long) \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/misc/MessageUtils.kt b/composeApp/src/commonMain/kotlin/misc/MessageUtils.kt index 92592b7..ee9675b 100644 --- a/composeApp/src/commonMain/kotlin/misc/MessageUtils.kt +++ b/composeApp/src/commonMain/kotlin/misc/MessageUtils.kt @@ -35,7 +35,7 @@ class MessageUtils { fun showMessage(message: String, duration: Long = 1000L) { if (useToast()) { - showToast(message, duration.toInt()) + showToast(message, duration) } else { snackbarCoroutineJob?.cancel() snackbarMessage.value = message diff --git a/composeApp/src/desktopMain/kotlin/Toast.desktop.kt b/composeApp/src/desktopMain/kotlin/Toast.desktop.kt index 25e1046..de579b7 100644 --- a/composeApp/src/desktopMain/kotlin/Toast.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/Toast.desktop.kt @@ -1,2 +1,2 @@ actual fun useToast(): Boolean = false -actual fun showToast(message: String, duration: Int) {} \ No newline at end of file +actual fun showToast(message: String, duration: Long) {} \ No newline at end of file diff --git a/composeApp/src/iosMain/kotlin/Toast.ios.kt b/composeApp/src/iosMain/kotlin/Toast.ios.kt index 25e1046..de579b7 100644 --- a/composeApp/src/iosMain/kotlin/Toast.ios.kt +++ b/composeApp/src/iosMain/kotlin/Toast.ios.kt @@ -1,2 +1,2 @@ actual fun useToast(): Boolean = false -actual fun showToast(message: String, duration: Int) {} \ No newline at end of file +actual fun showToast(message: String, duration: Long) {} \ No newline at end of file