aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-16 17:57:14 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-16 17:57:14 -0600
commit21e16e27f047053582d8b0c722feedf3c8badebe (patch)
tree07f1e6844cea6cc42f2a7f5eaa57d4f3b57e0ea2 /shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models
parentf030f9cc2327fa3825964a9b06430ae5881ebcba (diff)
downloadetbsa-trackermap-mobile-21e16e27f047053582d8b0c722feedf3c8badebe.tar.gz
etbsa-trackermap-mobile-21e16e27f047053582d8b0c722feedf3c8badebe.tar.bz2
etbsa-trackermap-mobile-21e16e27f047053582d8b0c722feedf3c8badebe.zip
Refactored report types into commonMain, added support for event report types in controller and API
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt79
1 files changed, 78 insertions, 1 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt
index c4f91fe..befd8f1 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt
@@ -4,4 +4,81 @@ data class EventInformation(
val event: Event,
val position: Position?,
val geofence: Geofence?
-)
+) {
+ enum class Type {
+ ALL,
+ DEVICE_ONLINE,
+ DEVICE_UNKNOWN,
+ DEVICE_OFFLINE,
+ DEVICE_INACTIVE,
+ DEVICE_MOVING,
+ DEVICE_STOPPED,
+ DEVICE_OVERSPEED,
+ DEVICE_FUEL_DROP,
+ COMMAND_RESULT,
+ GEOFENCE_ENTER,
+ GEOFENCE_EXIT,
+ ALARM,
+ IGNITION_ON,
+ IGNITION_OFF,
+ MAINTENANCE,
+ TEXT_MESSAGE,
+ DRIVER_CHANGED,
+ UNKNOWN
+ }
+
+ companion object {
+ fun reportTypeToString(t: Type) =
+ when (t) {
+ Type.ALL -> "%"
+ Type.DEVICE_ONLINE -> "deviceOnline"
+ Type.DEVICE_UNKNOWN -> "deviceUnknown"
+ Type.DEVICE_OFFLINE -> "deviceOffline"
+ Type.DEVICE_INACTIVE -> "deviceInactive"
+ Type.DEVICE_MOVING -> "deviceMoving"
+ Type.DEVICE_STOPPED -> "deviceStopped"
+ Type.DEVICE_OVERSPEED -> "deviceOverspeed"
+ Type.DEVICE_FUEL_DROP -> "deviceFuelDrop"
+ Type.COMMAND_RESULT -> "commandResult"
+ Type.GEOFENCE_ENTER -> "geofenceEnter"
+ Type.GEOFENCE_EXIT -> "geofenceExit"
+ Type.ALARM -> "alarm"
+ Type.IGNITION_ON -> "ignitionOn"
+ Type.IGNITION_OFF -> "ignitionOff"
+ Type.MAINTENANCE -> "maintenance"
+ Type.TEXT_MESSAGE -> "textMessage"
+ Type.DRIVER_CHANGED -> "driverChanged"
+ Type.UNKNOWN -> "unknown"
+ }
+
+ fun reportTypesToString(t: Array<Type>) =
+ if (t.isEmpty() || t.contains(Type.ALL)) {
+ reportTypeToString(Type.ALL)
+ } else {
+ t.joinToString(",", transform = this::reportTypeToString)
+ }
+
+ fun stringToReportType(s: String) =
+ when (s) {
+ "deviceOnline" -> Type.DEVICE_ONLINE
+ "deviceUnknown" -> Type.DEVICE_UNKNOWN
+ "deviceOffline" -> Type.DEVICE_OFFLINE
+ "deviceInactive" -> Type.DEVICE_INACTIVE
+ "deviceMoving" -> Type.DEVICE_MOVING
+ "deviceStopped" -> Type.DEVICE_STOPPED
+ "deviceOverspeed" -> Type.DEVICE_OVERSPEED
+ "deviceFuelDrop" -> Type.DEVICE_FUEL_DROP
+ "commandResult" -> Type.COMMAND_RESULT
+ "geofenceEnter" -> Type.GEOFENCE_ENTER
+ "geofenceExit" -> Type.GEOFENCE_EXIT
+ "alarm" -> Type.ALARM
+ "ignitionOn" -> Type.IGNITION_ON
+ "ignitionOff" -> Type.IGNITION_OFF
+ "maintenance" -> Type.MAINTENANCE
+ "textMessage" -> Type.TEXT_MESSAGE
+ "driverChanged" -> Type.DRIVER_CHANGED
+ "unknown" -> Type.UNKNOWN
+ else -> Type.UNKNOWN
+ }
+ }
+}