aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-11 20:05:03 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-11 20:05:03 -0600
commitee9e673695e221e115758b1ac32a6b63683ae7c9 (patch)
treeea175b800416bf82662538b9df0426bf5f8e4d8b /androidApp/src/main/java/mx/trackermap/TrackerMap/android/map
parent7baad408f97d7d4ab512b822bdc0799469e2d496 (diff)
downloadetbsa-trackermap-mobile-ee9e673695e221e115758b1ac32a6b63683ae7c9.tar.gz
etbsa-trackermap-mobile-ee9e673695e221e115758b1ac32a6b63683ae7c9.tar.bz2
etbsa-trackermap-mobile-ee9e673695e221e115758b1ac32a6b63683ae7c9.zip
unit_item.xml data fields are generated programmatically, and DevicesAdapter code was refactored into UnitRenderData to be shared with UnitMapFragment.
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/map')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt2
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt61
2 files changed, 13 insertions, 50 deletions
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!!)
}