mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 16:55:26 +02:00
Fixed crash when batch converting
Will clean later.
This commit is contained in:
parent
5cd2b3b205
commit
67ace59469
@ -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.
|
||||
|
@ -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()
|
||||
) + " "
|
||||
} ?: ""
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -183,5 +183,5 @@ fun UnitListItem(
|
||||
isSelected = isSelected,
|
||||
selectAction = selectAction,
|
||||
favoriteAction = favoriteAction,
|
||||
shortNameLabel = "${convertValue(unit)} ${stringResource(unit.shortName)}"
|
||||
shortNameLabel = "${convertValue(unit)}${stringResource(unit.shortName)}"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user