Skip to content

Set library update time - #2591

Open
tempacct-mihon wants to merge 4 commits into
mihonapp:mainfrom
tempacct-mihon:main
Open

tempacct-mihon wants to merge 4 commits into
mihonapp:mainfrom
tempacct-mihon:main

Conversation

@tempacct-mihon

Copy link
Copy Markdown

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

Menu option Time picker Tablet mode
menu item time picker time picker tablet

@tempacct-mihon tempacct-mihon changed the title Fixed library update time Set library update time Oct 13, 2025
@MajorTanya

Copy link
Copy Markdown
Member

What does that look like in 24 hour format? I refuse to use 12 hour format for anything like this.

@BrutuZ

BrutuZ commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

Should probably include a disclaimer about workers being inaccurate / drifting over time. Or at the very least an "approximately"
Once you add a clock people will have even more reason to expect alarm-like precision down to the minute.

@tempacct-mihon

Copy link
Copy Markdown
Author

@MajorTanya It now adapts to whatever time format your device is using

Images

Menu option Time picker
menu item 24 time picker 24

@tempacct-mihon

Copy link
Copy Markdown
Author

Should probably include a disclaimer about workers being inaccurate / drifting over time. Or at the very least an "approximately" Once you add a clock people will have even more reason to expect alarm-like precision down to the minute.

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

Comment on lines +517 to +548
// 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,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was this AI generated? Why is there a comment on pretty much every line?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i like to be thorough with my comments 🤷‍♂️tho ig i did go a bit overboard my b

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants