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 logsAsync = ref.watch(attendanceLogsProvider);
final allowTracking = profile?.allowTracking ?? false;
// local state for optimistic switch update and to avoid flicker while the
// profile stream lags. Once the network request completes we keep the
// local value until the provider returns the same value.
bool effectiveTracking;
if (_trackingSaving) {
effectiveTracking = _trackingLocal;
} else if (_trackingLocal != allowTracking) {
effectiveTracking = _trackingLocal;
} else {
effectiveTracking = allowTracking;
}
// local state for optimistic switch update. We only trust `_trackingLocal`
// while a save is in flight after that the server-side value (`allowTracking`)
// is authoritative. This ensures the toggle correctly reflects the persisted
// setting when the app restarts.
final bool effectiveTracking = _trackingSaving
? _trackingLocal
: allowTracking;
if (profile == null) {
return const Center(child: CircularProgressIndicator());
@ -938,6 +934,11 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
lat: position.latitude,
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
ref.read(whereaboutsControllerProvider).updatePositionNow();
if (mounted) {
@ -1017,6 +1018,11 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
lng: position.longitude,
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
ref.read(whereaboutsControllerProvider).updatePositionNow();
if (mounted) {