diff --git a/.gradle/7.2/executionHistory/executionHistory.lock b/.gradle/7.2/executionHistory/executionHistory.lock index 85b3cd99..f07bab90 100644 Binary files a/.gradle/7.2/executionHistory/executionHistory.lock and b/.gradle/7.2/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.2/fileHashes/fileHashes.lock b/.gradle/7.2/fileHashes/fileHashes.lock index 6971e8c9..848e86ae 100644 Binary files a/.gradle/7.2/fileHashes/fileHashes.lock and b/.gradle/7.2/fileHashes/fileHashes.lock differ diff --git a/word/src/main/java/com/one/word/data/task/dictionary/envi/WikiEnViDictionaryTask.kt b/word/src/main/java/com/one/word/data/task/dictionary/envi/WikiEnViDictionaryTask.kt index f2e7e410..e49b450c 100644 --- a/word/src/main/java/com/one/word/data/task/dictionary/envi/WikiEnViDictionaryTask.kt +++ b/word/src/main/java/com/one/word/data/task/dictionary/envi/WikiEnViDictionaryTask.kt @@ -2,6 +2,7 @@ package com.one.word.data.task.dictionary.envi import com.one.coreapp.data.usecase.ResultState import com.one.coreapp.data.usecase.toSuccess +import com.one.coreapp.utils.extentions.logException import com.one.word.data.task.dictionary.DictionaryTask import com.one.word.entities.TextLevel import com.one.word.entities.TextLevelType @@ -13,12 +14,19 @@ class WikiEnViDictionaryTask : DictionaryTask { override suspend fun execute(param: DictionaryTask.Param): ResultState> { - return if (param.inputCode != "en" || param.outputCode != "vi") { + if (param.inputCode != "en" || param.outputCode != "vi") { - ResultState.Failed(RuntimeException("Not support")) - } else { + return ResultState.Failed(RuntimeException("Not support")) + } + + return runCatching { handleFromWiki(param.text) + }.getOrElse { + + logException(java.lang.RuntimeException("WikiEnViDictionaryTask", it)) + + ResultState.Failed(it) } } diff --git a/word/src/main/java/com/one/word/data/task/spelling/en/EnSpellingTask.kt b/word/src/main/java/com/one/word/data/task/spelling/en/EnSpellingTask.kt index d95de64a..9bd3988a 100644 --- a/word/src/main/java/com/one/word/data/task/spelling/en/EnSpellingTask.kt +++ b/word/src/main/java/com/one/word/data/task/spelling/en/EnSpellingTask.kt @@ -1,7 +1,7 @@ package com.one.word.data.task.spelling.en -import android.util.Log import com.one.coreapp.data.usecase.ResultState +import com.one.coreapp.utils.extentions.logException import com.one.word.data.task.spelling.SpellingTask import com.one.word.entities.Spelling import org.jsoup.Jsoup @@ -10,12 +10,19 @@ class EnSpellingTask : SpellingTask { override suspend fun execute(param: SpellingTask.Param): ResultState> { - return if (param.inputCode != "en") { + if (param.inputCode != "en") { - ResultState.Failed(RuntimeException("Not support")) - } else { + return ResultState.Failed(RuntimeException("Not support")) + } + + return runCatching { handleFromWiki(param.text) + }.getOrElse { + + logException(java.lang.RuntimeException("EnSpellingTask", it)) + + ResultState.Failed(it) } } @@ -66,7 +73,7 @@ class EnSpellingTask : SpellingTask { } if (text.contains("us", true) && audio != null) { - map["us"]?.audio = "https:" + audio + map["us"]?.audio = "https:$audio" } diff --git a/word/src/main/java/com/one/word/data/usecase/FetchWordDictionaryUseCase.kt b/word/src/main/java/com/one/word/data/usecase/FetchWordDictionaryUseCase.kt index 53e173bf..f0ae8791 100644 --- a/word/src/main/java/com/one/word/data/usecase/FetchWordDictionaryUseCase.kt +++ b/word/src/main/java/com/one/word/data/usecase/FetchWordDictionaryUseCase.kt @@ -3,6 +3,7 @@ package com.one.word.data.usecase import com.one.coreapp.data.usecase.BaseUseCase import com.one.coreapp.data.usecase.ResultState import com.one.coreapp.utils.extentions.executeByFast +import com.one.coreapp.utils.extentions.log import com.one.word.data.task.dictionary.DictionaryTask import com.one.word.entities.TextLevel @@ -13,6 +14,8 @@ class FetchWordDictionaryUseCase( override suspend fun execute(param: Param?): ResultState> { checkNotNull(param) + log("fetch word dictionary use case ${param.inputCode} ${param.outputCode}") + return list.executeByFast(DictionaryTask.Param(param.text, param.inputCode, param.outputCode)) } diff --git a/word/src/main/java/com/one/word/data/usecase/FetchWordSpellingUseCase.kt b/word/src/main/java/com/one/word/data/usecase/FetchWordSpellingUseCase.kt index ce814e78..a09d20f6 100644 --- a/word/src/main/java/com/one/word/data/usecase/FetchWordSpellingUseCase.kt +++ b/word/src/main/java/com/one/word/data/usecase/FetchWordSpellingUseCase.kt @@ -3,6 +3,7 @@ package com.one.word.data.usecase import com.one.coreapp.data.usecase.BaseUseCase import com.one.coreapp.data.usecase.ResultState import com.one.coreapp.utils.extentions.executeByFast +import com.one.coreapp.utils.extentions.log import com.one.word.data.task.spelling.SpellingTask import com.one.word.entities.Spelling @@ -13,6 +14,8 @@ class FetchWordSpellingUseCase( override suspend fun execute(param: Param?): ResultState> { checkNotNull(param) + log("fetch word spelling use case ${param.inputCode}") + return list.executeByFast(SpellingTask.Param(param.text, param.inputCode)) } diff --git a/word/src/main/java/com/one/word/ui/WordDetailViewModel.kt b/word/src/main/java/com/one/word/ui/WordDetailViewModel.kt index 5a544f1f..110586f6 100644 --- a/word/src/main/java/com/one/word/ui/WordDetailViewModel.kt +++ b/word/src/main/java/com/one/word/ui/WordDetailViewModel.kt @@ -30,7 +30,6 @@ import com.one.word.ui.adapters.SpellingViewItem import com.one.word.ui.adapters.TextViewItem import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async -import kotlinx.coroutines.flow.first import kotlinx.coroutines.suspendCancellableCoroutine import java.util.* @@ -96,7 +95,7 @@ class WordDetailViewModel( } val translateAsync = viewModelScope.async(handler + Dispatchers.IO) { - translateUseCase.execute(TranslateUseCase.Param(listOf(text), inputCode, Locale.getDefault().language)).toSuccess()?.data?.first() + translateUseCase.execute(TranslateUseCase.Param(listOf(text), inputCode, Locale.getDefault().language)).toSuccess()?.data?.firstOrNull() } val dictionaryAsync = viewModelScope.async(handler + Dispatchers.IO) {