From 99c4644753fd4e644183ed5e923154ff39f9d26c Mon Sep 17 00:00:00 2001 From: Cristan Meijer Date: Wed, 13 Nov 2024 22:51:11 +0100 Subject: [PATCH] Use the dutch locale whenever we use a locale --- .../java/nl/ovfietsbeschikbaarheid/LocationsDataTest.kt | 4 ++-- .../java/nl/ovfietsbeschikbaarheid/mapper/LocationsMapper.kt | 5 +++++ .../ovfietsbeschikbaarheid/repository/StationRepository.kt | 4 ++-- app/src/main/java/nl/ovfietsbeschikbaarheid/util/Locale.kt | 5 +++++ 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/nl/ovfietsbeschikbaarheid/util/Locale.kt diff --git a/app/src/androidTest/java/nl/ovfietsbeschikbaarheid/LocationsDataTest.kt b/app/src/androidTest/java/nl/ovfietsbeschikbaarheid/LocationsDataTest.kt index 25389fa..c7af658 100644 --- a/app/src/androidTest/java/nl/ovfietsbeschikbaarheid/LocationsDataTest.kt +++ b/app/src/androidTest/java/nl/ovfietsbeschikbaarheid/LocationsDataTest.kt @@ -4,8 +4,8 @@ import androidx.test.platform.app.InstrumentationRegistry import kotlinx.coroutines.runBlocking import nl.ovfietsbeschikbaarheid.repository.OverviewRepository import nl.ovfietsbeschikbaarheid.repository.StationRepository +import nl.ovfietsbeschikbaarheid.util.dutchLocale import org.junit.Test -import java.util.Locale class LocationsDataTest { @@ -24,7 +24,7 @@ class LocationsDataTest { // Same applies to Utrecht Vaartsche Rijn: this is made at 2016. println("Station ${it.stationCode} not found for $it") } - val foundCapacity = capacities[it.locationCode.lowercase(Locale.UK)] + val foundCapacity = capacities[it.locationCode.lowercase(dutchLocale)] if (foundCapacity == null) { error("Capacity for ${it.locationCode} not found") } diff --git a/app/src/main/java/nl/ovfietsbeschikbaarheid/mapper/LocationsMapper.kt b/app/src/main/java/nl/ovfietsbeschikbaarheid/mapper/LocationsMapper.kt index 98b8d0e..453bf33 100644 --- a/app/src/main/java/nl/ovfietsbeschikbaarheid/mapper/LocationsMapper.kt +++ b/app/src/main/java/nl/ovfietsbeschikbaarheid/mapper/LocationsMapper.kt @@ -6,7 +6,9 @@ import nl.ovfietsbeschikbaarheid.ext.distanceTo import nl.ovfietsbeschikbaarheid.model.LocationOverviewModel import nl.ovfietsbeschikbaarheid.model.LocationOverviewWithDistanceModel import nl.ovfietsbeschikbaarheid.model.LocationType +import nl.ovfietsbeschikbaarheid.util.dutchLocale import java.text.DecimalFormat +import java.text.DecimalFormatSymbols import kotlin.math.roundToInt object LocationsMapper { @@ -49,9 +51,12 @@ object LocationsMapper { } fun withDistance(locations: List, currentCoordinates: Coordinates): List { + val symbols = DecimalFormatSymbols(dutchLocale) + val kmFormat = DecimalFormat().apply { minimumFractionDigits = 1 maximumFractionDigits = 1 + decimalFormatSymbols = symbols } return locations .sortedBy { it.distanceTo(currentCoordinates) } diff --git a/app/src/main/java/nl/ovfietsbeschikbaarheid/repository/StationRepository.kt b/app/src/main/java/nl/ovfietsbeschikbaarheid/repository/StationRepository.kt index 3a931fb..35855ce 100644 --- a/app/src/main/java/nl/ovfietsbeschikbaarheid/repository/StationRepository.kt +++ b/app/src/main/java/nl/ovfietsbeschikbaarheid/repository/StationRepository.kt @@ -3,7 +3,7 @@ package nl.ovfietsbeschikbaarheid.repository import android.content.Context import com.github.doyaaaaaken.kotlincsv.dsl.csvReader import nl.ovfietsbeschikbaarheid.R -import java.util.Locale +import nl.ovfietsbeschikbaarheid.util.dutchLocale class StationRepository(private val context: Context) { private var cachedStations: Map? = null @@ -19,7 +19,7 @@ class StationRepository(private val context: Context) { val stationsStream = context.resources.openRawResource(R.raw.stations_nl_2015_08) val stations = HashMap() csvReader { delimiter = ';' }.readAll(stationsStream).forEach { - val code = it[1].uppercase(Locale.UK) + val code = it[1].uppercase(dutchLocale) val stationName = it[3] stations[code] = stationName } diff --git a/app/src/main/java/nl/ovfietsbeschikbaarheid/util/Locale.kt b/app/src/main/java/nl/ovfietsbeschikbaarheid/util/Locale.kt new file mode 100644 index 0000000..e228f88 --- /dev/null +++ b/app/src/main/java/nl/ovfietsbeschikbaarheid/util/Locale.kt @@ -0,0 +1,5 @@ +package nl.ovfietsbeschikbaarheid.util + +import java.util.Locale + +val dutchLocale = Locale("NL", "nl") \ No newline at end of file