mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-28 20:53:03 +02:00
Only shows translations if the result is different than the origin
This commit is contained in:
@@ -38,6 +38,8 @@ import com.vitorpamplona.amethyst.service.lang.LanguageTranslatorService
|
|||||||
import com.vitorpamplona.amethyst.service.lang.ResultOrError
|
import com.vitorpamplona.amethyst.service.lang.ResultOrError
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TranslateableRichTextViewer(
|
fun TranslateableRichTextViewer(
|
||||||
@@ -62,19 +64,21 @@ fun TranslateableRichTextViewer(
|
|||||||
val account = accountState?.account ?: return
|
val account = accountState?.account ?: return
|
||||||
|
|
||||||
LaunchedEffect(accountState) {
|
LaunchedEffect(accountState) {
|
||||||
LanguageTranslatorService.autoTranslate(
|
withContext(Dispatchers.IO) {
|
||||||
content,
|
LanguageTranslatorService.autoTranslate(
|
||||||
account.dontTranslateFrom,
|
content,
|
||||||
account.translateTo
|
account.dontTranslateFrom,
|
||||||
).addOnCompleteListener { task ->
|
account.translateTo
|
||||||
if (task.isSuccessful) {
|
).addOnCompleteListener { task ->
|
||||||
if (task.result.sourceLang != null && task.result.targetLang != null) {
|
if (task.isSuccessful && content != task.result.result) {
|
||||||
val preference = account.preferenceBetween(task.result.sourceLang!!, task.result.targetLang!!)
|
if (task.result.sourceLang != null && task.result.targetLang != null) {
|
||||||
showOriginal = preference == task.result.sourceLang
|
val preference = account.preferenceBetween(task.result.sourceLang!!, task.result.targetLang!!)
|
||||||
|
showOriginal = preference == task.result.sourceLang
|
||||||
|
}
|
||||||
|
translatedTextState.value = task.result
|
||||||
|
} else {
|
||||||
|
translatedTextState.value = ResultOrError(content, null, null, null)
|
||||||
}
|
}
|
||||||
translatedTextState.value = task.result
|
|
||||||
} else {
|
|
||||||
translatedTextState.value = ResultOrError(content, null, null, null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user