Skip to content

Colota - Android GPS Location tracker

feat: show WiFi/motionless pause reason in dashboard map banner

Max Dietrichb7a541058b0a
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.kt
index bfcbdeb0..16e9fb91 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
@@ -260,14 +260,15 @@ class LocationServiceModule(reactContext: ReactApplicationContext) :
/** Emits pause zone entry/exit events for the JS geofence UI. */
@JvmStatic
- fun sendPauseZoneEvent(entered: Boolean, zoneName: String?): Boolean {
+ fun sendPauseZoneEvent(entered: Boolean, zoneName: String?, pauseReason: String? = null): Boolean {
val context = reactContextRef.get() ?: return false
if (!context.hasActiveCatalystInstance()) return false
-
+
return try {
val params = Arguments.createMap().apply {
putBoolean("entered", entered)
putString("zoneName", zoneName)
+ putString("pauseReason", pauseReason)
}
context
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
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.kt
index 27dc22d1..aaf23a92 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
@@ -652,6 +652,7 @@ class LocationForegroundService : Service() {
isWifiPaused = true
stopLocationUpdates()
updateNotification(forceUpdate = true)
+ LocationServiceModule.sendPauseZoneEvent(true, currentZoneName, "wifi")
AppLogger.i(TAG, "Unmetered network available - WiFi pause active (networks=$unmeteredNetworkCount)")
}
}
@@ -667,6 +668,7 @@ class LocationForegroundService : Service() {
if (isWifiPaused && unmeteredNetworkCount == 0) {
isWifiPaused = false
maybeResumeGps()
+ LocationServiceModule.sendPauseZoneEvent(true, currentZoneName, if (isMotionlessPaused) "motionless" else null)
AppLogger.i(TAG, "GPS resumed after unmetered network lost")
}
}
@@ -714,6 +716,7 @@ class LocationForegroundService : Service() {
stopLocationUpdates()
motionDetector?.arm()
updateNotification(forceUpdate = true)
+ LocationServiceModule.sendPauseZoneEvent(true, currentZoneName, "motionless")
AppLogger.i(TAG, "Motionless timeout reached - GPS paused, motion sensor armed")
}
}
@@ -739,6 +742,7 @@ class LocationForegroundService : Service() {
clearMotionlessPauseState()
val geofence = currentZoneGeofence
maybeResumeGps()
+ LocationServiceModule.sendPauseZoneEvent(true, currentZoneName, if (isWifiPaused) "wifi" else null)
// Restart countdown so the zone can pause again if device becomes stationary
if (geofence?.pauseOnMotionless == true) {
startMotionlessCountdown(geofence.motionlessTimeoutMinutes)
diff --git a/apps/mobile/src/components/features/dashboard/DashboardMap.tsx b/apps/mobile/src/components/features/dashboard/DashboardMap.tsx
index 42271d88..1dac3ab5 100644
--- a/apps/mobile/src/components/features/dashboard/DashboardMap.tsx
+++ b/apps/mobile/src/components/features/dashboard/DashboardMap.tsx
@@ -22,6 +22,7 @@ type Props = {
coords: LocationCoords | null
tracking: boolean
activeZoneName: string | null
+ pauseReason: string | null
activeProfileName: string | null
}
@@ -29,7 +30,7 @@ const isValidCoords = (c: LocationCoords | null): c is LocationCoords => {
return c !== null && c.latitude !== 0 && c.longitude !== 0
}
-export function DashboardMap({ coords, tracking, activeZoneName, activeProfileName }: Props) {
+export function DashboardMap({ coords, tracking, activeZoneName, pauseReason, activeProfileName }: Props) {
const mapRef = useRef<ColotaMapRef>(null)
const { colors } = useTheme()
const [geofences, setGeofences] = useState<any[]>([])
@@ -149,7 +150,10 @@ export function DashboardMap({ coords, tracking, activeZoneName, activeProfileNa
{showMap && activeZoneName && (
<View style={[styles.statusBar, { backgroundColor: colors.warning + "DD" }]}>
- <Text style={styles.barText}>Paused in {activeZoneName}</Text>
+ <Text style={styles.barText}>
+ Paused in {activeZoneName}
+ {pauseReason === "wifi" ? " - WiFi" : pauseReason === "motionless" ? " - Motionless" : ""}
+ </Text>
</View>
)}
diff --git a/apps/mobile/src/components/features/dashboard/__tests__/DashboardMap.test.tsx b/apps/mobile/src/components/features/dashboard/__tests__/DashboardMap.test.tsx
index a876f33d..6b184b06 100644
--- a/apps/mobile/src/components/features/dashboard/__tests__/DashboardMap.test.tsx
+++ b/apps/mobile/src/components/features/dashboard/__tests__/DashboardMap.test.tsx
@@ -70,6 +70,7 @@ describe("DashboardMap info cards", () => {
coords: validCoords,
tracking: true,
activeZoneName: null as string | null,
+ pauseReason: null as string | null,
activeProfileName: null as string | null
}
diff --git a/apps/mobile/src/screens/DashboardScreen.tsx b/apps/mobile/src/screens/DashboardScreen.tsx
index d2d14bc7..2ae9f346 100644
--- a/apps/mobile/src/screens/DashboardScreen.tsx
+++ b/apps/mobile/src/screens/DashboardScreen.tsx
@@ -39,6 +39,7 @@ export function DashboardScreen({ navigation }: ScreenProps) {
const prevStats = useRef(stats)
const [currentPauseZone, setCurrentPauseZone] = useState<string | null>(null)
+ const [pauseReason, setPauseReason] = useState<string | null>(null)
const [scrollEnabled, setScrollEnabled] = useState(true)
// Animation for button
@@ -130,11 +131,13 @@ export function DashboardScreen({ navigation }: ScreenProps) {
useEffect(() => {
const pauseZoneListener = DeviceEventEmitter.addListener(
"onPauseZoneChange",
- (data: { entered: boolean; zoneName: string | null }) => {
+ (data: { entered: boolean; zoneName: string | null; pauseReason: string | null }) => {
if (data.entered) {
setCurrentPauseZone(data.zoneName)
+ setPauseReason(data.pauseReason)
} else {
setCurrentPauseZone(null)
+ setPauseReason(null)
}
}
)
@@ -161,6 +164,7 @@ export function DashboardScreen({ navigation }: ScreenProps) {
coords={coords}
tracking={tracking}
activeZoneName={currentPauseZone}
+ pauseReason={pauseReason}
activeProfileName={activeProfileName}
/>
</View>