From 65ea295e0c013d143552988911d44a84876f4f30 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sat, 29 Jan 2022 04:24:01 -0600 Subject: Updated UnitRenderData with new getStatus() and getEngineStop() functions in UnitInformation --- .../TrackerMap/android/shared/UnitRenderData.kt | 62 +++++++++++----------- 1 file changed, 30 insertions(+), 32 deletions(-) (limited to 'androidApp') 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 123e1ab..7b66bd3 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 @@ -89,43 +89,41 @@ class UnitRenderData { } } - statusIcon.visibility = View.GONE - engineStopIcon.visibility = View.GONE - - unit.position?.let { position -> - /* Status icon */ - statusIcon.visibility = View.VISIBLE - position.speed?.let { speed -> - if (speed >= 2) { - statusIcon.setColorFilter( - ContextCompat.getColor(context, R.color.colorOnline) - ) - } else { - statusIcon.setColorFilter( - ContextCompat.getColor(context, R.color.colorOffline) - ) - } - } ?: run { + /* Status icon */ + when (unit.getStatus()) { + UnitInformation.Status.ONLINE -> { + statusIcon.setColorFilter( + ContextCompat.getColor(context, R.color.colorOnline) + ) + } + UnitInformation.Status.OFFLINE -> { + statusIcon.setColorFilter( + ContextCompat.getColor(context, R.color.colorOffline) + ) + } + else -> { statusIcon.setColorFilter(Color.GRAY) } + } - /* Engine stop */ - val attributes = position.attributes - if (attributes["out1"].toString() != "null") { + /* Engine stop */ + when(unit.getEngineStop()) { + UnitInformation.EngineStop.ON -> { engineStopIcon.visibility = View.VISIBLE - engineStopIcon.setImageResource( - when (attributes["out1"].toString()) { - "true" -> R.drawable.device_unlocked - "false" -> R.drawable.device_locked - else -> R.drawable.device_locked - } - ) - engineStopIcon.contentDescription = when (attributes["out1"].toString()) { - "true" -> context.getString(R.string.unit_lock_on) - "false" -> context.getString(R.string.unit_lock_off) - else -> context.getString(R.string.unit_lock_on) - } + engineStopIcon.setImageResource(R.drawable.device_unlocked) + engineStopIcon.contentDescription = context.getString(R.string.unit_lock_on) + } + UnitInformation.EngineStop.OFF -> { + engineStopIcon.visibility = View.VISIBLE + engineStopIcon.setImageResource(R.drawable.device_locked) + engineStopIcon.contentDescription = context.getString(R.string.unit_lock_off) } + UnitInformation.EngineStop.UNKNOWN -> { + engineStopIcon.visibility = View.GONE + } + } + + unit.position?.let { position -> /* Speed */ position.speed?.let { speed -> -- cgit v1.2.3