mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-21 20:41:56 +02:00
v0.77.1
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
|||||||
applicationId "com.vitorpamplona.amethyst"
|
applicationId "com.vitorpamplona.amethyst"
|
||||||
minSdk 26
|
minSdk 26
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 297
|
versionCode 298
|
||||||
versionName "0.77.0"
|
versionName "0.77.1"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables {
|
vectorDrawables {
|
||||||
|
@@ -26,9 +26,7 @@ import com.vitorpamplona.amethyst.service.Nip11Retriever
|
|||||||
import com.vitorpamplona.amethyst.service.OnlineChecker
|
import com.vitorpamplona.amethyst.service.OnlineChecker
|
||||||
import com.vitorpamplona.amethyst.service.ZapPaymentHandler
|
import com.vitorpamplona.amethyst.service.ZapPaymentHandler
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.amethyst.service.lang.LanguageTranslatorService
|
|
||||||
import com.vitorpamplona.amethyst.ui.actions.Dao
|
import com.vitorpamplona.amethyst.ui.actions.Dao
|
||||||
import com.vitorpamplona.amethyst.ui.components.TranslationConfig
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.UrlPreviewState
|
import com.vitorpamplona.amethyst.ui.components.UrlPreviewState
|
||||||
import com.vitorpamplona.amethyst.ui.note.ZapAmountCommentNotification
|
import com.vitorpamplona.amethyst.ui.note.ZapAmountCommentNotification
|
||||||
import com.vitorpamplona.amethyst.ui.note.ZapraiserStatus
|
import com.vitorpamplona.amethyst.ui.note.ZapraiserStatus
|
||||||
@@ -566,27 +564,9 @@ class AccountViewModel(val account: Account) : ViewModel(), Dao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun translate(content: String, onTranslated: (TranslationConfig) -> Unit) {
|
fun runOnIO(runOnIO: () -> Unit) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
LanguageTranslatorService.autoTranslate(
|
runOnIO()
|
||||||
content,
|
|
||||||
account.dontTranslateFrom,
|
|
||||||
account.translateTo
|
|
||||||
).addOnCompleteListener { task ->
|
|
||||||
if (task.isSuccessful && !content.equals(task.result.result, true)) {
|
|
||||||
if (task.result.sourceLang != null && task.result.targetLang != null) {
|
|
||||||
val preference = account.preferenceBetween(task.result.sourceLang!!, task.result.targetLang!!)
|
|
||||||
val newConfig = TranslationConfig(
|
|
||||||
result = task.result.result,
|
|
||||||
sourceLang = task.result.sourceLang,
|
|
||||||
targetLang = task.result.targetLang,
|
|
||||||
showOriginal = preference == task.result.sourceLang
|
|
||||||
)
|
|
||||||
|
|
||||||
onTranslated(newConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@ import androidx.compose.ui.text.withStyle
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.os.ConfigurationCompat
|
import androidx.core.os.ConfigurationCompat
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
|
import com.vitorpamplona.amethyst.service.lang.LanguageTranslatorService
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.lessImportantLink
|
import com.vitorpamplona.amethyst.ui.theme.lessImportantLink
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
@@ -304,6 +305,26 @@ fun TranslateAndWatchLanguageChanges(content: String, accountViewModel: AccountV
|
|||||||
val accountState by accountViewModel.accountLanguagesLiveData.observeAsState()
|
val accountState by accountViewModel.accountLanguagesLiveData.observeAsState()
|
||||||
|
|
||||||
LaunchedEffect(accountState) {
|
LaunchedEffect(accountState) {
|
||||||
accountViewModel.translate(content, onTranslated)
|
accountViewModel.runOnIO {
|
||||||
|
LanguageTranslatorService.autoTranslate(
|
||||||
|
content,
|
||||||
|
accountViewModel.account.dontTranslateFrom,
|
||||||
|
accountViewModel.account.translateTo
|
||||||
|
).addOnCompleteListener { task ->
|
||||||
|
if (task.isSuccessful && !content.equals(task.result.result, true)) {
|
||||||
|
if (task.result.sourceLang != null && task.result.targetLang != null) {
|
||||||
|
val preference = accountViewModel.account.preferenceBetween(task.result.sourceLang!!, task.result.targetLang!!)
|
||||||
|
val newConfig = TranslationConfig(
|
||||||
|
result = task.result.result,
|
||||||
|
sourceLang = task.result.sourceLang,
|
||||||
|
targetLang = task.result.targetLang,
|
||||||
|
showOriginal = preference == task.result.sourceLang
|
||||||
|
)
|
||||||
|
|
||||||
|
onTranslated(newConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user