aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt9
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/shared/MarkerTransformations.kt95
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt60
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MarkerType.kt25
4 files changed, 84 insertions, 105 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 a07f054..b04bfbc 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
@@ -40,7 +40,6 @@ 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
typealias SetupCallback = () -> Unit
typealias MarkerCallback = (Int?) -> Unit
@@ -203,9 +202,9 @@ open class MapFragment : GlobeMapFragment() {
screenMarker.image = if (isReport) {
// For reports, position, start and end, icons must be different
when (i) {
- 0 -> getIcon(MarkerType.REPORT_START)
- markers.size - 1 -> getIcon(MarkerType.REPORT_END)
- else -> getIcon(MarkerType.REPORT_POSITION)
+ 0 -> getIcon(Marker.Type.REPORT_START)
+ markers.size - 1 -> getIcon(Marker.Type.REPORT_END)
+ else -> getIcon(Marker.Type.REPORT_POSITION)
}
} else getIcon(marker.type)
screenMarker.size = if (isReport) {
@@ -421,7 +420,7 @@ open class MapFragment : GlobeMapFragment() {
}
}
- private fun getIcon(markerType: MarkerType): Bitmap {
+ private fun getIcon(markerType: Marker.Type): Bitmap {
return ResourcesCompat.getDrawable(
requireActivity().resources,
MarkerTransformations.markerTypeToResourceId(markerType),
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 aacf414..2c395c8 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
@@ -19,62 +19,61 @@ package mx.trackermap.TrackerMap.android.shared
import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.client.models.Marker
-import mx.trackermap.TrackerMap.utils.MarkerType
object MarkerTransformations {
- fun markerTypeToResourceId(markerType: MarkerType): Int {
+ fun markerTypeToResourceId(markerType: Marker.Type): Int {
return when (markerType) {
- MarkerType.ANIMAL -> R.drawable.map_animal
- MarkerType.BICYCLE -> R.drawable.map_bicycle
- MarkerType.BOAT -> R.drawable.map_boat
- MarkerType.BUS -> R.drawable.map_bus
- MarkerType.CAR -> R.drawable.map_car
- MarkerType.CRANE -> R.drawable.map_crane
- MarkerType.DEFAULT -> R.drawable.map_default
- MarkerType.HELICOPTER -> R.drawable.map_helicopter
- MarkerType.MOTORCYCLE -> R.drawable.map_motorcycle
- MarkerType.OFFROAD -> R.drawable.map_offroad
- MarkerType.PERSON -> R.drawable.map_person
- MarkerType.PICKUP -> R.drawable.map_pickup
- MarkerType.PLANE -> R.drawable.map_plane
- MarkerType.SCOOTER -> R.drawable.map_scooter
- MarkerType.SHIP -> R.drawable.map_ship
- MarkerType.TRACTOR -> R.drawable.map_tractor
- MarkerType.TRAIN -> R.drawable.map_train
- MarkerType.TRAM -> R.drawable.map_tram
- MarkerType.TROLLEYBUS -> R.drawable.map_trolleybus
- MarkerType.TRUCK -> R.drawable.map_truck
- MarkerType.VAN -> R.drawable.map_van
+ Marker.Type.ANIMAL -> R.drawable.map_animal
+ Marker.Type.BICYCLE -> R.drawable.map_bicycle
+ Marker.Type.BOAT -> R.drawable.map_boat
+ Marker.Type.BUS -> R.drawable.map_bus
+ Marker.Type.CAR -> R.drawable.map_car
+ Marker.Type.CRANE -> R.drawable.map_crane
+ Marker.Type.DEFAULT -> R.drawable.map_default
+ Marker.Type.HELICOPTER -> R.drawable.map_helicopter
+ Marker.Type.MOTORCYCLE -> R.drawable.map_motorcycle
+ Marker.Type.OFFROAD -> R.drawable.map_offroad
+ Marker.Type.PERSON -> R.drawable.map_person
+ Marker.Type.PICKUP -> R.drawable.map_pickup
+ Marker.Type.PLANE -> R.drawable.map_plane
+ Marker.Type.SCOOTER -> R.drawable.map_scooter
+ Marker.Type.SHIP -> R.drawable.map_ship
+ Marker.Type.TRACTOR -> R.drawable.map_tractor
+ Marker.Type.TRAIN -> R.drawable.map_train
+ Marker.Type.TRAM -> R.drawable.map_tram
+ Marker.Type.TROLLEYBUS -> R.drawable.map_trolleybus
+ Marker.Type.TRUCK -> R.drawable.map_truck
+ Marker.Type.VAN -> R.drawable.map_van
- MarkerType.REPORT_POSITION -> R.drawable.map_report_position
- MarkerType.REPORT_START -> R.drawable.map_report_start
- MarkerType.REPORT_END -> R.drawable.map_report_end
+ Marker.Type.REPORT_POSITION -> R.drawable.map_report_position
+ Marker.Type.REPORT_START -> R.drawable.map_report_start
+ Marker.Type.REPORT_END -> R.drawable.map_report_end
}
}
- fun markerTypeToStringId(markerType: MarkerType): Int {
+ fun markerTypeToStringId(markerType: Marker.Type): Int {
return when (markerType) {
- MarkerType.ANIMAL -> R.string.unit_category_animal
- MarkerType.BICYCLE -> R.string.unit_category_bicycle
- MarkerType.BOAT -> R.string.unit_category_boat
- MarkerType.BUS -> R.string.unit_category_bus
- MarkerType.CAR -> R.string.unit_category_car
- MarkerType.CRANE -> R.string.unit_category_crane
- MarkerType.DEFAULT -> R.string.unit_category_default
- MarkerType.HELICOPTER -> R.string.unit_category_helicopter
- MarkerType.MOTORCYCLE -> R.string.unit_category_motorcycle
- MarkerType.OFFROAD -> R.string.unit_category_offroad
- MarkerType.PERSON -> R.string.unit_category_person
- MarkerType.PICKUP -> R.string.unit_category_pickup
- MarkerType.PLANE -> R.string.unit_category_plane
- MarkerType.SCOOTER -> R.string.unit_category_scooter
- MarkerType.SHIP -> R.string.unit_category_ship
- MarkerType.TRACTOR -> R.string.unit_category_tractor
- MarkerType.TRAIN -> R.string.unit_category_train
- MarkerType.TRAM -> R.string.unit_category_tram
- MarkerType.TROLLEYBUS -> R.string.unit_category_trolleybus
- MarkerType.TRUCK -> R.string.unit_category_truck
- MarkerType.VAN -> R.string.unit_category_van
+ Marker.Type.ANIMAL -> R.string.unit_category_animal
+ Marker.Type.BICYCLE -> R.string.unit_category_bicycle
+ Marker.Type.BOAT -> R.string.unit_category_boat
+ Marker.Type.BUS -> R.string.unit_category_bus
+ Marker.Type.CAR -> R.string.unit_category_car
+ Marker.Type.CRANE -> R.string.unit_category_crane
+ Marker.Type.DEFAULT -> R.string.unit_category_default
+ Marker.Type.HELICOPTER -> R.string.unit_category_helicopter
+ Marker.Type.MOTORCYCLE -> R.string.unit_category_motorcycle
+ Marker.Type.OFFROAD -> R.string.unit_category_offroad
+ Marker.Type.PERSON -> R.string.unit_category_person
+ Marker.Type.PICKUP -> R.string.unit_category_pickup
+ Marker.Type.PLANE -> R.string.unit_category_plane
+ Marker.Type.SCOOTER -> R.string.unit_category_scooter
+ Marker.Type.SHIP -> R.string.unit_category_ship
+ Marker.Type.TRACTOR -> R.string.unit_category_tractor
+ Marker.Type.TRAIN -> R.string.unit_category_train
+ Marker.Type.TRAM -> R.string.unit_category_tram
+ Marker.Type.TROLLEYBUS -> R.string.unit_category_trolleybus
+ Marker.Type.TRUCK -> R.string.unit_category_truck
+ Marker.Type.VAN -> R.string.unit_category_van
else -> R.string.unit_category_default
}
}
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
index a0cc729..606d92a 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Marker.kt
@@ -1,26 +1,32 @@
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
+ val type: Type = Type.DEFAULT
) {
+ enum class Type {
+ ANIMAL, BICYCLE, BOAT, BUS, CAR, CRANE, DEFAULT, HELICOPTER, MOTORCYCLE, OFFROAD, PERSON,
+ PICKUP, PLANE, SCOOTER, SHIP, TRACTOR, TRAIN, TRAM, TROLLEYBUS, TRUCK, VAN,
+
+ REPORT_POSITION, REPORT_START, REPORT_END
+ }
+
companion object {
fun fromUnit(unit: UnitInformation): Marker? {
- if (unit.position == null || unit.position!!.latitude == null || unit.position!!.longitude == null) {
+ if (unit.position?.latitude == null || unit.position.longitude == null) {
return null
}
return Marker(
unit.position.id!!,
unit.device.name,
- unit.position.latitude!!,
- unit.position.longitude!!,
+ unit.position.latitude,
+ unit.position.longitude,
categoryToMarkerType(unit.device.category ?: "")
)
}
@@ -52,29 +58,29 @@ data class Marker(
)
}
- fun categoryToMarkerType(category: String?): MarkerType {
+ fun categoryToMarkerType(category: String?): Type {
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
+ "animal" -> Type.ANIMAL
+ "bicycle" -> Type.BICYCLE
+ "boat" -> Type.BOAT
+ "bus" -> Type.BUS
+ "car" -> Type.CAR
+ "crane" -> Type.CRANE
+ "helicopter" -> Type.HELICOPTER
+ "motorcycle" -> Type.MOTORCYCLE
+ "offroad" -> Type.OFFROAD
+ "person" -> Type.PERSON
+ "pickup" -> Type.PICKUP
+ "plane" -> Type.PLANE
+ "scooter" -> Type.SCOOTER
+ "ship" -> Type.SHIP
+ "tractor" -> Type.TRACTOR
+ "train" -> Type.TRAIN
+ "tram" -> Type.TRAM
+ "trolleybus" -> Type.TROLLEYBUS
+ "truck" -> Type.TRUCK
+ "van" -> Type.VAN
+ else -> Type.DEFAULT
}
}
}
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MarkerType.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MarkerType.kt
deleted file mode 100644
index fc2abf1..0000000
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MarkerType.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * TrackerMap
- * Copyright (C) 2021-2022 Iván Ávalos <avalos@disroot.org>, Henoch Ojeda <imhenoch@protonmail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package mx.trackermap.TrackerMap.utils
-
-enum class MarkerType {
- ANIMAL, BICYCLE, BOAT, BUS, CAR, CRANE, DEFAULT, HELICOPTER, MOTORCYCLE, OFFROAD, PERSON,
- PICKUP, PLANE, SCOOTER, SHIP, TRACTOR, TRAIN, TRAM, TROLLEYBUS, TRUCK, VAN,
-
- REPORT_POSITION, REPORT_START, REPORT_END
-} \ No newline at end of file