feat(album): Rescan folders in albums every hour #3

Merged
lucas merged 2 commits from dev-LFA into main-LFA 2026-11-23 14:49:02 +01:00
3 changed files with 8 additions and 10 deletions

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ Paperize is an Android app that changes your home and lock screen wallpaper on a
<img src=".github/readme/feature-albums-light.png" alt="01. Albums, on rotation. The library with two albums, and an album open showing its wallpapers.">
</picture>
An album holds single images, whole folders, or both. Paperize rescans folders each time you open the app, and once a day while a schedule is running, so new files join the rotation and deleted ones leave it by themselves; **Refresh folder** rescans one straight away. Open an album's options menu to rename or delete it, or rescan all its folders. Removing something from an album never touches the file on your device.
An album holds single images, whole folders, or both. Paperize rescans folders each time you open the app, and every hour while a schedule is running, so new files join the rotation and deleted ones leave it by themselves; **Refresh folder** rescans one straight away. Open an album's options menu to rename or delete it, or rescan all its folders. Removing something from an album never touches the file on your device.
When creating an album, you can mark it encrypted; this choice is permanent and imports only `.jpg_enc` files made by wallpaper_changer. Set the same passphrase in **Settings → Encrypted albums**. It is protected by Android Keystore and remains available for scheduled changes. Encrypted previews are off by default; enabling them decrypts images in memory without caching them to disk. Turning previews off removes them from the app's display. Android may still retain the applied wallpaper, and wallpaper_changer's encryption format does not authenticate its contents.
@@ -15,7 +15,6 @@ import com.anthonyla.paperize.domain.model.ScheduleSettings
import com.anthonyla.paperize.domain.model.usesVisibleLiveTimer
import dagger.hilt.android.qualifiers.ApplicationContext
import java.time.Duration
import java.time.ZonedDateTime
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton
@@ -79,7 +78,7 @@ class WallpaperScheduler @Inject constructor(
workManager.cancelUniqueWork(workName(screen))
}
}
if (enabled) scheduleDailyAlbumRefresh(onlyIfNotScheduled) else workManager.cancelUniqueWork(Constants.WORK_NAME_REFRESH)
if (enabled) scheduleHourlyAlbumRefresh(onlyIfNotScheduled) else workManager.cancelUniqueWork(Constants.WORK_NAME_REFRESH)
}
fun cancelAllWallpaperChanges() {
@@ -96,13 +95,10 @@ class WallpaperScheduler @Inject constructor(
)
}
/** Refresh daily, with the first run at the next 3 AM. */
private fun scheduleDailyAlbumRefresh(onlyIfNotScheduled: Boolean) {
val now = ZonedDateTime.now()
val today3am = now.toLocalDate().atTime(3, 0).atZone(now.zone)
val next3am = if (today3am.isAfter(now)) today3am else today3am.plusDays(1)
val workRequest = PeriodicWorkRequestBuilder<AlbumRefreshWorker>(1, TimeUnit.DAYS)
.setInitialDelay(Duration.between(now, next3am))
/** Refresh hourly, with the first run after one hour. */
private fun scheduleHourlyAlbumRefresh(onlyIfNotScheduled: Boolean) {
val workRequest = PeriodicWorkRequestBuilder<AlbumRefreshWorker>(1, TimeUnit.HOURS)
.setInitialDelay(Duration.ofHours(1))
.build()
workManager.enqueueUniquePeriodicWork(Constants.WORK_NAME_REFRESH, policy(onlyIfNotScheduled), workRequest)
}
@@ -70,6 +70,8 @@ class WallpaperSchedulerTest {
)
assertEquals(Constants.WORK_NAME_REFRESH, enqueued.single().first)
assertEquals(ExistingPeriodicWorkPolicy.KEEP, enqueued.single().second)
assertEquals(TimeUnit.HOURS.toMillis(1), enqueued.single().third.workSpec.intervalDuration)
assertEquals(TimeUnit.HOURS.toMillis(1), enqueued.single().third.workSpec.initialDelay)
assertEquals(setOf(Constants.WORK_NAME_HOME, Constants.WORK_NAME_LOCK, Constants.WORK_NAME_BOTH,
Constants.WORK_NAME_LIVE), cancelled.toSet())
}