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) * 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. * Returns True if can be placed.

View File

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

View File

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