From 16b614d6f3fcc88924e79ac3a1bffef538b09e8b Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 16:11:47 -0600 Subject: Added hourmeter field --- .../android/details/information/UnitInformationFragment.kt | 8 ++++++++ .../TrackerMap/android/devices/UnitRenderData.kt | 14 ++++++++++++++ androidApp/src/main/res/drawable/position_hourmeter.xml | 10 ++++++++++ androidApp/src/main/res/values-es-rMX/strings.xml | 1 + androidApp/src/main/res/values/strings.xml | 1 + .../kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt | 5 ++++- 6 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 androidApp/src/main/res/drawable/position_hourmeter.xml diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt index 0c3577e..6c15ae4 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt @@ -13,6 +13,7 @@ import androidx.core.widget.TextViewCompat import androidx.fragment.app.Fragment import com.google.android.material.button.MaterialButton import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.serialization.json.longOrNull import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitDetailsInformationBinding import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter @@ -94,6 +95,13 @@ class UnitInformationFragment : Fragment() { unit.position?.address?.let { address -> details.add(getString(R.string.unit_info_address) to address) } + unit.position?.attributes?.get("hours")?.longOrNull?.let { + if (it > 0) { + details.add( + getString(R.string.unit_hourmeter) to Formatter.formatHours(it) + ) + } + } unit.position?.protocol?.let { protocol -> details.add(getString(R.string.unit_info_protocol) to protocol) } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt index beeba6f..c7999de 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt @@ -12,6 +12,7 @@ import android.widget.TextView import androidx.cardview.widget.CardView import androidx.core.content.ContextCompat import com.zerobranch.layout.SwipeLayout +import kotlinx.serialization.json.longOrNull import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.map.MarkerTransformations import mx.trackermap.TrackerMap.client.models.UnitInformation @@ -128,6 +129,19 @@ class UnitRenderData { ) } + /* Hourmeter */ + position.attributes["hours"]?.longOrNull?.let { + if (it > 0) { + details.add( + Triple( + R.drawable.position_hourmeter, + Formatter.formatHours(it), + context.getString(R.string.unit_hourmeter) + ) + ) + } + } + /* Date time */ position.fixTime?.let { fixTime -> details.add( diff --git a/androidApp/src/main/res/drawable/position_hourmeter.xml b/androidApp/src/main/res/drawable/position_hourmeter.xml new file mode 100644 index 0000000..52ff427 --- /dev/null +++ b/androidApp/src/main/res/drawable/position_hourmeter.xml @@ -0,0 +1,10 @@ + + + diff --git a/androidApp/src/main/res/values-es-rMX/strings.xml b/androidApp/src/main/res/values-es-rMX/strings.xml index 5e41768..f843c29 100644 --- a/androidApp/src/main/res/values-es-rMX/strings.xml +++ b/androidApp/src/main/res/values-es-rMX/strings.xml @@ -31,6 +31,7 @@ Nombre del conductor Velocidad Dirección de la última posición + Horómetro Fecha y hora de la última posición Animal diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 11c914f..60547d3 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -44,6 +44,7 @@ Driver name Speed Last position address + Hourmeter Last position datetime Animal 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 878418e..c113bef 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt @@ -1,7 +1,6 @@ package mx.trackermap.TrackerMap.utils import kotlinx.datetime.* -import kotlin.math.round class Formatter { companion object { @@ -25,5 +24,9 @@ class Formatter { } } } + + fun formatHours(millis: Long): String { + return "${millis / (1000 * 60 * 60)} hr" + } } } \ No newline at end of file -- cgit v1.2.3