Background location notification icon and a much more user friendly Location Tracking toggle

This commit is contained in:
Marc Rejohn Castillano 2026-03-09 22:57:28 +08:00
parent ccc1c62262
commit 24ecca9f06
2 changed files with 21 additions and 11 deletions

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@mipmap/ic_launcher"
android:gravity="center" />

View File

@ -360,17 +360,13 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
final schedulesAsync = ref.watch(dutySchedulesProvider); final schedulesAsync = ref.watch(dutySchedulesProvider);
final logsAsync = ref.watch(attendanceLogsProvider); final logsAsync = ref.watch(attendanceLogsProvider);
final allowTracking = profile?.allowTracking ?? false; final allowTracking = profile?.allowTracking ?? false;
// local state for optimistic switch update and to avoid flicker while the // local state for optimistic switch update. We only trust `_trackingLocal`
// profile stream lags. Once the network request completes we keep the // while a save is in flight after that the server-side value (`allowTracking`)
// local value until the provider returns the same value. // is authoritative. This ensures the toggle correctly reflects the persisted
bool effectiveTracking; // setting when the app restarts.
if (_trackingSaving) { final bool effectiveTracking = _trackingSaving
effectiveTracking = _trackingLocal; ? _trackingLocal
} else if (_trackingLocal != allowTracking) { : allowTracking;
effectiveTracking = _trackingLocal;
} else {
effectiveTracking = allowTracking;
}
if (profile == null) { if (profile == null) {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
@ -938,6 +934,11 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
lat: position.latitude, lat: position.latitude,
lng: position.longitude, lng: position.longitude,
); );
// automatically enable tracking when user checks in
try {
await ref.read(whereaboutsControllerProvider).setTracking(true);
} catch (_) {}
_trackingLocal = true; // reflect new state immediately
// Update live position immediately on check-in // Update live position immediately on check-in
ref.read(whereaboutsControllerProvider).updatePositionNow(); ref.read(whereaboutsControllerProvider).updatePositionNow();
if (mounted) { if (mounted) {
@ -1017,6 +1018,11 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
lng: position.longitude, lng: position.longitude,
justification: checkOutJustification, justification: checkOutJustification,
); );
// automatically disable tracking when user checks out
try {
await ref.read(whereaboutsControllerProvider).setTracking(false);
} catch (_) {}
_trackingLocal = false;
// Update live position immediately on check-out // Update live position immediately on check-out
ref.read(whereaboutsControllerProvider).updatePositionNow(); ref.read(whereaboutsControllerProvider).updatePositionNow();
if (mounted) { if (mounted) {