Repository navigation
Save the regularly update data switch and check once a month - #779
bhanu-dev82 wants to merge 3 commits into
Conversation
Save the regularly update data switch and default it to off. While it is on, both apps check data-version immediately and once during the second week of each month, then post a local notification.
|
Wow, this looks absolutely amazing! 🤩 What a feature to add in! |
|
I'll have a bit more time later in the week to look into this :) |
| } | ||
| } catch (cancelled: CancellationException) { | ||
| throw cancelled | ||
| } catch (e: Exception) { |
There was a problem hiding this comment.
This swallows every per-language error, so if the network fails for all languages languagesWithUpdates() returns an empty list and the worker reports success and schedules the next check for next month
There was a problem hiding this comment.
Good catch! check() now returns checked/failed counts, and the worker retries when every language failed instead of reporting success (c5e8106).
| onCheckedChange = { checked -> | ||
| enabled = checked | ||
| if (checked && needsNotificationPermission(context)) { | ||
| permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) |
There was a problem hiding this comment.
If the permission is denied on Android 13+ the switch stays on and the worker still does the network checks, but the notification can never appear, so the user gets nothing. As far as I know notify() is dropped silently without the permission rather than throwing
There was a problem hiding this comment.
Fixed in c5e8106: a denial leaves the switch off and schedules nothing, and the worker skips the network checks when notifications aren't allowed.
| } catch (e: Exception) { | ||
| Log.w(TAG, "Data update check failed", e) | ||
| if (userInitiated) { | ||
| Result.retry() |
There was a problem hiding this comment.
A failed user-initiated run retries forever with exponential backoff and keeps userInitiated = true, so it also bypasses the battery-saver wait every time. Could we cap it with runAttemptCount and then fall through to scheduling the next monthly slot?
There was a problem hiding this comment.
Capped with runAttemptCount (MAX_ATTEMPTS = 3), after which it queues the next monthly slot (c5e8106).
|
@bhanu-dev82 The new tests cover the calendar, checker, comparator and preference, but nothing covers the worker, scheduler or notifier also I would suggest big feature updates like this should be covered in parts not in a single pr |
|
@bhanu-dev82, it looks like there are a few more comments from @Roniscend on this PR. Would you want to address those and we can bring this in later today, if possible? :) |
# Conflicts: # app/proguard-rules.pro
…ate the switch on notifications - DataUpdateChecker.check() returns a result with checked and failed counts so a run where every language failed is no longer reported as success. - The worker logic moves into DataUpdateCheckRunner: retry while every check fails, stop after MAX_ATTEMPTS (3) and queue the next monthly slot, skip the network when notifications are not allowed. - The Regularly update data switch stays off and schedules nothing when the notification permission is denied on Android 13+.
|
Thanks for the review, @Roniscend, all three were good catches! Fixed in c5e8106 🙂 If every language check fails, the worker now retries instead of reporting success. If notification permission is denied, the switch stays off and nothing is scheduled. Failing runs now stop after 3 attempts and wait for the next monthly slot. I also added tests for each case and merged main to fix a small conflict. Thanks @andrewtavis for pushing this along! |
Contributor checklist
./gradlew lintKotlin detekt testcommand as directed in the testing section of the contributing guideDescription
The switch was unsaved Compose state and started on. It is now saved, defaults to off, and checks
data-version/{lang}immediately and once in the second week of each month. A newer downloaded language gets a local notification. The pack is not downloaded.The label stays "Regularly update data" until Scribe-i18n has a new string. The notification uses strings that already exist.
Files
DataVersionComparator.kt— shared date check, so the screen and the background job agree.DataUpdateCalendar.kt— picks the monthly slot once per install and the battery-saver delay.DataUpdateChecker.kt— callsdata-versiononly for languages already downloaded. Keyboards and Conjugate use different preference files.DataUpdateScheduler.kt— the only WorkManager calls. On runs a check now, off cancels it. Opening the app does not.DataUpdateCheckWorker.kt— runs the check, notifies, and queues next month.DataUpdateNotifier.kt— the notification and the tap that opens the download screen.DownloadNavEvents.kt— handles that tap, including when the app is already open. The keyboard banner uses the same extra.RegularDataCheckSwitch.kt— one switch for both download screens, including the Android 13 permission ask.ic_stat_data_update.xml— white status-bar icon. The launcher art does not work there.AndroidManifest.xml—POST_NOTIFICATIONS.app/build.gradle.kts—androidx.work:work-runtime-ktx:2.11.2, not the Play Services build.proguard-rules.pro— keeps the worker constructor for minify.PreferencesHelper.kt— saves the switch. Missing means off.mutableStateOf(true).updated_atstill shows the invalid-response error.MainActivityfiles — schedule the next check on launch, and open the right download screen from the notification.Screenshot
Related issue