From edbd2c7713a0ba4e7e7a3ba6d59d16861ea4eb23 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 17 Sep 2023 21:56:55 -0600 Subject: - [shared] Implement network state monitoring - [android] UI reacts to network state - [ios] UI reacts to network state --- shared/src/androidMain/AndroidManifest.xml | 4 +- .../TrackerMap/controllers/NetworkController.kt | 55 ++++++++++++++++++++++ .../TrackerMap/client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/SessionManager.kt | 2 + .../TrackerMap/controllers/NetworkController.kt | 8 ++++ .../TrackerMap/controllers/SessionController.kt | 18 ++----- .../TrackerMap/controllers/NetworkController.kt | 25 ++++++++++ 7 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 shared/src/androidMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt create mode 100644 shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt create mode 100644 shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt (limited to 'shared') diff --git a/shared/src/androidMain/AndroidManifest.xml b/shared/src/androidMain/AndroidManifest.xml index 568741e..f0f34af 100644 --- a/shared/src/androidMain/AndroidManifest.xml +++ b/shared/src/androidMain/AndroidManifest.xml @@ -1,2 +1,4 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/shared/src/androidMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt b/shared/src/androidMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt new file mode 100644 index 0000000..eecd7de --- /dev/null +++ b/shared/src/androidMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt @@ -0,0 +1,55 @@ +package mx.trackermap.TrackerMap.controllers + +import android.content.Context +import android.net.ConnectivityManager +import android.net.Network +import android.net.NetworkCapabilities +import android.net.NetworkRequest +import android.os.Build +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import mx.trackermap.TrackerMap.Injectable + +actual class NetworkController(context: Context): Injectable { + private val networkRequest = NetworkRequest.Builder().build() + private val connectivityManager: ConnectivityManager + private val _networkAvailable = MutableStateFlow(null) + actual val networkAvailable = _networkAvailable.asStateFlow() + + private val networkCallback = object: ConnectivityManager.NetworkCallback() { + override fun onCapabilitiesChanged( + network: Network, + networkCapabilities: NetworkCapabilities + ) { + super.onCapabilitiesChanged(network, networkCapabilities) + _networkAvailable.value = checkNetworkAccess(networkCapabilities) + } + + override fun onLost(network: Network) { + super.onLost(network) + _networkAvailable.value = false + } + } + + init { + connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + _networkAvailable.value = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + checkNetworkAccess(connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)) + } else { + connectivityManager.activeNetworkInfo?.isConnected == true + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + connectivityManager.registerDefaultNetworkCallback(networkCallback) + } else { + connectivityManager.registerNetworkCallback(networkRequest, networkCallback) + } + } + + private fun checkNetworkAccess(capabilities: NetworkCapabilities?) = + capabilities != null + && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) + && if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED) + } else true +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt index 937b2dd..8238f7e 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt @@ -168,7 +168,7 @@ open class ApiClient( } } - if (sessionManager.token.isNotEmpty()) { + if (sessionManager.hasSession) { request.headers["Cookie"] = sessionManager.token } val response: HttpResponse = client.request(request) diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt index caf2da1..71ae5d0 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt @@ -28,6 +28,8 @@ class SessionManager( settings[ACCESS_TOKEN_KEY] = token } + val hasSession: Boolean get() = settings.hasKey(ACCESS_TOKEN_KEY) + fun clearSession() { settings.remove(ACCESS_TOKEN_KEY) settings.remove(SERVER_URL_KEY) diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt new file mode 100644 index 0000000..08dcc87 --- /dev/null +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt @@ -0,0 +1,8 @@ +package mx.trackermap.TrackerMap.controllers + +import kotlinx.coroutines.flow.StateFlow +import mx.trackermap.TrackerMap.Injectable + +expect class NetworkController: Injectable { + val networkAvailable: StateFlow +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt index a63bba2..5cfdf96 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt @@ -25,13 +25,15 @@ import kotlinx.serialization.json.JsonPrimitive import mx.trackermap.TrackerMap.Injectable import mx.trackermap.TrackerMap.client.apis.SessionApi import mx.trackermap.TrackerMap.client.apis.UsersApi +import mx.trackermap.TrackerMap.client.infrastructure.SessionManager import mx.trackermap.TrackerMap.client.models.SessionBody import mx.trackermap.TrackerMap.client.models.User @DelicateCoroutinesApi class SessionController( + private val sessionManager: SessionManager, private val sessionApi: SessionApi, - private val usersApi: UsersApi + private val usersApi: UsersApi, ): Injectable { sealed class LoginState { object Nothing: LoginState() @@ -46,6 +48,7 @@ class SessionController( val loginStateFlow = MutableStateFlow(null) val userFlow = MutableStateFlow(null) + val hasSession: Boolean get() = sessionManager.hasSession fun getSession() { loginStateFlow.value = LoginState.Loading @@ -59,19 +62,6 @@ class SessionController( } } - fun restoreSession() { - loginStateFlow.value = LoginState.Loading - GlobalScope.launch { - try { - userFlow.value = sessionApi.sessionGet() - loginStateFlow.value = LoginState.Success - } catch (e: Exception) { - e.printStackTrace() - loginStateFlow.value = LoginState.Nothing - } - } - } - fun login(body: SessionBody) { val url = body.url.trim() val email = body.email.trim() diff --git a/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt new file mode 100644 index 0000000..d112c11 --- /dev/null +++ b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/controllers/NetworkController.kt @@ -0,0 +1,25 @@ +package mx.trackermap.TrackerMap.controllers + +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import mx.trackermap.TrackerMap.Injectable +import platform.Network.* +import platform.darwin.* + +actual class NetworkController: Injectable { + private val monitor = nw_path_monitor_create() + private val queue: dispatch_queue_t = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND.toLong(), 0u) + private val _networkAvailable = MutableStateFlow(null) + actual val networkAvailable = _networkAvailable.asStateFlow() + + private val updateHandler: nw_path_monitor_update_handler_t = { path: nw_path_t -> + val status = nw_path_get_status(path) + _networkAvailable.value = status in arrayOf(nw_path_status_satisfied, nw_path_status_satisfiable) + } + + init { + nw_path_monitor_set_update_handler(monitor, updateHandler) + nw_path_monitor_set_queue(monitor, queue) + nw_path_monitor_start(monitor) + } +} \ No newline at end of file -- cgit v1.2.3 From 9f9c6b247900a3a08e2b2322896d4f185a12d047 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Wed, 20 Sep 2023 22:32:46 -0600 Subject: - [android] Add direction arrows to reports. - [android] Use DP for marker sizes. --- .../TrackerMap/android/map/MapFragment.kt | 43 +++++++++++++++------- .../android/shared/MarkerTransformations.kt | 19 +++++++++- androidApp/src/main/res/drawable/angle_0.xml | 22 +++++++++++ androidApp/src/main/res/drawable/angle_135.xml | 22 +++++++++++ androidApp/src/main/res/drawable/angle_180.xml | 22 +++++++++++ androidApp/src/main/res/drawable/angle_225.xml | 22 +++++++++++ androidApp/src/main/res/drawable/angle_270.xml | 22 +++++++++++ androidApp/src/main/res/drawable/angle_315.xml | 22 +++++++++++ androidApp/src/main/res/drawable/angle_45.xml | 22 +++++++++++ androidApp/src/main/res/drawable/angle_90.xml | 22 +++++++++++ androidApp/src/main/res/values/dimen.xml | 4 +- .../mx/trackermap/TrackerMap/utils/ReportDates.kt | 14 +------ 12 files changed, 229 insertions(+), 27 deletions(-) create mode 100644 androidApp/src/main/res/drawable/angle_0.xml create mode 100644 androidApp/src/main/res/drawable/angle_135.xml create mode 100644 androidApp/src/main/res/drawable/angle_180.xml create mode 100644 androidApp/src/main/res/drawable/angle_225.xml create mode 100644 androidApp/src/main/res/drawable/angle_270.xml create mode 100644 androidApp/src/main/res/drawable/angle_315.xml create mode 100644 androidApp/src/main/res/drawable/angle_45.xml create mode 100644 androidApp/src/main/res/drawable/angle_90.xml (limited to 'shared') 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 4915c49..2be9bb4 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,6 +40,7 @@ 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 kotlin.math.atan2 typealias SetupCallback = () -> Unit typealias MarkerCallback = (Int?) -> Unit @@ -186,11 +187,14 @@ open class MapFragment : GlobeMapFragment() { 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 vectorWidth = requireContext().resources.getDimensionPixelSize(R.dimen.report_label_width).toFloat() + + val markerSize = requireContext().resources.getDimensionPixelSize(R.dimen.marker_size).toDouble() + val vertexSize = requireContext().resources.getDimensionPixelSize(R.dimen.vertex_size).toDouble() val vectorInfo = VectorInfo() - vectorInfo.setColor(colorReport) - vectorInfo.setLineWidth(vectorWidth ?: 20f) + vectorInfo.color = colorReport + vectorInfo.lineWidth = vectorWidth val labelInfo = LabelInfo() labelInfo.typeface = Typeface.DEFAULT_BOLD @@ -210,17 +214,17 @@ open class MapFragment : GlobeMapFragment() { when (i) { 0 -> getIcon(Marker.Type.REPORT_START) markers.size - 1 -> getIcon(Marker.Type.REPORT_END) - else -> getIcon(Marker.Type.REPORT_POSITION) + else -> getIconForDirection(points[i], points[i + 1]) } } else getIcon(marker.type) screenMarker.size = if (isReport) { // For reports, position, start and end, size must be different when (i) { - 0 -> Point2d(144.0, 144.0) - markers.size - 1 -> Point2d(144.0, 144.0) - else -> Point2d(82.0, 82.0) + 0 -> Point2d(markerSize, markerSize) + markers.size - 1 -> Point2d(markerSize, markerSize) + else -> Point2d(vertexSize, vertexSize) } - } else Point2d(144.0, 144.0) + } else Point2d(markerSize, markerSize) screenMarker.userObject = marker.id screenMarker.selectable = true @@ -292,11 +296,11 @@ open class MapFragment : GlobeMapFragment() { 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 vectorWidth = requireContext().resources.getDimensionPixelSize(R.dimen.geofence_label_width).toFloat() val vectorInfo = VectorInfo() - vectorInfo.setColor(colorFill) - vectorInfo.setLineWidth(vectorWidth ?: 4f) + vectorInfo.color = colorFill + vectorInfo.lineWidth = vectorWidth val labelInfo = LabelInfo() labelInfo.typeface = Typeface.DEFAULT_BOLD @@ -334,7 +338,7 @@ open class MapFragment : GlobeMapFragment() { } } } - } catch (e: SFException) {} + } catch (_: SFException) {} } } @@ -427,9 +431,22 @@ open class MapFragment : GlobeMapFragment() { } private fun getIcon(markerType: Marker.Type): Bitmap { + val markerSize = requireContext().resources.getDimensionPixelSize(R.dimen.marker_size) return ResourcesCompat.getDrawable( requireActivity().resources, MarkerTransformations.markerTypeToResourceId(markerType), - requireActivity().theme)!!.toBitmap(144, 144) + requireActivity().theme)!!.toBitmap(markerSize, markerSize) + } + + private fun getIconForDirection(a: Point2d, b: Point2d): Bitmap { + val vertexSize = requireContext().resources.getDimensionPixelSize(R.dimen.vertex_size) + val vectorX = b.x - a.x + val vectorY = b.y - a.y + val angleRad = atan2(vectorY, vectorX) + return ResourcesCompat.getDrawable( + requireActivity().resources, + MarkerTransformations.angleToResourceId(angleRad), + requireActivity().theme + )!!.toBitmap(vertexSize, vertexSize) } } \ No newline at end of file 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 1e5c4de..88cb422 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,6 +19,7 @@ package mx.trackermap.TrackerMap.android.shared import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.client.models.Marker +import kotlin.math.PI object MarkerTransformations { fun markerTypeToResourceId(markerType: Marker.Type): Int { @@ -51,7 +52,7 @@ object MarkerTransformations { } } - fun markerTypeToStringId(markerType: Marker.Type): Int { + private fun markerTypeToStringId(markerType: Marker.Type): Int { return when (markerType) { Marker.Type.ANIMAL -> R.string.unit_category_animal Marker.Type.BICYCLE -> R.string.unit_category_bicycle @@ -85,4 +86,20 @@ object MarkerTransformations { fun categoryToStringId(category: String?): Int { return markerTypeToStringId(Marker.categoryToMarkerType(category)) } + + private const val STEP = PI / 8 + + @OptIn(ExperimentalStdlibApi::class) + fun angleToResourceId(rad: Double): Int = when (rad) { + in 0.0 ..< STEP -> R.drawable.angle_0 + in STEP ..< STEP * 3 -> R.drawable.angle_45 + in STEP * 3 ..< STEP * 5 -> R.drawable.angle_90 + in STEP * 5 ..< STEP * 7 -> R.drawable.angle_135 + in STEP * 7 ..< STEP * 9 -> R.drawable.angle_180 + in STEP * 9 ..< STEP * 11 -> R.drawable.angle_225 + in STEP * 11 ..< STEP * 13 -> R.drawable.angle_270 + in STEP * 13 ..< STEP * 15 -> R.drawable.angle_315 + in STEP * 15 ..< STEP * 16 -> R.drawable.angle_0 + else -> angleToResourceId(PI * 2 + rad) + } } \ No newline at end of file diff --git a/androidApp/src/main/res/drawable/angle_0.xml b/androidApp/src/main/res/drawable/angle_0.xml new file mode 100644 index 0000000..53957d9 --- /dev/null +++ b/androidApp/src/main/res/drawable/angle_0.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/androidApp/src/main/res/drawable/angle_135.xml b/androidApp/src/main/res/drawable/angle_135.xml new file mode 100644 index 0000000..cd1b88e --- /dev/null +++ b/androidApp/src/main/res/drawable/angle_135.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/androidApp/src/main/res/drawable/angle_180.xml b/androidApp/src/main/res/drawable/angle_180.xml new file mode 100644 index 0000000..f3fca08 --- /dev/null +++ b/androidApp/src/main/res/drawable/angle_180.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/androidApp/src/main/res/drawable/angle_225.xml b/androidApp/src/main/res/drawable/angle_225.xml new file mode 100644 index 0000000..bd7c512 --- /dev/null +++ b/androidApp/src/main/res/drawable/angle_225.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/androidApp/src/main/res/drawable/angle_270.xml b/androidApp/src/main/res/drawable/angle_270.xml new file mode 100644 index 0000000..19db1cf --- /dev/null +++ b/androidApp/src/main/res/drawable/angle_270.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/androidApp/src/main/res/drawable/angle_315.xml b/androidApp/src/main/res/drawable/angle_315.xml new file mode 100644 index 0000000..3186db0 --- /dev/null +++ b/androidApp/src/main/res/drawable/angle_315.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/androidApp/src/main/res/drawable/angle_45.xml b/androidApp/src/main/res/drawable/angle_45.xml new file mode 100644 index 0000000..9d8b5a9 --- /dev/null +++ b/androidApp/src/main/res/drawable/angle_45.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/androidApp/src/main/res/drawable/angle_90.xml b/androidApp/src/main/res/drawable/angle_90.xml new file mode 100644 index 0000000..44dae03 --- /dev/null +++ b/androidApp/src/main/res/drawable/angle_90.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/androidApp/src/main/res/values/dimen.xml b/androidApp/src/main/res/values/dimen.xml index 8c8c5f5..4afaf23 100644 --- a/androidApp/src/main/res/values/dimen.xml +++ b/androidApp/src/main/res/values/dimen.xml @@ -29,10 +29,12 @@ 64dp + 55dp + 24dp 11sp 11sp 4dp - 10dp + 12dp 11sp diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt index 5298df3..d261d07 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt @@ -22,20 +22,10 @@ import kotlinx.datetime.* @DelicateCoroutinesApi class ReportDates { - enum class PeriodTypes { - TODAY, - LAST_24, - YESTERDAY, - THIS_WEEK, - LAST_7, - THIS_MONTH, - LAST_30, - CUSTOM - } sealed class ReportPeriod { val timezone = TimeZone.currentSystemDefault() - val clock = Clock.System + private val clock = Clock.System val instant = clock.now() val dateTime = instant.toLocalDateTime(timezone) val date = dateTime.date @@ -47,7 +37,7 @@ class ReportDates { return formatDateTime(from) to formatDateTime(to) } - fun formatDateTime(dateTime: LocalDateTime) = + private fun formatDateTime(dateTime: LocalDateTime) = dateTime.toInstant(timezone).toString() class Today : ReportPeriod() { -- cgit v1.2.3 From 6b6b521c157dfe03797b1dec64f8a615e73a8dfa Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Thu, 21 Sep 2023 20:46:37 -0600 Subject: - [ios] Add direction arrows to reports. - [ios] Use scales for marker sizes and labels. - [ios] Fix builds in Xcode 15. --- iosApp/iosApp.xcodeproj/project.pbxproj | 6 ++- .../iosApp/Assets.xcassets/Angle0.imageset/0 2.svg | 60 ++++++++++++++++++++++ .../Assets.xcassets/Angle0.imageset/Contents.json | 21 ++++++++ .../Assets.xcassets/Angle135.imageset/135.svg | 60 ++++++++++++++++++++++ .../Angle135.imageset/Contents.json | 21 ++++++++ .../Assets.xcassets/Angle180.imageset/180.svg | 60 ++++++++++++++++++++++ .../Angle180.imageset/Contents.json | 21 ++++++++ .../Assets.xcassets/Angle225.imageset/225.svg | 60 ++++++++++++++++++++++ .../Angle225.imageset/Contents.json | 21 ++++++++ .../Assets.xcassets/Angle270.imageset/270.svg | 60 ++++++++++++++++++++++ .../Angle270.imageset/Contents.json | 21 ++++++++ .../Assets.xcassets/Angle315.imageset/315.svg | 60 ++++++++++++++++++++++ .../Angle315.imageset/Contents.json | 21 ++++++++ .../iosApp/Assets.xcassets/Angle45.imageset/45.svg | 60 ++++++++++++++++++++++ .../Assets.xcassets/Angle45.imageset/Contents.json | 21 ++++++++ .../iosApp/Assets.xcassets/Angle90.imageset/90.svg | 59 +++++++++++++++++++++ .../Assets.xcassets/Angle90.imageset/Contents.json | 21 ++++++++ .../Details/Reports/UnitReportsViewModel.swift | 49 ++++++++++-------- iosApp/iosApp/Map/MapViewController.swift | 36 ++++++++----- iosApp/iosApp/Shared/Constants.swift | 19 +++++++ iosApp/iosApp/Shared/MarkerTransformations.swift | 19 +++++++ iosApp/iosApp/Units/UnitsViewModel.swift | 2 +- shared/build.gradle.kts | 5 ++ .../mx/trackermap/TrackerMap/utils/ReportDates.kt | 12 +++++ 24 files changed, 758 insertions(+), 37 deletions(-) create mode 100644 iosApp/iosApp/Assets.xcassets/Angle0.imageset/0 2.svg create mode 100644 iosApp/iosApp/Assets.xcassets/Angle0.imageset/Contents.json create mode 100644 iosApp/iosApp/Assets.xcassets/Angle135.imageset/135.svg create mode 100644 iosApp/iosApp/Assets.xcassets/Angle135.imageset/Contents.json create mode 100644 iosApp/iosApp/Assets.xcassets/Angle180.imageset/180.svg create mode 100644 iosApp/iosApp/Assets.xcassets/Angle180.imageset/Contents.json create mode 100644 iosApp/iosApp/Assets.xcassets/Angle225.imageset/225.svg create mode 100644 iosApp/iosApp/Assets.xcassets/Angle225.imageset/Contents.json create mode 100644 iosApp/iosApp/Assets.xcassets/Angle270.imageset/270.svg create mode 100644 iosApp/iosApp/Assets.xcassets/Angle270.imageset/Contents.json create mode 100644 iosApp/iosApp/Assets.xcassets/Angle315.imageset/315.svg create mode 100644 iosApp/iosApp/Assets.xcassets/Angle315.imageset/Contents.json create mode 100644 iosApp/iosApp/Assets.xcassets/Angle45.imageset/45.svg create mode 100644 iosApp/iosApp/Assets.xcassets/Angle45.imageset/Contents.json create mode 100644 iosApp/iosApp/Assets.xcassets/Angle90.imageset/90.svg create mode 100644 iosApp/iosApp/Assets.xcassets/Angle90.imageset/Contents.json create mode 100644 iosApp/iosApp/Shared/Constants.swift (limited to 'shared') diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj index 2ba44a3..f79521b 100644 --- a/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/iosApp/iosApp.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 53; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -30,6 +30,7 @@ E36A5A8627B4BFC40070DED5 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = E36A5A8527B4BFC40070DED5 /* FirebaseMessaging */; }; E36DF77B27AB740C003C561C /* MapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E36DF77927AB740C003C561C /* MapViewController.swift */; }; E36DF77C27AB740C003C561C /* MapViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E36DF77A27AB740C003C561C /* MapViewController.xib */; }; + E37F5CA92ABD26DE00EA3234 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = E37F5CA82ABD26DE00EA3234 /* Constants.swift */; }; E38F241527A242870069FC45 /* Inject.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38F241427A242870069FC45 /* Inject.swift */; }; E38F241727A242C70069FC45 /* Resolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38F241627A242C70069FC45 /* Resolver.swift */; }; E38F241C27A26DD70069FC45 /* RootViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38F241B27A26DD70069FC45 /* RootViewModel.swift */; }; @@ -104,6 +105,7 @@ E36A5A8927B4C8BB0070DED5 /* iosApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = iosApp.entitlements; sourceTree = ""; }; E36DF77927AB740C003C561C /* MapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapViewController.swift; sourceTree = ""; }; E36DF77A27AB740C003C561C /* MapViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MapViewController.xib; sourceTree = ""; }; + E37F5CA82ABD26DE00EA3234 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; E38F241427A242870069FC45 /* Inject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Inject.swift; sourceTree = ""; }; E38F241627A242C70069FC45 /* Resolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolver.swift; sourceTree = ""; }; E38F241B27A26DD70069FC45 /* RootViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewModel.swift; sourceTree = ""; }; @@ -290,6 +292,7 @@ E3B5740727F68F5F0018AFCF /* XlsxFile.swift */, E3B5740927F69F750018AFCF /* ShareViewController.swift */, E3F5F2782AB8080E008A47A7 /* OfflineBanner.swift */, + E37F5CA82ABD26DE00EA3234 /* Constants.swift */, ); path = Shared; sourceTree = ""; @@ -430,6 +433,7 @@ E33A236527A530F300DD647F /* SmallLabelStyle.swift in Sources */, E39ABC4327A4E88C00965D05 /* UnitsViewModel.swift in Sources */, E360251B27BCA8A600958B21 /* AccountViewModel.swift in Sources */, + E37F5CA92ABD26DE00EA3234 /* Constants.swift in Sources */, E34A2F4827A7878200AD8AEB /* HyperlinkText.swift in Sources */, E3B5740827F68F5F0018AFCF /* XlsxFile.swift in Sources */, 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */, diff --git a/iosApp/iosApp/Assets.xcassets/Angle0.imageset/0 2.svg b/iosApp/iosApp/Assets.xcassets/Angle0.imageset/0 2.svg new file mode 100644 index 0000000..efe814f --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle0.imageset/0 2.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + diff --git a/iosApp/iosApp/Assets.xcassets/Angle0.imageset/Contents.json b/iosApp/iosApp/Assets.xcassets/Angle0.imageset/Contents.json new file mode 100644 index 0000000..be69468 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle0.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "0 2.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Assets.xcassets/Angle135.imageset/135.svg b/iosApp/iosApp/Assets.xcassets/Angle135.imageset/135.svg new file mode 100644 index 0000000..a7c625b --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle135.imageset/135.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + diff --git a/iosApp/iosApp/Assets.xcassets/Angle135.imageset/Contents.json b/iosApp/iosApp/Assets.xcassets/Angle135.imageset/Contents.json new file mode 100644 index 0000000..1e01d4c --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle135.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "135.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Assets.xcassets/Angle180.imageset/180.svg b/iosApp/iosApp/Assets.xcassets/Angle180.imageset/180.svg new file mode 100644 index 0000000..4df8b75 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle180.imageset/180.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + diff --git a/iosApp/iosApp/Assets.xcassets/Angle180.imageset/Contents.json b/iosApp/iosApp/Assets.xcassets/Angle180.imageset/Contents.json new file mode 100644 index 0000000..cca2175 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle180.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "180.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Assets.xcassets/Angle225.imageset/225.svg b/iosApp/iosApp/Assets.xcassets/Angle225.imageset/225.svg new file mode 100644 index 0000000..35d4080 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle225.imageset/225.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + diff --git a/iosApp/iosApp/Assets.xcassets/Angle225.imageset/Contents.json b/iosApp/iosApp/Assets.xcassets/Angle225.imageset/Contents.json new file mode 100644 index 0000000..1b49b8a --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle225.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "225.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Assets.xcassets/Angle270.imageset/270.svg b/iosApp/iosApp/Assets.xcassets/Angle270.imageset/270.svg new file mode 100644 index 0000000..23562a0 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle270.imageset/270.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + diff --git a/iosApp/iosApp/Assets.xcassets/Angle270.imageset/Contents.json b/iosApp/iosApp/Assets.xcassets/Angle270.imageset/Contents.json new file mode 100644 index 0000000..9eab5a3 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle270.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "270.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Assets.xcassets/Angle315.imageset/315.svg b/iosApp/iosApp/Assets.xcassets/Angle315.imageset/315.svg new file mode 100644 index 0000000..a501605 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle315.imageset/315.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + diff --git a/iosApp/iosApp/Assets.xcassets/Angle315.imageset/Contents.json b/iosApp/iosApp/Assets.xcassets/Angle315.imageset/Contents.json new file mode 100644 index 0000000..fed8257 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle315.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "315.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Assets.xcassets/Angle45.imageset/45.svg b/iosApp/iosApp/Assets.xcassets/Angle45.imageset/45.svg new file mode 100644 index 0000000..1ce060e --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle45.imageset/45.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + diff --git a/iosApp/iosApp/Assets.xcassets/Angle45.imageset/Contents.json b/iosApp/iosApp/Assets.xcassets/Angle45.imageset/Contents.json new file mode 100644 index 0000000..a785b47 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle45.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "45.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Assets.xcassets/Angle90.imageset/90.svg b/iosApp/iosApp/Assets.xcassets/Angle90.imageset/90.svg new file mode 100644 index 0000000..de994b5 --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle90.imageset/90.svg @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + diff --git a/iosApp/iosApp/Assets.xcassets/Angle90.imageset/Contents.json b/iosApp/iosApp/Assets.xcassets/Angle90.imageset/Contents.json new file mode 100644 index 0000000..c84e36d --- /dev/null +++ b/iosApp/iosApp/Assets.xcassets/Angle90.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "90.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift index 0132685..3a99f16 100644 --- a/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift +++ b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift @@ -19,6 +19,7 @@ import Foundation import Combine import shared +@MainActor class UnitReportsViewModel: ObservableObject { @Inject var reportController: ReportController @Inject var geofencesController: GeofencesController @@ -38,25 +39,27 @@ class UnitReportsViewModel: ObservableObject { } @Published var periodType: ReportDates.PeriodTypes = .today { didSet { - switch periodType { - case .today: - reportPeriod = ReportDates.ReportPeriodToday() - case .last24: - reportPeriod = ReportDates.ReportPeriodLast24() - case .yesterday: - reportPeriod = ReportDates.ReportPeriodYesterday() - case .thisWeek: - reportPeriod = ReportDates.ReportPeriodThisWeek() - case .last7: - reportPeriod = ReportDates.ReportPeriodLast7() - case .thisMonth: - reportPeriod = ReportDates.ReportPeriodThisMonth() - case .last30: - reportPeriod = ReportDates.ReportPeriodLast30() - case .custom: - reportPeriod = ReportDates.ReportPeriodCustom(from: nil, to: nil) - default: - reportPeriod = ReportDates.ReportPeriodToday() + Task { @MainActor in + switch periodType { + case .today: + reportPeriod = ReportDates.ReportPeriodToday() + case .last24: + reportPeriod = ReportDates.ReportPeriodLast24() + case .yesterday: + reportPeriod = ReportDates.ReportPeriodYesterday() + case .thisWeek: + reportPeriod = ReportDates.ReportPeriodThisWeek() + case .last7: + reportPeriod = ReportDates.ReportPeriodLast7() + case .thisMonth: + reportPeriod = ReportDates.ReportPeriodThisMonth() + case .last30: + reportPeriod = ReportDates.ReportPeriodLast30() + case .custom: + reportPeriod = ReportDates.ReportPeriodCustom(from: nil, to: nil) + default: + reportPeriod = ReportDates.ReportPeriodToday() + } } } } @@ -136,11 +139,15 @@ class UnitReportsViewModel: ObservableObject { } func setReport (report: ReportController.Report) { - self.report = report + Task { @MainActor in + self.report = report + } } private func setGeofences(geofences: [Int: Geofence]) { - self.geofences = geofences + Task { @MainActor in + self.geofences = geofences + } } func fetchReport(xlsx: Bool = false) { diff --git a/iosApp/iosApp/Map/MapViewController.swift b/iosApp/iosApp/Map/MapViewController.swift index a320781..f424389 100644 --- a/iosApp/iosApp/Map/MapViewController.swift +++ b/iosApp/iosApp/Map/MapViewController.swift @@ -224,14 +224,14 @@ class OurMaplyViewController: MaplyViewController { Float(marker.latitude)) } - let fontSize = 11.0 + let fontSize = Constants.markerLabelTextSize let colorReport = UIColor(red: 0.0, green: 0.5, blue: 0.0, alpha: 1.0) let colorLabel = UIColor.darkGray let colorLabelOutline = UIColor.white let vectorDesc: [AnyHashable : Any] = [ kMaplyColor: colorReport, - kMaplyVecWidth: 12.0, + kMaplyVecWidth: Constants.reportLineWidth, kMaplyWideVecImpl: kMaplyWideVecImplPerf ] @@ -248,26 +248,26 @@ class OurMaplyViewController: MaplyViewController { screenMarker.layoutImportance = .greatestFiniteMagnitude screenMarker.loc = MaplyCoordinateMakeWithDegrees(Float(marker.longitude), Float(marker.latitude)) - var type: Marker.Type_ = .default_ + var image: UIImage if isReport { // For reports, position, start and end icons must be different switch i { - case markers.startIndex: type = .reportStart - case markers.endIndex - 1: type = .reportEnd - default: type = .reportPosition + case markers.startIndex: image = getIcon(markerType: .reportStart) + case markers.endIndex - 1: image = getIcon(markerType: .reportEnd) + default: image = getIcon(forDirection: points[i], to: points[i + 1]) } } else { - type = marker.type + image = getIcon(markerType: marker.type) } - screenMarker.image = getIcon(markerType: type) + screenMarker.image = image - var size = 50.0 + var size = Constants.markerSize if isReport { // For reports, position, start and end sizes must be different switch i { - case markers.startIndex: size = 40.0 - case markers.endIndex - 1: size = 40.0 - default: size = 22.0 + case markers.startIndex: size = Constants.markerSize + case markers.endIndex - 1: size = Constants.markerSize + default: size = Constants.vertexsize } } screenMarker.size = CGSize(width: size, height: size) @@ -342,14 +342,14 @@ class OurMaplyViewController: MaplyViewController { func display(geofences: [Geofence]) { clear(geofences: true) - let fontSize = 11.0 + let fontSize = Constants.geofenceLabelTextSize let colorFill = UIColor(red: 0.10, green: 0.46, blue: 0.82, alpha: 1.00) let colorLabel = UIColor(red: 0.10, green: 0.46, blue: 0.82, alpha: 1.00) let colorLabelOutline = UIColor.white let vectorDesc: [AnyHashable : Any] = [ kMaplyColor: colorFill, - kMaplyVecWidth: 12.0, + kMaplyVecWidth: Constants.geofenceLineWidth, kMaplyWideVecImpl: kMaplyWideVecImplPerf ] @@ -439,4 +439,12 @@ class OurMaplyViewController: MaplyViewController { return UIImage(named: MarkerTransformations .markerTypeToImageName(markerType: markerType))! } + + private func getIcon(forDirection a: MaplyCoordinate, to b: MaplyCoordinate) -> UIImage { + let vectorX = b.x - a.x + let vectorY = b.y - a.y + let angleRad = atan2(vectorY, vectorX) + return UIImage(named: MarkerTransformations + .angleToImageName(rad: angleRad))! + } } diff --git a/iosApp/iosApp/Shared/Constants.swift b/iosApp/iosApp/Shared/Constants.swift new file mode 100644 index 0000000..de82b0b --- /dev/null +++ b/iosApp/iosApp/Shared/Constants.swift @@ -0,0 +1,19 @@ +// +// Constants.swift +// iosApp +// +// Created by Ivan Avalos on 21/09/23. +// Copyright © 2023 orgName. All rights reserved. +// + +import Foundation +import UIKit + +struct Constants { + static var markerSize = 14.0 * UIScreen.main.scale + static var vertexsize = 8.0 * UIScreen.main.scale + static var markerLabelTextSize = UIFont.smallSystemFontSize + static var geofenceLabelTextSize = UIFont.smallSystemFontSize + static var geofenceLineWidth = 4.0 * UIScreen.main.scale + static var reportLineWidth = 4.0 * UIScreen.main.scale +} diff --git a/iosApp/iosApp/Shared/MarkerTransformations.swift b/iosApp/iosApp/Shared/MarkerTransformations.swift index 1e51907..c496d76 100644 --- a/iosApp/iosApp/Shared/MarkerTransformations.swift +++ b/iosApp/iosApp/Shared/MarkerTransformations.swift @@ -50,4 +50,23 @@ class MarkerTransformations { } return imageName } + + static let STEP = Float.pi / 8 + + static func angleToImageName(rad: Float) -> String { + var imageName: String + switch rad { + case 0.0 ..< STEP: imageName = "Angle0" + case STEP ..< STEP * 3: imageName = "Angle45" + case STEP * 3 ..< STEP * 5: imageName = "Angle90" + case STEP * 5 ..< STEP * 7: imageName = "Angle135" + case STEP * 7 ..< STEP * 9: imageName = "Angle180" + case STEP * 9 ..< STEP * 11: imageName = "Angle225" + case STEP * 11 ..< STEP * 13: imageName = "Angle270" + case STEP * 13 ..< STEP * 15: imageName = "Angle315" + case STEP * 15 ..< STEP * 16: imageName = "Angle0" + default: imageName = angleToImageName(rad: Float.pi * 2 + rad) + } + return imageName + } } diff --git a/iosApp/iosApp/Units/UnitsViewModel.swift b/iosApp/iosApp/Units/UnitsViewModel.swift index b12291e..52e0c39 100644 --- a/iosApp/iosApp/Units/UnitsViewModel.swift +++ b/iosApp/iosApp/Units/UnitsViewModel.swift @@ -106,8 +106,8 @@ class UnitsViewModel: ObservableObject { print("Positions") Task { @MainActor in self.units = units + updateSelectedUnit() } - updateSelectedUnit() } private func setGeofences(geofences: [Int: Geofence]) { diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 67acdb8..6517f7f 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -19,6 +19,11 @@ kotlin { ).forEach { it.binaries.framework { baseName = "shared" + + // Fix builds in Xcode 15 + if (System.getenv("XCODE_VERSION_MAJOR") == "1500") { + linkerOpts += "-ld64" + } } } diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt index d261d07..9f3a142 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/ReportDates.kt @@ -23,6 +23,18 @@ import kotlinx.datetime.* @DelicateCoroutinesApi class ReportDates { + // Don't remove! Used by iOS + enum class PeriodTypes { + TODAY, + LAST_24, + YESTERDAY, + THIS_WEEK, + LAST_7, + THIS_MONTH, + LAST_30, + CUSTOM + } + sealed class ReportPeriod { val timezone = TimeZone.currentSystemDefault() private val clock = Clock.System -- cgit v1.2.3 From 3022b877d0cf9b7546c80953237c7bca5a4afa50 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 26 Sep 2023 19:32:13 -0600 Subject: [shared] Fix hourmeter for some devices --- .../trackermap/TrackerMap/client/models/UnitInformation.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'shared') diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt index 6afa350..33e85ee 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt @@ -53,5 +53,15 @@ data class UnitInformation( } ?: EngineStop.UNKNOWN } else EngineStop.UNKNOWN - fun getHourmeter() = position?.attributes?.get("hours")?.longOrNull + fun getHourmeter() = position?.attributes?.let { attrs -> + if ("io16" in attrs) { + // Minutes + attrs["io16"]?.longOrNull?.let { it * 60 * 1000 } + } else if ("hours" in attrs) { + // Milliseconds + attrs["hours"]?.longOrNull + } else { + null + } + } } \ No newline at end of file -- cgit v1.2.3