Colota - Android GPS Location tracker
fix: show pause reason (WiFi/motionless) on dashboard map when app resumes
Max Dietrich595bc890fe56
diff --git a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.ktindex 6b6afa64..f319ced3 100644--- a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt+++ b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt@@ -703,7 +703,22 @@ class LocationServiceModule(reactContext: ReactApplicationContext) :val zone = withContext(Dispatchers.IO) {geofenceHelper.getPauseZone(loc)}- promise.resolve(zone?.name)+ if (zone == null) {+ promise.resolve(null)+ } else {+ val db = DatabaseHelper.getInstance(reactApplicationContext)+ val settings = withContext(Dispatchers.IO) { db.loadSettings() }+ val reason = when {+ settings["pause_zone_wifi_active"]?.toBoolean() == true -> "wifi"+ settings["pause_zone_motionless_active"]?.toBoolean() == true -> "motionless"+ else -> null+ }+ val result = Arguments.createMap().apply {+ putString("zoneName", zone.name)+ putString("pauseReason", reason)+ }+ promise.resolve(result)+ }} catch (e: Exception) {AppLogger.e(TAG, "Pause zone check failed", e)promise.resolve(null)diff --git a/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt b/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.ktindex 7641d0d4..fc70c43d 100644--- a/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt+++ b/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt@@ -638,7 +638,6 @@ class LocationForegroundService : Service() {dbHelper.saveSetting("pause_zone_name", "")val wasWifiPaused = isWifiPausedval wasMotionlessPaused = isMotionlessPaused- isWifiPaused = falseunregisterWifiPause()cancelMotionlessCountdown()clearMotionlessPauseState()@@ -683,6 +682,7 @@ class LocationForegroundService : Service() {unmeteredNetworkCount++if (!isWifiPaused) {isWifiPaused = true+ dbHelper.saveSetting("pause_zone_wifi_active", "true")stopLocationUpdates()updateNotification(forceUpdate = true)LocationServiceModule.sendPauseZoneEvent(true, currentZoneName, "wifi")@@ -700,6 +700,7 @@ class LocationForegroundService : Service() {withContext(Dispatchers.Main) {if (isWifiPaused && unmeteredNetworkCount == 0) {isWifiPaused = false+ dbHelper.saveSetting("pause_zone_wifi_active", "false")maybeResumeGps()LocationServiceModule.sendPauseZoneEvent(true, currentZoneName, if (isMotionlessPaused) "motionless" else null)AppLogger.i(TAG, "GPS resumed after unmetered network lost")@@ -722,6 +723,8 @@ class LocationForegroundService : Service() {wifiResumeJob?.cancel()wifiResumeJob = nullunmeteredNetworkCount = 0+ isWifiPaused = false+ dbHelper.saveSetting("pause_zone_wifi_active", "false")val cb = wifiCallback ?: returnwifiCallback = nulltry {@@ -990,6 +993,7 @@ class LocationForegroundService : Service() {LocationServiceModule.sendTrackingStoppedEvent(reason)dbHelper.saveSetting("tracking_enabled", "false")dbHelper.saveSetting("pause_zone_name", "")+ dbHelper.saveSetting("pause_zone_wifi_active", "false")dbHelper.saveSetting("pause_zone_motionless_active", "false")stopForeground(Service.STOP_FOREGROUND_DETACH)diff --git a/apps/mobile/src/screens/DashboardScreen.tsx b/apps/mobile/src/screens/DashboardScreen.tsxindex e5295d7e..1d3e28a0 100644--- a/apps/mobile/src/screens/DashboardScreen.tsx+++ b/apps/mobile/src/screens/DashboardScreen.tsx@@ -99,11 +99,13 @@ export function DashboardScreen({ navigation }: ScreenProps) {const updatePauseZone = useCallback(async () => {try {- const zoneName = await NativeLocationService.checkCurrentPauseZone()- setCurrentPauseZone(zoneName)+ const result = await NativeLocationService.checkCurrentPauseZone()+ setCurrentPauseZone(result?.zoneName ?? null)+ setPauseReason(result?.pauseReason ?? null)} catch (err) {logger.error("[Dashboard] Failed to update pause zone:", err)setCurrentPauseZone(null)+ setPauseReason(null)}}, [])diff --git a/apps/mobile/src/screens/GeofenceScreen.tsx b/apps/mobile/src/screens/GeofenceScreen.tsxindex bff79b85..19a9db8f 100644--- a/apps/mobile/src/screens/GeofenceScreen.tsx+++ b/apps/mobile/src/screens/GeofenceScreen.tsx@@ -93,8 +93,8 @@ export function GeofenceScreen({ navigation }: ScreenProps) {useEffect(() => {const checkPauseZone = async () => {try {- const zoneName = await NativeLocationService.checkCurrentPauseZone()- setCurrentPauseZone(zoneName)+ const result = await NativeLocationService.checkCurrentPauseZone()+ setCurrentPauseZone(result?.zoneName ?? null)} catch (err) {logger.error("[GeofenceScreen] Failed to check pause zone:", err)}diff --git a/apps/mobile/src/services/NativeLocationService.ts b/apps/mobile/src/services/NativeLocationService.tsindex e5677218..a1cb6a61 100644--- a/apps/mobile/src/services/NativeLocationService.ts+++ b/apps/mobile/src/services/NativeLocationService.ts@@ -339,9 +339,9 @@ class NativeLocationService {/*** Checks if device is currently inside a pause zone- * @returns Pause zone name or null+ * @returns Pause zone info with name and reason, or null*/- static async checkCurrentPauseZone(): Promise<string | null> {+ static async checkCurrentPauseZone(): Promise<{ zoneName: string; pauseReason: string | null } | null> {this.ensureModule()return this.safeExecute(() => LocationServiceModule.checkCurrentPauseZone(), null, "checkCurrentPauseZone failed")}