Repository navigation
Set library update time - #2591
tempacct-mihon wants to merge 4 commits into
Conversation
|
What does that look like in 24 hour format? I refuse to use 12 hour format for anything like this. |
|
Should probably include a disclaimer about workers being inaccurate / drifting over time. Or at the very least an "approximately" |
|
@MajorTanya It now adapts to whatever time format your device is using Images
|
@BrutuZ This will fix the drifting issue and in my experience testing this it is precise to the minute. With restricted battery it may lose some precision tho. |
| // Convert time string into LocalTime obj | ||
| val format = DateTimeFormatter.ofPattern("h:mm a") | ||
| val updateTime = LocalTime.parse(time, format) | ||
|
|
||
| // Create LocalDateTime obj with today's date and the time set to the update time | ||
| var updateCal = LocalDateTime.now() | ||
| updateCal = updateCal.withHour(updateTime.hour).withMinute(updateTime.minute) | ||
|
|
||
| // Check if update time has already passed, if so: schedule for tomorrow | ||
| val now = LocalDateTime.now() | ||
| if (ChronoUnit.MINUTES.between(now,updateCal) <= 0) | ||
| updateCal = updateCal.plusHours(interval.toLong()) | ||
|
|
||
| // Get number of minutes until update | ||
| val delay = ChronoUnit.MINUTES.between(now,updateCal) + 1 | ||
|
|
||
|
|
||
| // Create one time request | ||
| val request = OneTimeWorkRequestBuilder<LibraryUpdateJob>() | ||
| .setInitialDelay(delay, TimeUnit.MINUTES) | ||
| .addTag(TAG) | ||
| .addTag(WORK_NAME_AUTO) | ||
| .setConstraints(constraints) | ||
| .setBackoffCriteria(BackoffPolicy.LINEAR, 10, TimeUnit.MINUTES) | ||
| .build() | ||
|
|
||
| // Enqueue request | ||
| context.workManager.enqueueUniqueWork( | ||
| WORK_NAME_AUTO, | ||
| ExistingWorkPolicy.REPLACE, | ||
| request, | ||
| ) |
There was a problem hiding this comment.
Was this AI generated? Why is there a comment on pretty much every line?
There was a problem hiding this comment.
i like to be thorough with my comments 🤷♂️tho ig i did go a bit overboard my b


Currently the method for scheduling library updates at a given time is tedious to set up as it just uses the time the first update was scheduled. It also uses PeriodicWorkRequests which aren't very precise as they will update within a window resulting in the update time steadily drifting from what it was originally set from.
This PR adds a new setting in the library settings menu to set the time the library update will be triggered. It calculates the delay in minutes until the specified update time and then enqueues a LibraryUpdateJob OneTimeWorkRequest to run after that many minutes. After each LibraryUpdateJob a new OneTimeWorkRequest is enqueued for the user specified time.
These changes have been tested on every update delay interval, and the UI changes have been tested with all base themes and tablet mode
Images