From 4ff1b200f12fc335abd1f0f6117649f50b3968ce Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sat, 29 Jan 2022 22:19:28 -0600 Subject: Moved MapFragment.Marker and MarkerTransformations functions to Marker model in shared module --- .../TrackerMap/android/map/MapFragment.kt | 25 +++---- .../TrackerMap/android/map/MapWrapperFragment.kt | 6 +- .../android/shared/MarkerTransformations.kt | 77 +--------------------- 3 files changed, 15 insertions(+), 93 deletions(-) (limited to 'androidApp/src/main') 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 a76ebde..a07f054 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 @@ -38,6 +38,7 @@ import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.shared.MarkerTransformations import mx.trackermap.TrackerMap.client.models.Geofence import mx.trackermap.TrackerMap.client.models.MapLayer +import mx.trackermap.TrackerMap.client.models.Marker import mx.trackermap.TrackerMap.utils.MapCalculus import mx.trackermap.TrackerMap.utils.MarkerType @@ -48,14 +49,6 @@ open class MapFragment : GlobeMapFragment() { private var loader: QuadImageLoader? = null - data class Marker( - val id: Int, - val name: String, - val latitude: Double, - val longitude: Double, - val type: MarkerType = MarkerType.DEFAULT - ) - var hasStarted: Boolean = false val setupCallbacks = mutableListOf() var markerCallback: MarkerCallback? = null @@ -185,9 +178,9 @@ open class MapFragment : GlobeMapFragment() { }.toTypedArray() val fontSize = context?.resources?.getDimensionPixelSize(R.dimen.marker_label_text_size) - val colorReport = ContextCompat.getColor(context!!, R.color.colorReport) - val colorLabel = ContextCompat.getColor(context!!, R.color.colorMarkerLabel) - val colorLabelOutline = ContextCompat.getColor(context!!, R.color.colorMarkerLabelOutline) + val colorReport = ContextCompat.getColor(requireContext(), R.color.colorReport) + val colorLabel = ContextCompat.getColor(requireContext(), R.color.colorMarkerLabel) + val colorLabelOutline = ContextCompat.getColor(requireContext(), R.color.colorMarkerLabelOutline) val vectorWidth = context?.resources?.getDimensionPixelSize(R.dimen.report_label_width)?.toFloat() val vectorInfo = VectorInfo() @@ -291,9 +284,9 @@ open class MapFragment : GlobeMapFragment() { clear(true) val fontSize = context?.resources?.getDimensionPixelSize(R.dimen.marker_label_text_size) - val colorFill = ContextCompat.getColor(context!!, R.color.colorGeofence) - val colorLabel = ContextCompat.getColor(context!!, R.color.colorGeofenceLabel) - val colorLabelOutline = ContextCompat.getColor(context!!, R.color.colorMarkerLabelOutline) + val colorFill = ContextCompat.getColor(requireContext(), R.color.colorGeofence) + val colorLabel = ContextCompat.getColor(requireContext(), R.color.colorGeofenceLabel) + val colorLabelOutline = ContextCompat.getColor(requireContext(), R.color.colorMarkerLabelOutline) val vectorWidth = context?.resources?.getDimensionPixelSize(R.dimen.geofence_label_width)?.toFloat() val vectorInfo = VectorInfo() @@ -430,8 +423,8 @@ open class MapFragment : GlobeMapFragment() { private fun getIcon(markerType: MarkerType): Bitmap { return ResourcesCompat.getDrawable( - activity!!.resources, + requireActivity().resources, MarkerTransformations.markerTypeToResourceId(markerType), - activity!!.theme)!!.toBitmap(144, 144) + requireActivity().theme)!!.toBitmap(144, 144) } } \ No newline at end of file diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt index c9eab70..aa2faf9 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt @@ -165,7 +165,7 @@ class MapWrapperFragment: Fragment() { Log.d("MapWrapperFragment", "Displaying positions: $positions") mapFragment.display( - positions.mapNotNull(MarkerTransformations::positionToMarker).toTypedArray(), + positions.mapNotNull(Marker::fromPosition).toTypedArray(), isReport = isReport, center = center ) @@ -181,7 +181,7 @@ class MapWrapperFragment: Fragment() { Log.d("MapWrapperFragment", "Displaying units: $units") mapFragment.display( - units.mapNotNull(MarkerTransformations::unitToMarker).toTypedArray(), + units.mapNotNull(Marker::fromUnit).toTypedArray(), isReport = isReport, center = center ) @@ -197,7 +197,7 @@ class MapWrapperFragment: Fragment() { Log.d("MapWrapperFragment", "Displaying stops: $stops") mapFragment.display( - stops.mapNotNull(MarkerTransformations::stopToMarker).toTypedArray(), + stops.mapNotNull(Marker::fromStop).toTypedArray(), isReport = true ) } else { diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/shared/MarkerTransformations.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/shared/MarkerTransformations.kt index 58ee108..aacf414 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/shared/MarkerTransformations.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/shared/MarkerTransformations.kt @@ -17,82 +17,11 @@ */ package mx.trackermap.TrackerMap.android.shared -import android.util.Log import mx.trackermap.TrackerMap.android.R -import mx.trackermap.TrackerMap.android.map.MapFragment -import mx.trackermap.TrackerMap.client.models.Position -import mx.trackermap.TrackerMap.client.models.Stop -import mx.trackermap.TrackerMap.client.models.UnitInformation +import mx.trackermap.TrackerMap.client.models.Marker import mx.trackermap.TrackerMap.utils.MarkerType object MarkerTransformations { - fun unitToMarker(unit: UnitInformation): MapFragment.Marker? { - if (unit.position == null || unit.position!!.latitude == null || unit.position!!.longitude == null) { - return null - } - - return MapFragment.Marker( - unit.position!!.id!!, - unit.device.name, - unit.position!!.latitude!!, - unit.position!!.longitude!!, - categoryToMarkerType(unit.device.category ?: "") - ) - } - - fun positionToMarker(position: Position): MapFragment.Marker? { - if (position.latitude == null || position.longitude == null) { - return null - } - - return MapFragment.Marker( - position.id!!, - "", - position.latitude!!, - position.longitude!! - ) - } - - fun stopToMarker(stop: Stop): MapFragment.Marker? { - Log.d("MarkerTransformations", "stopToMarker($stop)") - if (stop.latitude == null || stop.longitude == null) { - return null - } - - return MapFragment.Marker( - stop.deviceId!!, - stop.deviceName!!, - stop.latitude!!, - stop.longitude!! - ) - } - - private fun categoryToMarkerType(category: String?): MarkerType { - return when (category?.lowercase()) { - "animal" -> MarkerType.ANIMAL - "bicycle" -> MarkerType.BICYCLE - "boat" -> MarkerType.BOAT - "bus" -> MarkerType.BUS - "car" -> MarkerType.CAR - "crane" -> MarkerType.CRANE - "helicopter" -> MarkerType.HELICOPTER - "motorcycle" -> MarkerType.MOTORCYCLE - "offroad" -> MarkerType.OFFROAD - "person" -> MarkerType.PERSON - "pickup" -> MarkerType.PICKUP - "plane" -> MarkerType.PLANE - "scooter" -> MarkerType.SCOOTER - "ship" -> MarkerType.SHIP - "tractor" -> MarkerType.TRACTOR - "train" -> MarkerType.TRAIN - "tram" -> MarkerType.TRAM - "trolleybus" -> MarkerType.TROLLEYBUS - "truck" -> MarkerType.TRUCK - "van" -> MarkerType.VAN - else -> MarkerType.DEFAULT - } - } - fun markerTypeToResourceId(markerType: MarkerType): Int { return when (markerType) { MarkerType.ANIMAL -> R.drawable.map_animal @@ -151,10 +80,10 @@ object MarkerTransformations { } fun categoryToResourceId(category: String?): Int { - return markerTypeToResourceId(categoryToMarkerType(category)) + return markerTypeToResourceId(Marker.categoryToMarkerType(category)) } fun categoryToStringId(category: String?): Int { - return markerTypeToResourceId(categoryToMarkerType(category)) + return markerTypeToResourceId(Marker.categoryToMarkerType(category)) } } \ No newline at end of file -- cgit v1.2.3