diff --git a/README.md b/README.md index e643e7c..f35f83e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Paperize is an Android app that changes your home and lock screen wallpaper on a 01. Albums, on rotation. The library with two albums, and an album open showing its wallpapers. -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. diff --git a/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperScheduler.kt b/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperScheduler.kt index 648d95e..2908a2a 100644 --- a/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperScheduler.kt +++ b/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperScheduler.kt @@ -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(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(1, TimeUnit.HOURS) + .setInitialDelay(Duration.ofHours(1)) .build() workManager.enqueueUniquePeriodicWork(Constants.WORK_NAME_REFRESH, policy(onlyIfNotScheduled), workRequest) } diff --git a/app/src/test/java/com/anthonyla/paperize/service/worker/WallpaperSchedulerTest.kt b/app/src/test/java/com/anthonyla/paperize/service/worker/WallpaperSchedulerTest.kt index 9f68a7b..ca403e1 100644 --- a/app/src/test/java/com/anthonyla/paperize/service/worker/WallpaperSchedulerTest.kt +++ b/app/src/test/java/com/anthonyla/paperize/service/worker/WallpaperSchedulerTest.kt @@ -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()) }