From 86b5601d7d9965bea7d57f04600b02f5432dc966 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 3 Jan 2023 19:49:37 -0600 Subject: [android] Changed way that online status is calculated, and added ignition icon --- .../TrackerMap/android/devices/DevicesAdapter.kt | 1 + .../TrackerMap/android/map/UnitMapFragment.kt | 1 + .../TrackerMap/android/shared/UnitRenderData.kt | 9 ++++++++- .../src/main/res/drawable/device_ignition.xml | 5 +++++ androidApp/src/main/res/layout/unit_item.xml | 8 ++++++++ .../src/main/res/layout/unit_map_fragment.xml | 8 ++++++++ androidApp/src/main/res/values-es-rMX/strings.xml | 1 + androidApp/src/main/res/values/strings.xml | 1 + .../TrackerMap/client/models/UnitInformation.kt | 21 ++++++++++----------- 9 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 androidApp/src/main/res/drawable/device_ignition.xml diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt index 0fbf597..326fe79 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt @@ -63,6 +63,7 @@ class DevicesAdapter( unitName = unitName, unitIcon = unitIcon, statusIcon = statusIcon, + ignitionIcon = ignitionIcon, engineStopIcon = engineStopIcon, gridLayout = gridLayout, detailsButton = detailsButton, diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt index 5e2224b..2fbb25a 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt @@ -124,6 +124,7 @@ class UnitMapFragment : Fragment() { UnitRenderData.UnitRenderViewHolder( unitName = binding.unitName, statusIcon = binding.statusIcon, + ignitionIcon = binding.ignitionIcon, engineStopIcon = binding.engineStopIcon, gridLayout = binding.gridLayout, detailsButton = binding.detailsButton, diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/shared/UnitRenderData.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/shared/UnitRenderData.kt index 9a9f85c..340371a 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/shared/UnitRenderData.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/shared/UnitRenderData.kt @@ -29,7 +29,6 @@ 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.client.models.UnitInformation import mx.trackermap.TrackerMap.utils.Formatter @@ -42,6 +41,7 @@ class UnitRenderData { val unitName: TextView, val unitIcon: ImageView? = null, val statusIcon: ImageView, + val ignitionIcon: ImageView, val engineStopIcon: ImageView, val gridLayout: GridLayout, val detailsButton: Button? = null, @@ -106,6 +106,13 @@ class UnitRenderData { } } + /* Ignition icon */ + ignitionIcon.visibility = if (unit.getIgnition()) { + View.VISIBLE + } else { + View.GONE + } + /* Engine stop */ when(unit.getEngineStop()) { UnitInformation.EngineStop.ON -> { diff --git a/androidApp/src/main/res/drawable/device_ignition.xml b/androidApp/src/main/res/drawable/device_ignition.xml new file mode 100644 index 0000000..d2d8103 --- /dev/null +++ b/androidApp/src/main/res/drawable/device_ignition.xml @@ -0,0 +1,5 @@ + + + diff --git a/androidApp/src/main/res/layout/unit_item.xml b/androidApp/src/main/res/layout/unit_item.xml index 6946d1d..03bef15 100644 --- a/androidApp/src/main/res/layout/unit_item.xml +++ b/androidApp/src/main/res/layout/unit_item.xml @@ -112,6 +112,14 @@ app:tint="?android:textColorPrimary" tools:ignore="ContentDescription" /> + + + + Estatus encendido Estatus apagado + Ignición apagada Paro de motor encendido Paro de motor apagado Nombre del conductor diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 93dd45f..57eaf66 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -47,6 +47,7 @@ Status on Status off + Ignition on Engine stop on Engine stop off Driver name diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt index 1e23396..6afa350 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt @@ -17,6 +17,7 @@ */ package mx.trackermap.TrackerMap.client.models +import kotlinx.serialization.json.boolean import kotlinx.serialization.json.longOrNull data class UnitInformation( @@ -31,17 +32,15 @@ data class UnitInformation( ON, OFF, UNKNOWN } - /** - * Status is calculated from speed, because status based on - * the actual connection to the server is useless for our clients. - */ - fun getStatus() = position?.speed?.let { - if (it >= 2) { - Status.ONLINE - } else { - Status.OFFLINE - } - } ?: Status.UNKNOWN + fun getStatus() = when (device.status) { + "online" -> Status.ONLINE + "offline" -> Status.OFFLINE + else -> Status.UNKNOWN + } + + fun getIgnition() = if (position?.attributes?.containsKey("ignition") == true) { + position.attributes["ignition"]?.boolean ?: false + } else false /* Many GPS devices reserve pin 1 for engine stop */ fun getEngineStop() = if (position?.attributes?.containsKey("out1") == true) { -- cgit v1.2.3