[codex] Fix widget refresh staleness#2193
Open
wolph wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce widget staleness by centralizing widget refreshes and making widget providers/factories refresh from local data after repository writes.
Changes:
- Adds
WidgetUpdaterand injects it into repositories/MainActivity. - Adds network-refresh gating for widget update broadcasts.
- Adds unit tests for widget update helpers, factories, and repository-triggered refreshes.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
Habitica/src/main/java/com/habitrpg/android/habitica/widget/WidgetUpdater.kt |
New centralized widget update helper. |
Habitica/src/main/java/com/habitrpg/android/habitica/widget/BaseWidgetProvider.kt |
Adds pre-update network refresh handling. |
Habitica/src/main/java/com/habitrpg/android/habitica/widget/TaskListFactory.kt |
Loads collection data synchronously. |
Habitica/src/main/java/com/habitrpg/android/habitica/widget/TaskListWidgetProvider.kt |
Relies on repository refresh after task scoring. |
Habitica/src/main/java/com/habitrpg/android/habitica/widget/HabitButtonWidgetService.kt |
Stops service after async rendering. |
Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/TaskRepositoryImpl.kt |
Notifies widgets after selected task writes. |
Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/UserRepositoryImpl.kt |
Notifies widgets after user retrieval. |
Habitica/src/main/java/com/habitrpg/android/habitica/modules/UserRepositoryModule.kt |
Wires WidgetUpdater into repositories. |
Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/MainActivity.kt |
Uses WidgetUpdater on pause. |
Habitica/src/test/java/com/habitrpg/android/habitica/widget/WidgetUpdaterTest.kt |
Tests widget updater behavior. |
Habitica/src/test/java/com/habitrpg/android/habitica/widget/BaseWidgetProviderTest.kt |
Tests refresh helper behavior. |
Habitica/src/test/java/com/habitrpg/android/habitica/widget/TaskListFactoryTest.kt |
Tests synchronous task factory loading. |
Habitica/src/test/java/com/habitrpg/android/habitica/data/implementation/UserRepositoryImplTest.kt |
Tests user repository widget updates. |
Habitica/src/test/java/com/habitrpg/android/habitica/data/implementation/TaskRepositoryImplTest.kt |
Extends task repository widget update tests. |
gradle/libs.versions.toml |
Adds coroutine test dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+45
to
+47
| val mirroredTasks = | ||
| userRepository.getUser() | ||
| .firstOrNull()?.preferences?.tasks?.mirrorGroupTasks?.toTypedArray() |
Comment on lines
64
to
+65
| localRepository.saveTasks(userId, order, tasks) | ||
| widgetUpdater.updateTaskListWidgets() |
| taskRepository.saveTasks(id, tasksOrder, tasks) | ||
| } | ||
| } | ||
| widgetUpdater.updateAllWidgets() |
Comment on lines
113
to
+117
| if (id != null && tasksOrder != null && tasks != null) { | ||
| taskRepository.saveTasks(id, tasksOrder, tasks) | ||
| } | ||
| } | ||
| widgetUpdater.updateAllWidgets() |
Comment on lines
+174
to
+175
| return intent.action == AppWidgetManager.ACTION_APPWIDGET_UPDATE && | ||
| !intent.getBooleanExtra(WidgetUpdater.EXTRA_SKIP_NETWORK_REFRESH, false) |
Comment on lines
+58
to
+62
| val task = taskRepository.getUnmanagedTask(taskid).firstOrNull() | ||
| updateData(task) | ||
| } | ||
| } finally { | ||
| stopSelf(startId) |
Comment on lines
+41
to
+45
| try { | ||
| dispatchWidgetUpdate(context, intent) | ||
| } finally { | ||
| pendingResult.finish() | ||
| } |
af05e6e to
65ea197
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1233.
WidgetUpdaterto centralize task-list notifications and explicit widget update broadcasts.onCreate()andonDataSetChanged().HabitButtonWidgetServiceonly after async rendering finishes.Tests
JAVA_HOME=/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home ./gradlew :Habitica:testProdDebugUnitTest --tests com.habitrpg.android.habitica.widget.BaseWidgetProviderTest --tests com.habitrpg.android.habitica.widget.WidgetUpdaterTest --tests com.habitrpg.android.habitica.widget.TaskListFactoryTest --tests com.habitrpg.android.habitica.data.implementation.UserRepositoryImplTest --tests com.habitrpg.android.habitica.data.implementation.TaskRepositoryImplTestJAVA_HOME=/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home ./gradlew :Habitica:compileProdDebugKotlingit diff --checkKnown Existing Failures
JAVA_HOME=/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home ./gradlew :Habitica:testProdDebugUnitTestTaskTest.isDueTodaycases atTaskTest.kt:46,TaskTest.kt:53, andTaskTest.kt:60.JAVA_HOME=/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home ./gradlew testcommontests atcommon/src/test/java/com/habitrpg/common/habitica/helpers/NumberAbbreviatorTest.kt:44.