mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 08:45:27 +02:00
Fix equality (in code, not world)
This commit is contained in:
parent
29c2f2f26e
commit
0bb260e921
@ -58,7 +58,14 @@ internal sealed class UnitConverterUIState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class ConverterResult {
|
internal sealed class ConverterResult {
|
||||||
data class Default(val value: BigDecimal) : ConverterResult()
|
data class Default(val value: BigDecimal) : ConverterResult() {
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (other !is Default) return false
|
||||||
|
return this.value.compareTo(other.value) == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int = value.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
data class NumberBase(val value: String) : ConverterResult()
|
data class NumberBase(val value: String) : ConverterResult()
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ import kotlinx.coroutines.flow.StateFlow
|
|||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.getAndUpdate
|
import kotlinx.coroutines.flow.getAndUpdate
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.mapLatest
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -112,15 +112,15 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
else -> UnitConverterUIState.Loading
|
else -> UnitConverterUIState.Loading
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onEach { ui ->
|
.mapLatest { ui ->
|
||||||
when (_currenciesState.value) {
|
when (_currenciesState.value) {
|
||||||
is CurrencyRateUpdateState.Loading -> {
|
is CurrencyRateUpdateState.Loading -> {
|
||||||
_result.update { ConverterResult.Loading }
|
_result.update { ConverterResult.Loading }
|
||||||
return@onEach
|
return@mapLatest ui
|
||||||
}
|
}
|
||||||
is CurrencyRateUpdateState.Error -> {
|
is CurrencyRateUpdateState.Error -> {
|
||||||
_result.update { ConverterResult.Error }
|
_result.update { ConverterResult.Error }
|
||||||
return@onEach
|
return@mapLatest ui
|
||||||
}
|
}
|
||||||
is CurrencyRateUpdateState.Ready, is CurrencyRateUpdateState.Nothing -> {}
|
is CurrencyRateUpdateState.Ready, is CurrencyRateUpdateState.Nothing -> {}
|
||||||
}
|
}
|
||||||
@ -143,6 +143,7 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
is UnitConverterUIState.Loading -> {}
|
is UnitConverterUIState.Loading -> {}
|
||||||
}
|
}
|
||||||
|
ui
|
||||||
}
|
}
|
||||||
.stateIn(viewModelScope, UnitConverterUIState.Loading)
|
.stateIn(viewModelScope, UnitConverterUIState.Loading)
|
||||||
|
|
||||||
@ -160,7 +161,7 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
verticalList = prefs.enableToolsExperiment,
|
verticalList = prefs.enableToolsExperiment,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.onEach {
|
.mapLatest {
|
||||||
filterUnitsLeft(
|
filterUnitsLeft(
|
||||||
query = it.query,
|
query = it.query,
|
||||||
unitGroup = it.unitGroup,
|
unitGroup = it.unitGroup,
|
||||||
@ -168,6 +169,7 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
sorting = it.sorting,
|
sorting = it.sorting,
|
||||||
shownUnitGroups = it.shownUnitGroups,
|
shownUnitGroups = it.shownUnitGroups,
|
||||||
)
|
)
|
||||||
|
it
|
||||||
}
|
}
|
||||||
.stateIn(viewModelScope, SharingStarted.Lazily, LeftSideUIState())
|
.stateIn(viewModelScope, SharingStarted.Lazily, LeftSideUIState())
|
||||||
|
|
||||||
@ -193,7 +195,7 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
currencyRateUpdateState = currenciesState
|
currencyRateUpdateState = currenciesState
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.onEach {
|
.mapLatest {
|
||||||
filterUnitsRight(
|
filterUnitsRight(
|
||||||
query = it.query,
|
query = it.query,
|
||||||
unitGroup = it.unitTo?.group,
|
unitGroup = it.unitTo?.group,
|
||||||
@ -201,6 +203,7 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
sorting = it.sorting,
|
sorting = it.sorting,
|
||||||
shownUnitGroups = emptyList(),
|
shownUnitGroups = emptyList(),
|
||||||
)
|
)
|
||||||
|
it
|
||||||
}
|
}
|
||||||
.stateIn(viewModelScope, SharingStarted.Lazily, RightSideUIState())
|
.stateIn(viewModelScope, SharingStarted.Lazily, RightSideUIState())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user