diff options
author | Iván Ávalos <avalos@disroot.org> | 2021-12-16 02:51:12 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2021-12-16 02:51:12 -0600 |
commit | 066298eda3c5ebe40b74ae67894417d72ff428a9 (patch) | |
tree | 371fa98e475593bc9edd310caa92b7b3a1fff5d2 /androidApp/src/main/java/mx/trackermap/TrackerMap | |
parent | 64edb0466aae0f920b6a9d6c01c142e1207ae5b1 (diff) | |
download | etbsa-trackermap-mobile-066298eda3c5ebe40b74ae67894417d72ff428a9.tar.gz etbsa-trackermap-mobile-066298eda3c5ebe40b74ae67894417d72ff428a9.tar.bz2 etbsa-trackermap-mobile-066298eda3c5ebe40b74ae67894417d72ff428a9.zip |
- Basically fully implemented device item with all details and icons.
- Attributes for all models are deserialized as Map<String, JsonPrimitive>.
- Removed redundant qualifier names
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt | 53 |
1 files changed, 48 insertions, 5 deletions
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 4aa210d..dd7333d 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 @@ -1,9 +1,15 @@ package mx.trackermap.TrackerMap.android.devices +import android.graphics.Color +import android.graphics.ColorFilter +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.ViewStructure +import androidx.core.content.res.ResourcesCompat import androidx.recyclerview.widget.RecyclerView +import kotlinx.serialization.json.JsonNull import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitItemBinding import mx.trackermap.TrackerMap.client.models.UnitInformation @@ -29,11 +35,46 @@ class DevicesAdapter( holder.toggleOptions(false) val unit = units[position] + val context = holder.itemView.context holder.binding.apply { + + unit.position?.let { position -> + /* Status icon */ + position.speed?.let { speed -> + if (speed >= 2) { + statusIcon.setColorFilter(Color.GREEN) + } else { + statusIcon.setColorFilter(Color.RED) + } + } ?: run { + statusIcon.setColorFilter(Color.GRAY) + } + + /* Engine stop */ + val attributes = position.attributes + if (attributes["out1"].toString() == "null") { + engineStopIcon.visibility = View.GONE + } else { + engineStopIcon.visibility = View.VISIBLE + engineStopIcon.setImageResource( + when (attributes["out1"].toString()) { + "true" -> R.drawable.ic_baseline_lock_24 + "false" -> R.drawable.ic_baseline_lock_open_24 + else -> R.drawable.ic_baseline_lock_open_24 + } + ) + 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) + } + } + } + unitName.text = unit.device.name driverName.text = unit.device.contact - unitSpeed.text = "${unit.position?.speed ?: "--"} Km/h" - lastAddress.text = unit.position?.address ?: "Unknown location" + unitSpeed.text = context.getString(R.string.unit_speed_format, unit.position?.speed?.toInt() ?: 0) + lastAddress.text = unit.position?.address lastDate.text = "yyyy/mm/dd, hh:mm" actionCallback?.let { callback -> detailsButton.setOnClickListener { callback(unit, Action.DETAILS) } @@ -55,9 +96,11 @@ class DevicesAdapter( fun toggleOptions(shouldExpand: Boolean) { val context = binding.root.context binding.unitCard.setCardBackgroundColor( - context - .resources - .getColor(if (shouldExpand) R.color.background else R.color.darkBackground) + ResourcesCompat.getColor( + context.resources, + if (shouldExpand) R.color.background else R.color.darkBackground, + context.theme + ) ) binding.itemOptions.visibility = if (shouldExpand) View.VISIBLE else View.GONE binding.unitCard.cardElevation = if (shouldExpand) 5.0F else 0.0F |