From 2afa0d1f98f3b3b623d37ef20b146e54d386a2ff Mon Sep 17 00:00:00 2001 From: DatLag Date: Thu, 11 Jul 2024 16:10:20 +0200 Subject: [PATCH] fix translation crash --- .../component/TranslateButton.android.kt | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/TranslateButton.android.kt b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/TranslateButton.android.kt index cfc97b5..d7ad5ef 100644 --- a/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/TranslateButton.android.kt +++ b/composeApp/src/androidMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/TranslateButton.android.kt @@ -86,21 +86,23 @@ actual fun TranslateButton( progress = false enabled = false }.addOnSuccessListener { - englishLocaleTranslator - .translate(text) - .addOnFailureListener { - progress = false - enabled = true + scopeCatching { + englishLocaleTranslator + .translate(text) + .addOnFailureListener { + progress = false + enabled = true - translated = false - onTranslation(null) - }.addOnSuccessListener { - progress = false - enabled = true + translated = false + onTranslation(null) + }.addOnSuccessListener { + progress = false + enabled = true - translated = true - onTranslation(it) - } + translated = true + onTranslation(it) + } + }.getOrNull() } }.getOrNull() }