From ee9e673695e221e115758b1ac32a6b63683ae7c9 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 11 Jan 2022 20:05:03 -0600 Subject: unit_item.xml data fields are generated programmatically, and DevicesAdapter code was refactored into UnitRenderData to be shared with UnitMapFragment. --- .../TrackerMap/android/map/MapFragment.kt | 2 +- .../TrackerMap/android/map/UnitMapFragment.kt | 61 +++++----------------- 2 files changed, 13 insertions(+), 50 deletions(-) (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/map') diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt index 39312a8..9bda9d4 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt @@ -260,7 +260,7 @@ class MapFragment : GlobeMapFragment() { val lat = latitude * Math.PI / 180 val lon = longitude * Math.PI / 180 if (animated) { - mapControl.animatePositionGeo(lon, lat, zoom, 0.5) + mapControl.animatePositionGeo(lon, lat, zoom, 0.2) } else { mapControl.setPositionGeo(lon, lat, zoom) } 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!!) } -- cgit v1.2.3