mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
Use favorite unit as default pair
This commit is contained in:
parent
679e89ee69
commit
d0a873ea43
@ -292,9 +292,13 @@ internal class ConverterViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateUnitFrom(unit: AbstractUnit) = viewModelScope.launch {
|
fun updateUnitFrom(unit: AbstractUnit) = viewModelScope.launch {
|
||||||
val pair = unitsRepo.getById(
|
val pairId = unit.pairId
|
||||||
unit.pairId ?: unitsRepo.getCollection(unit.group).first().id
|
val pair: AbstractUnit = if (pairId == null) {
|
||||||
)
|
val collection = unitsRepo.getCollection(unit.group).sortedByDescending { it.counter }
|
||||||
|
collection.firstOrNull { it.isFavorite } ?: collection.first()
|
||||||
|
} else {
|
||||||
|
unitsRepo.getById(pairId)
|
||||||
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
unitsRepo.incrementCounter(unit)
|
unitsRepo.incrementCounter(unit)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user