Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Oct 22, 2022
1 parent 61a6f7d commit 5f1c389
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
27 changes: 6 additions & 21 deletions app/src/main/java/com/bnyro/translate/api/lv/LVEngine.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/bnyro/translate/ext/ExpOrNull.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bnyro.translate.ext

inline fun <R> expOrNull(block: () -> R): R? {
return try {
block()
} catch (e: Throwable) {
null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ fun TranslationComponent(
}
}

Spacer(
modifier = Modifier
.height(10.dp)
)

if (viewModel.simTranslationEnabled) {
SimTranslationComponent()
} else {
Expand Down

0 comments on commit 5f1c389

Please sign in to comment.