Skip to content

Save the regularly update data switch and check once a month - #779

Open
bhanu-dev82 wants to merge 3 commits into
scribe-org:mainfrom
bhanu-dev82:feat/monthly-data-update-check
Open

bhanu-dev82 wants to merge 3 commits into
scribe-org:mainfrom
bhanu-dev82:feat/monthly-data-update-check

Conversation

@bhanu-dev82

@bhanu-dev82 bhanu-dev82 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Contributor checklist


Description

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 — calls data-version only 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.
  • Tests — date rule, monthly slot, which languages are requested, and the default of off.
  • 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.
  • Both download screens — drop the unsaved mutableStateOf(true).
  • Both download ViewModels — use the shared date check. A bad updated_at still shows the invalid-response error.
  • Both MainActivity files — schedule the next check on launch, and open the right download screen from the notification.
  • Both changelogs — one bullet each.

Screenshot

Screenshot_20261118_132419_One UI Home

Related issue

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.
@andrewtavis

Copy link
Copy Markdown
Member

Wow, this looks absolutely amazing! 🤩 What a feature to add in!

@andrewtavis

Copy link
Copy Markdown
Member

I'll have a bit more time later in the week to look into this :)

@andrewtavis andrewtavis added the -priority- High priority label Nov 18, 2026
}
} catch (cancelled: CancellationException) {
throw cancelled
} catch (e: Exception) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capped with runAttemptCount (MAX_ATTEMPTS = 3), after which it queues the next monthly slot (c5e8106).

@Roniscend

Copy link
Copy Markdown
Collaborator

@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

@andrewtavis

Copy link
Copy Markdown
Member

@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+.
@bhanu-dev82

Copy link
Copy Markdown
Collaborator Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

-priority- High priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add functionality to the regularly check for new data toggle in Android applications

3 participants