aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt61
1 files changed, 12 insertions, 49 deletions
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 4f98a96..fc417a0 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
@@ -13,6 +13,7 @@ import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.android.databinding.UnitMapFragmentBinding
import mx.trackermap.TrackerMap.android.details.DetailsActivity
import mx.trackermap.TrackerMap.android.devices.Action
+import mx.trackermap.TrackerMap.android.devices.UnitRenderData
import mx.trackermap.TrackerMap.android.units.UnitsViewModel
import mx.trackermap.TrackerMap.client.models.UnitInformation
import mx.trackermap.TrackerMap.utils.Formatter
@@ -71,55 +72,17 @@ class UnitMapFragment : Fragment() {
return@let
}
- binding.apply {
- context?.let { context ->
- 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.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)
- }
- }
- }
-
- unitName.text = unit.device.name
- driverName.text = unit.device.contact
- unitSpeed.text =
- Formatter.formatSpeed(unit.position?.speed ?: 0.0, SpeedUnit.KMH)
- lastAddress.text = unit.position?.address
- unit.position?.fixTime?.let {
- lastDate.text = Formatter.formatDate(it)
- }
- detailsButton.setOnClickListener { itemAction(unit, Action.DETAILS) }
- reportsButton.setOnClickListener { itemAction(unit, Action.REPORTS) }
- commandsButton.setOnClickListener { itemAction(unit, Action.COMMANDS) }
- }
- }
+ UnitRenderData.render(
+ UnitRenderData.UnitRenderViewHolder(
+ unitName = binding.unitName,
+ statusIcon = binding.statusIcon,
+ engineStopIcon = binding.engineStopIcon,
+ gridLayout = binding.gridLayout,
+ detailsButton = binding.detailsButton,
+ reportsButton = binding.reportsButton,
+ commandsButton = binding.commandsButton
+ ), binding.mapUnitCard.context, unit, this::itemAction
+ )
unitsMapFragment.focusOn(unit.position!!.latitude!!, unit.position!!.longitude!!)
}