Fixed crash when batch converting

Will clean later.
This commit is contained in:
Sad Ellie 2022-12-17 13:31:22 +04:00
parent 5cd2b3b205
commit 67ace59469
3 changed files with 14 additions and 6 deletions

View File

@ -500,7 +500,13 @@ class MainViewModel @Inject constructor(
/**
* Returns value to be used when converting value on the right side screen (unit selection)
*/
fun inputValue() = (mainFlow.value.calculatedValue ?: mainFlow.value.inputValue).toBigDecimal()
fun inputValue(): BigDecimal? {
return try {
(mainFlow.value.calculatedValue ?: mainFlow.value.inputValue).toBigDecimal()
} catch (e: NumberFormatException) {
null
}
}
/**
* Returns True if can be placed.

View File

@ -174,7 +174,7 @@ fun RightSideScreen(
navigateUp: () -> Unit,
navigateToSettingsAction: () -> Unit,
selectAction: (AbstractUnit) -> Unit,
inputValue: BigDecimal,
inputValue: BigDecimal?,
unitFrom: AbstractUnit
) {
val uiState = viewModel.mainFlow.collectAsStateWithLifecycle()
@ -225,9 +225,11 @@ fun RightSideScreen(
},
favoriteAction = { viewModel.favoriteUnit(it) },
convertValue = {
Formatter.format(
unitFrom.convert(unit, inputValue, 3).toPlainString()
)
inputValue?.let {
Formatter.format(
unitFrom.convert(unit, it, 3).toPlainString()
) + " "
} ?: ""
}
)
}

View File

@ -183,5 +183,5 @@ fun UnitListItem(
isSelected = isSelected,
selectAction = selectAction,
favoriteAction = favoriteAction,
shortNameLabel = "${convertValue(unit)} ${stringResource(unit.shortName)}"
shortNameLabel = "${convertValue(unit)}${stringResource(unit.shortName)}"
)