aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-29 22:19:28 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-29 22:19:28 -0600
commit4ff1b200f12fc335abd1f0f6117649f50b3968ce (patch)
treed013b45e6f022766d9a9d80aa8b90646561271d5 /shared/src/commonMain/kotlin/mx
parent65ea295e0c013d143552988911d44a84876f4f30 (diff)
downloadetbsa-trackermap-mobile-4ff1b200f12fc335abd1f0f6117649f50b3968ce.tar.gz
etbsa-trackermap-mobile-4ff1b200f12fc335abd1f0f6117649f50b3968ce.tar.bz2
etbsa-trackermap-mobile-4ff1b200f12fc335abd1f0f6117649f50b3968ce.zip
Moved MapFragment.Marker and MarkerTransformations functions to Marker model in shared module
Diffstat (limited to 'shared/src/commonMain/kotlin/mx')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt81
1 files changed, 81 insertions, 0 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt
new file mode 100644
index 0000000..a0cc729
--- /dev/null
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt
@@ -0,0 +1,81 @@
+package mx.trackermap.TrackerMap.client.models
+
+import android.util.Log
+import mx.trackermap.TrackerMap.utils.MarkerType
+
+data class Marker(
+ val id: Int,
+ val name: String,
+ val latitude: Double,
+ val longitude: Double,
+ val type: MarkerType = MarkerType.DEFAULT
+) {
+ companion object {
+ fun fromUnit(unit: UnitInformation): Marker? {
+ if (unit.position == null || unit.position!!.latitude == null || unit.position!!.longitude == null) {
+ return null
+ }
+
+ return Marker(
+ unit.position.id!!,
+ unit.device.name,
+ unit.position.latitude!!,
+ unit.position.longitude!!,
+ categoryToMarkerType(unit.device.category ?: "")
+ )
+ }
+
+ fun fromPosition(position: Position): Marker? {
+ if (position.latitude == null || position.longitude == null) {
+ return null
+ }
+
+ return Marker(
+ position.id!!,
+ "",
+ position.latitude,
+ position.longitude
+ )
+ }
+
+ fun fromStop(stop: Stop): Marker? {
+ Log.d("MarkerTransformations", "stopToMarker($stop)")
+ if (stop.latitude == null || stop.longitude == null) {
+ return null
+ }
+
+ return Marker(
+ stop.deviceId!!,
+ stop.deviceName!!,
+ stop.latitude,
+ stop.longitude
+ )
+ }
+
+ 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
+ }
+ }
+ }
+} \ No newline at end of file