mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 08:45:27 +02:00
parent
4319d18e17
commit
9f683785cf
@ -139,7 +139,6 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
is CurrencyRateUpdateState.Ready, is CurrencyRateUpdateState.Nothing -> {}
|
is CurrencyRateUpdateState.Ready, is CurrencyRateUpdateState.Nothing -> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
when (ui) {
|
when (ui) {
|
||||||
is UnitConverterUIState.Default -> {
|
is UnitConverterUIState.Default -> {
|
||||||
convertDefault(
|
convertDefault(
|
||||||
@ -159,10 +158,6 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
is UnitConverterUIState.Loading -> {}
|
is UnitConverterUIState.Loading -> {}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
_result.update { ConverterResult.Default(BigDecimal.ZERO) }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ui
|
ui
|
||||||
}
|
}
|
||||||
@ -471,21 +466,24 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
_calculation.update { if (input1.text.isExpression()) calculated1 else null }
|
_calculation.update { if (input1.text.isExpression()) calculated1 else null }
|
||||||
|
|
||||||
// Convert
|
// Convert
|
||||||
|
val result: ConverterResult = try {
|
||||||
var conversion = unitFrom.convert(unitTo, calculated1)
|
var conversion = unitFrom.convert(unitTo, calculated1)
|
||||||
if (footInchInput) {
|
if (footInchInput) {
|
||||||
// Converted from second text field too
|
// Converted from second text field too
|
||||||
val inches = unitsRepo.getById(MyUnitIDS.inch) as DefaultUnit
|
val inches = unitsRepo.getById(MyUnitIDS.inch) as DefaultUnit
|
||||||
conversion += inches.convert(unitTo, calculated2)
|
conversion += inches.convert(unitTo, calculated2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update result
|
|
||||||
_result.update {
|
|
||||||
when {
|
when {
|
||||||
(unitFrom.group == UnitGroup.TIME) and (formatTime) -> formatTime(calculated1.multiply(unitFrom.basicUnit))
|
(unitFrom.group == UnitGroup.TIME) and (formatTime) -> formatTime(calculated1.multiply(unitFrom.basicUnit))
|
||||||
unitTo.id == MyUnitIDS.foot -> formatFootInch(conversion, unitTo, unitsRepo.getById(MyUnitIDS.inch) as DefaultUnit)
|
unitTo.id == MyUnitIDS.foot -> formatFootInch(conversion, unitTo, unitsRepo.getById(MyUnitIDS.inch) as DefaultUnit)
|
||||||
else -> ConverterResult.Default(conversion)
|
else -> ConverterResult.Default(conversion)
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
ConverterResult.Default(BigDecimal.ZERO)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update result
|
||||||
|
_result.update { result }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertNumberBase(
|
private fun convertNumberBase(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user