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 {
|
||||
val pair = unitsRepo.getById(
|
||||
unit.pairId ?: unitsRepo.getCollection(unit.group).first().id
|
||||
)
|
||||
val pairId = unit.pairId
|
||||
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) {
|
||||
unitsRepo.incrementCounter(unit)
|
||||
|
Loading…
x
Reference in New Issue
Block a user