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)
|
* 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.
|
||||||
|
@ -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()
|
||||||
|
) + " "
|
||||||
|
} ?: ""
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -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)}"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user