From 41aad20b7ebe24f318476c7f3fdb6be744dd5b9d Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 14:09:38 -0600 Subject: Fixed focusOn not respecting max zoom, and added zoom level 21 to MapCalculus --- .../src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt | 1 + 1 file changed, 1 insertion(+) (limited to 'shared/src') diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt index 118c117..b1a6444 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt @@ -31,6 +31,7 @@ class MapCalculus { 19 -> 1066.36479193 20 -> 533.182395965 21 -> 266.5911979825 + 22 -> 133.29559899125 else -> null } } -- cgit v1.2.3 From 16b614d6f3fcc88924e79ac3a1bffef538b09e8b Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 16:11:47 -0600 Subject: Added hourmeter field --- .../android/details/information/UnitInformationFragment.kt | 8 ++++++++ .../TrackerMap/android/devices/UnitRenderData.kt | 14 ++++++++++++++ androidApp/src/main/res/drawable/position_hourmeter.xml | 10 ++++++++++ androidApp/src/main/res/values-es-rMX/strings.xml | 1 + androidApp/src/main/res/values/strings.xml | 1 + .../kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt | 5 ++++- 6 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 androidApp/src/main/res/drawable/position_hourmeter.xml (limited to 'shared/src') diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt index 0c3577e..6c15ae4 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt @@ -13,6 +13,7 @@ import androidx.core.widget.TextViewCompat import androidx.fragment.app.Fragment import com.google.android.material.button.MaterialButton import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.serialization.json.longOrNull import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitDetailsInformationBinding import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter @@ -94,6 +95,13 @@ class UnitInformationFragment : Fragment() { unit.position?.address?.let { address -> details.add(getString(R.string.unit_info_address) to address) } + unit.position?.attributes?.get("hours")?.longOrNull?.let { + if (it > 0) { + details.add( + getString(R.string.unit_hourmeter) to Formatter.formatHours(it) + ) + } + } unit.position?.protocol?.let { protocol -> details.add(getString(R.string.unit_info_protocol) to protocol) } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt index beeba6f..c7999de 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/UnitRenderData.kt @@ -12,6 +12,7 @@ import android.widget.TextView import androidx.cardview.widget.CardView import androidx.core.content.ContextCompat import com.zerobranch.layout.SwipeLayout +import kotlinx.serialization.json.longOrNull import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.map.MarkerTransformations import mx.trackermap.TrackerMap.client.models.UnitInformation @@ -128,6 +129,19 @@ class UnitRenderData { ) } + /* Hourmeter */ + position.attributes["hours"]?.longOrNull?.let { + if (it > 0) { + details.add( + Triple( + R.drawable.position_hourmeter, + Formatter.formatHours(it), + context.getString(R.string.unit_hourmeter) + ) + ) + } + } + /* Date time */ position.fixTime?.let { fixTime -> details.add( diff --git a/androidApp/src/main/res/drawable/position_hourmeter.xml b/androidApp/src/main/res/drawable/position_hourmeter.xml new file mode 100644 index 0000000..52ff427 --- /dev/null +++ b/androidApp/src/main/res/drawable/position_hourmeter.xml @@ -0,0 +1,10 @@ + + + diff --git a/androidApp/src/main/res/values-es-rMX/strings.xml b/androidApp/src/main/res/values-es-rMX/strings.xml index 5e41768..f843c29 100644 --- a/androidApp/src/main/res/values-es-rMX/strings.xml +++ b/androidApp/src/main/res/values-es-rMX/strings.xml @@ -31,6 +31,7 @@ Nombre del conductor Velocidad Dirección de la última posición + Horómetro Fecha y hora de la última posición Animal diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 11c914f..60547d3 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -44,6 +44,7 @@ Driver name Speed Last position address + Hourmeter Last position datetime Animal diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt index 878418e..c113bef 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt @@ -1,7 +1,6 @@ package mx.trackermap.TrackerMap.utils import kotlinx.datetime.* -import kotlin.math.round class Formatter { companion object { @@ -25,5 +24,9 @@ class Formatter { } } } + + fun formatHours(millis: Long): String { + return "${millis / (1000 * 60 * 60)} hr" + } } } \ No newline at end of file -- cgit v1.2.3 From 21e16e27f047053582d8b0c722feedf3c8badebe Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 17:57:14 -0600 Subject: Refactored report types into commonMain, added support for event report types in controller and API --- .../android/details/reports/UnitReportsFragment.kt | 42 ++++++------ .../details/reports/UnitReportsViewModel.kt | 20 +++++- .../TrackerMap/client/apis/ReportsApi.kt | 10 ++- .../TrackerMap/client/models/EventInformation.kt | 79 +++++++++++++++++++++- .../TrackerMap/controllers/ReportController.kt | 14 ++-- 5 files changed, 136 insertions(+), 29 deletions(-) (limited to 'shared/src') diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt index 3b3570b..4c87b31 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt @@ -205,26 +205,28 @@ class UnitReportsFragment : Fragment() { datetimeText.text = Formatter.formatDate(it) } event.event.type?.let { - eventText.text = getString(when (it) { - "deviceOnline" -> R.string.event_device_online - "deviceUnknown" -> R.string.event_device_unknown - "deviceOffline" -> R.string.event_device_offline - "deviceInactive" -> R.string.event_device_inactive - "deviceMoving" -> R.string.event_device_moving - "deviceStopped" -> R.string.event_device_stopped - "deviceOverspeed" -> R.string.event_device_overspeed - "deviceFuelDrop" -> R.string.event_device_fuel_drop - "commandResult" -> R.string.event_command_result - "geofenceEnter" -> R.string.event_geofence_enter - "geofenceExit" -> R.string.event_geofence_exit - "alarm" -> R.string.event_alarm - "ignitionOn" -> R.string.event_ignition_on - "ignitionOff" -> R.string.event_ignition_off - "maintenance" -> R.string.event_maintenance - "textMessage" -> R.string.event_text_message - "driverChanged" -> R.string.event_driver_changed - else -> R.string.event_unknown - }) + eventText.text = getString( + when (EventInformation.stringToReportType(it)) { + EventInformation.Type.DEVICE_ONLINE -> R.string.event_device_online + EventInformation.Type.DEVICE_UNKNOWN -> R.string.event_device_unknown + EventInformation.Type.DEVICE_OFFLINE -> R.string.event_device_offline + EventInformation.Type.DEVICE_INACTIVE -> R.string.event_device_inactive + EventInformation.Type.DEVICE_MOVING -> R.string.event_device_moving + EventInformation.Type.DEVICE_STOPPED -> R.string.event_device_stopped + EventInformation.Type.DEVICE_OVERSPEED -> R.string.event_device_overspeed + EventInformation.Type.DEVICE_FUEL_DROP -> R.string.event_device_fuel_drop + EventInformation.Type.COMMAND_RESULT -> R.string.event_command_result + EventInformation.Type.GEOFENCE_ENTER -> R.string.event_geofence_enter + EventInformation.Type.GEOFENCE_EXIT -> R.string.event_geofence_exit + EventInformation.Type.ALARM -> R.string.event_alarm + EventInformation.Type.IGNITION_ON -> R.string.event_ignition_on + EventInformation.Type.IGNITION_OFF -> R.string.event_ignition_off + EventInformation.Type.MAINTENANCE -> R.string.event_maintenance + EventInformation.Type.TEXT_MESSAGE -> R.string.event_text_message + EventInformation.Type.DRIVER_CHANGED -> R.string.event_driver_changed + EventInformation.Type.UNKNOWN -> R.string.event_unknown + else -> R.string.event_unknown + }) } event.geofence?.let { geofenceText.text = it.name diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt index 865f096..62ac4f2 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.* import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch +import mx.trackermap.TrackerMap.client.models.EventInformation import mx.trackermap.TrackerMap.controllers.ReportController import mx.trackermap.TrackerMap.utils.ReportDates import org.koin.core.component.KoinComponent @@ -84,7 +85,24 @@ class UnitReportsViewModel( deviceId = id, reportType = _reportType.value, reportPeriod = _reportPeriod.value, - xlsx = xlsx + xlsx = xlsx, + eventTypes = arrayOf( + EventInformation.Type.DEVICE_INACTIVE, + EventInformation.Type.DEVICE_MOVING, + EventInformation.Type.DEVICE_STOPPED, + EventInformation.Type.DEVICE_OVERSPEED, + EventInformation.Type.DEVICE_FUEL_DROP, + EventInformation.Type.COMMAND_RESULT, + EventInformation.Type.GEOFENCE_ENTER, + EventInformation.Type.GEOFENCE_EXIT, + EventInformation.Type.ALARM, + EventInformation.Type.IGNITION_ON, + EventInformation.Type.IGNITION_OFF, + EventInformation.Type.MAINTENANCE, + EventInformation.Type.TEXT_MESSAGE, + EventInformation.Type.DRIVER_CHANGED, + EventInformation.Type.UNKNOWN + ) ) } } diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt index b4d6f74..3765207 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt @@ -36,12 +36,14 @@ class ReportsApi(basePath: String = "https://demo.traccar.org/api") : ApiClient( from: String, to: String, deviceId: Int, + type: String = "%", xlsx: Boolean = false ): Any { val localVariableQuery: MultiValueMap = mapOf( "deviceId" to toMultiValue(listOf(deviceId), "multi"), "from" to listOf(from), - "to" to listOf(to) + "to" to listOf(to), + "type" to listOf(type) ) val localVariableHeaders = mutableMapOf() if (xlsx) { @@ -79,18 +81,20 @@ class ReportsApi(basePath: String = "https://demo.traccar.org/api") : ApiClient( suspend fun reportsEventsGet( from: String, to: String, + type: String = "%", deviceId: Int, ): Array { - return reportsEventsGetBase(from, to, deviceId, false) as Array + return reportsEventsGetBase(from, to, deviceId, type, false) as Array } @Suppress("UNCHECKED_CAST") suspend fun reportsEventsGetXlsx( from: String, to: String, + type: String = "%", deviceId: Int, ): ByteArray { - return reportsEventsGetBase(from, to, deviceId, true) as ByteArray + return reportsEventsGetBase(from, to, deviceId, type, true) as ByteArray } /** 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) = + 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 + } + } +} diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt index 2151331..8a7f527 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt @@ -36,7 +36,8 @@ class ReportController( deviceId: Int, reportType: ReportType?, reportPeriod: ReportDates.ReportPeriod?, - xlsx: Boolean = false + xlsx: Boolean = false, + eventTypes: Array = arrayOf() ) { if (reportType == null || reportPeriod == null) { return @@ -54,7 +55,7 @@ class ReportController( GlobalScope.launch { when (reportType) { ReportType.POSITIONS -> fetchPositions(deviceId, previousDate, currentDate, xlsx) - ReportType.EVENTS -> fetchEvents(deviceId, previousDate, currentDate, xlsx) + ReportType.EVENTS -> fetchEvents(deviceId, previousDate, currentDate, eventTypes, xlsx) ReportType.STOPS -> fetchStops(deviceId, previousDate, currentDate, xlsx) } } @@ -84,13 +85,16 @@ class ReportController( deviceId: Int, from: String, to: String, + types: Array, xlsx: Boolean ) { Log.d("UnitReportsVM", "Fetching events") if (!xlsx) { val positionsResult = reportsApi.reportsRouteGet(from, to, deviceId) - val eventsResult = reportsApi.reportsEventsGet(from, to, deviceId) + val eventsResult = reportsApi.reportsEventsGet( + from, to, EventInformation.reportTypesToString(types), deviceId + ) val geofencesResult = geofencesApi.geofencesGet(all = true) val result = mutableListOf() @@ -105,7 +109,9 @@ class ReportController( Log.d("UnitReportsVM", "Events report: $result") reportFlow.value = Report.EventsReport(result.toTypedArray()) } else { - val result = reportsApi.reportsEventsGetXlsx(from, to, deviceId) + val result = reportsApi.reportsEventsGetXlsx( + from, to, EventInformation.reportTypesToString(types), deviceId + ) Log.d("UnitReportsVM", "Events report: $result") reportFlow.value = Report.XlsxReport(result) -- cgit v1.2.3