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/client/models/UnitInformation.kt | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models') 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