Auto-oppdater widget ved posisjonsendring #6

Closed
opened 2026-03-08 19:14:19 +01:00 by olemd · 0 comments
Owner

Update the widget to refresh automatically when the device moves significantly, using WorkManager.

Implementation

  • Add androidx.work:work-runtime-ktx dependency
  • Create a PeriodicWorkRequest (minimum 15 minutes) that:
    1. Gets last known location from LocationManager
    2. Compares with previous widget location
    3. If moved >500m, queries Room DB for nearest shelter and updates RemoteViews
  • Register worker in ShelterWidgetProvider.onEnabled(), cancel in onDisabled()
  • Store last widget location in SharedPreferences
  • Keep manual refresh button as immediate override

Why

The current widget only updates on manual tap. If the user commutes or travels, the widget shows stale data. A 15-minute background check keeps it useful without meaningful battery impact.

Update the widget to refresh automatically when the device moves significantly, using WorkManager. ## Implementation - Add `androidx.work:work-runtime-ktx` dependency - Create a `PeriodicWorkRequest` (minimum 15 minutes) that: 1. Gets last known location from LocationManager 2. Compares with previous widget location 3. If moved >500m, queries Room DB for nearest shelter and updates RemoteViews - Register worker in `ShelterWidgetProvider.onEnabled()`, cancel in `onDisabled()` - Store last widget location in SharedPreferences - Keep manual refresh button as immediate override ## Why The current widget only updates on manual tap. If the user commutes or travels, the widget shows stale data. A 15-minute background check keeps it useful without meaningful battery impact.
olemd closed this issue 2026-03-09 09:36:19 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
olemd/tilfluktsrom#6
No description provided.