From 3e15173c529b2b307e813288f4728f5110fb5a78 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 4 Jan 2022 22:37:36 -0600 Subject: Implemented formatSpeed, redesigned UnitInformationFragment, added button to open device location in map, minor UI tweaks and added translations. --- .../kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt | 15 +++++++++++++++ .../kotlin/mx/trackermap/TrackerMap/utils/SpeedUnit.kt | 5 +++++ 2 files changed, 20 insertions(+) create mode 100644 shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/SpeedUnit.kt (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap') diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt index 133c028..af4e14d 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt @@ -1,6 +1,7 @@ package mx.trackermap.TrackerMap.utils import kotlinx.datetime.* +import kotlin.math.round class Formatter { companion object { @@ -8,5 +9,19 @@ class Formatter { return date.substring(0 until date.indexOf('+')) .toLocalDateTime().toString().replace('T', ' ') } + + fun formatSpeed(speed: Double, unit: SpeedUnit): String { + return when (unit) { + SpeedUnit.KMH -> { + "${(speed * 1.852).toInt()} km/h" + } + SpeedUnit.MPH -> { + "${(speed * 1.15078).toInt()} mph" + } + SpeedUnit.KN -> { + "${speed.toInt()} kn" + } + } + } } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/SpeedUnit.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/SpeedUnit.kt new file mode 100644 index 0000000..bc9cdb4 --- /dev/null +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/SpeedUnit.kt @@ -0,0 +1,5 @@ +package mx.trackermap.TrackerMap.utils + +enum class SpeedUnit { + KMH, MPH, KN +} \ No newline at end of file -- cgit v1.2.3