diff --git a/app/src/main/java/com/bnyro/translate/api/lv/LVEngine.kt b/app/src/main/java/com/bnyro/translate/api/lv/LVEngine.kt index 9fdaf4195..ea747e0ec 100644 --- a/app/src/main/java/com/bnyro/translate/api/lv/LVEngine.kt +++ b/app/src/main/java/com/bnyro/translate/api/lv/LVEngine.kt @@ -1,7 +1,7 @@ package com.bnyro.translate.api.lv -import android.util.Log import com.bnyro.translate.const.ApiKeyState +import com.bnyro.translate.ext.expOrNull import com.bnyro.translate.obj.Definition import com.bnyro.translate.obj.Language import com.bnyro.translate.obj.Translation @@ -37,35 +37,20 @@ class LVEngine : TranslationEngine( target, URLHelper.encodeURL(query) ) - val x = Translation( + return Translation( translatedText = URLHelper.decodeURL(response.translation), detectedLanguage = response.info?.detectedSource, examples = response.info?.examples, similar = response.info?.similar, definitions = response.info?.definitions ?.map { - val def = Definition( + Definition( type = it.type, - definition = try { - it.list.first().definition - } catch (e: Exception) { - null - }, - example = try { - it.list.first().example - } catch (e: Exception) { - null - }, - synonym = try { - it.list.first().synonyms.first() - } catch (e: Exception) { - null - } + definition = expOrNull { it.list.first().definition }, + example = expOrNull { it.list.first().example }, + synonym = expOrNull { it.list.first().synonyms.first() } ) - Log.e("moin", def.toString()) - def } ) - return x } } diff --git a/app/src/main/java/com/bnyro/translate/ext/ExpOrNull.kt b/app/src/main/java/com/bnyro/translate/ext/ExpOrNull.kt new file mode 100644 index 000000000..77eea4fcc --- /dev/null +++ b/app/src/main/java/com/bnyro/translate/ext/ExpOrNull.kt @@ -0,0 +1,9 @@ +package com.bnyro.translate.ext + +inline fun expOrNull(block: () -> R): R? { + return try { + block() + } catch (e: Throwable) { + null + } +} diff --git a/app/src/main/java/com/bnyro/translate/ui/views/TranslationComponent.kt b/app/src/main/java/com/bnyro/translate/ui/views/TranslationComponent.kt index cde139bfd..880a47a46 100644 --- a/app/src/main/java/com/bnyro/translate/ui/views/TranslationComponent.kt +++ b/app/src/main/java/com/bnyro/translate/ui/views/TranslationComponent.kt @@ -182,6 +182,11 @@ fun TranslationComponent( } } + Spacer( + modifier = Modifier + .height(10.dp) + ) + if (viewModel.simTranslationEnabled) { SimTranslationComponent() } else {