mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +02:00
Fixed batch conversion
This commit is contained in:
parent
541e13908b
commit
6fcb600ed2
@ -66,20 +66,16 @@ internal fun RightSideScreen(
|
|||||||
val uiState = viewModel.mainFlow.collectAsStateWithLifecycle()
|
val uiState = viewModel.mainFlow.collectAsStateWithLifecycle()
|
||||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
|
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
val inputAsBigDecimal: BigDecimal? = try {
|
|
||||||
inputValue.toBigDecimal()
|
|
||||||
} catch (e: NumberFormatException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
val convertMethod: (AbstractUnit) -> String = when {
|
val convertMethod: (AbstractUnit) -> String = try {
|
||||||
unitFrom.group == UnitGroup.NUMBER_BASE -> {{
|
val inputAsBigDecimal = BigDecimal(inputValue)
|
||||||
convertForSecondaryNumberBase(inputValue, unitFrom as NumberBaseUnit, it as NumberBaseUnit)
|
if (unitFrom.group == UnitGroup.NUMBER_BASE) {
|
||||||
}}
|
{ (convertForSecondaryNumberBase(inputValue, unitFrom, it)) }
|
||||||
inputAsBigDecimal != null -> {{
|
} else {
|
||||||
convertForSecondary(inputAsBigDecimal, unitFrom, it)
|
{ convertForSecondary(inputAsBigDecimal, unitFrom, it) }
|
||||||
}}
|
}
|
||||||
else -> {{""}}
|
} catch(e: Exception) {
|
||||||
|
{ "" }
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
@ -141,10 +137,12 @@ private fun convertForSecondary(inputValue: BigDecimal, unitFrom: AbstractUnit,
|
|||||||
) + " "
|
) + " "
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertForSecondaryNumberBase(inputValue: String, unitFrom: NumberBaseUnit, unitTo: NumberBaseUnit): String {
|
private fun convertForSecondaryNumberBase(inputValue: String, unitFrom: AbstractUnit, unitTo: AbstractUnit): String {
|
||||||
return try {
|
return try {
|
||||||
unitFrom.convertToBase(inputValue, unitTo.base) + " "
|
(unitFrom as NumberBaseUnit).convertToBase(inputValue, (unitTo as NumberBaseUnit).base) + " "
|
||||||
} catch (e: NumberFormatException) {
|
} catch (e: NumberFormatException) {
|
||||||
""
|
""
|
||||||
|
} catch (e: ClassCastException) {
|
||||||
|
""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user