diff --git a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/UnitConverterRepository.kt b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/UnitConverterRepository.kt index e8aa795ac..a10cd1470 100644 --- a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/UnitConverterRepository.kt +++ b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/UnitConverterRepository.kt @@ -20,6 +20,7 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch @@ -67,7 +68,7 @@ internal class UnitConverterRepositoryImpl( TemperatureConverter(context), VolumeConverter(context), ) - if (includeCurrencies) converters.add(CurrencyConverter(currencyRepository)) + if (includeCurrencies) converters.add(CurrencyConverter(currencyRepository, settings.preferredCurrencies.first())) return converters } diff --git a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/CurrencyConverter.kt b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/CurrencyConverter.kt index c2a5df88a..401a726f1 100644 --- a/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/CurrencyConverter.kt +++ b/data/unitconverter/src/main/java/de/mm20/launcher2/unitconverter/converters/CurrencyConverter.kt @@ -16,6 +16,7 @@ import java.util.Currency as JCurrency class CurrencyConverter( private val repository: CurrencyRepository, + private val preferredCurrencies: List, ) : Converter { override val dimension: Dimension = Dimension.Currency @@ -88,23 +89,15 @@ class CurrencyConverter( ) }.toMutableList() - val ownCurrencySymbol = JCurrency.getInstance(Locale.getDefault()).currencyCode ?: "USD" - val index = values.indexOfFirst { it.symbol == ownCurrencySymbol } - - val ownCurrency = if (index != -1) { - values.removeAt(index) - } else { - null + val ownCurrencySymbols = preferredCurrencies.ifEmpty { + listOf(JCurrency.getInstance(Locale.getDefault()).currencyCode ?: "USD") } + val topCurrencies = ownCurrencySymbols + topCurrencies values.sortBy { val i = topCurrencies.indexOf(it.symbol) - if (i != -1) i.toString() - else it.formattedName - } - - if (ownCurrency != null) { - values.add(0, ownCurrency) + if (i != -1) return@sortBy ("000$i").takeLast(4) + it.formattedName } val inputValue = UnitValue(