Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b506ac179f | ||
|
|
8eb3d501cd | ||
|
|
47aa0a6f25 | ||
|
|
0f988dd1a7 |
No files matched your search
@@ -74,7 +74,7 @@ Albums and settings stay on your device, and Paperize has no internet permission
|
||||
|
||||
## Translations
|
||||
|
||||
Paperize ships in 38 languages. To add or improve a language, translate it on [Crowdin](https://crowdin.com/project/paperize). Translations are reviewed there before they reach the app, and a new language is added once 90% of it has been reviewed.
|
||||
Paperize ships in more than 35 languages. To add or improve a language, translate it on [Crowdin](https://crowdin.com/project/paperize). Translations are reviewed there before they reach the app, and a new language is added once 90% of it has been reviewed.
|
||||
|
||||
## Building from source
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ android {
|
||||
applicationId = "com.anthonyla.paperize"
|
||||
minSdk = 31
|
||||
targetSdk = 37
|
||||
versionCode = 60
|
||||
versionName = "4.3.0"
|
||||
versionCode = 61
|
||||
versionName = "4.3.1"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
||||
@@ -32,13 +32,10 @@ class ChangeWallpaperUseCase @Inject constructor(
|
||||
) {
|
||||
suspend operator fun invoke(albumId: String, screenType: ScreenType): PreparedWallpaper {
|
||||
val settings = settingsRepository.getScheduleSettings()
|
||||
repeat(Constants.MAX_WALLPAPER_LOAD_RETRIES) {
|
||||
currentCoroutineContext().ensureActive()
|
||||
val candidate = dequeueNext(albumId, screenType, settings.shuffleEnabled)
|
||||
return dequeueReadable(albumId, screenType, settings.shuffleEnabled) { candidate ->
|
||||
try {
|
||||
val bitmap = renderer.render(candidate, screenType, settings)
|
||||
if (bitmap != null) {
|
||||
return PreparedWallpaper(bitmap, albumId, screenType, candidate.id, settings.shuffleEnabled)
|
||||
renderer.render(candidate, screenType, settings)?.let { bitmap ->
|
||||
PreparedWallpaper(bitmap, albumId, screenType, candidate.id, settings.shuffleEnabled)
|
||||
}
|
||||
} catch (e: CancellationException) {
|
||||
// Cancelling preparation must not consume the selected queue item.
|
||||
@@ -51,10 +48,33 @@ class ChangeWallpaperUseCase @Inject constructor(
|
||||
}
|
||||
throw e
|
||||
} catch (_: Exception) {
|
||||
// Unreadable images are skipped for this cycle; refresh owns permanent pruning.
|
||||
null
|
||||
}
|
||||
} ?: throw NoValidWallpaperException()
|
||||
}
|
||||
|
||||
/**
|
||||
* Dequeue until [open] reads an item. Unreadable items are skipped for this cycle; refresh
|
||||
* owns permanent pruning. When none is readable the source itself is likely unavailable
|
||||
* (storage still mounting, a revoked permission), so the queue is left as it was.
|
||||
*/
|
||||
suspend fun <T : Any> dequeueReadable(
|
||||
albumId: String,
|
||||
screenType: ScreenType,
|
||||
shuffle: Boolean,
|
||||
open: suspend (Wallpaper) -> T?
|
||||
): T? {
|
||||
val unreadable = mutableListOf<Wallpaper>()
|
||||
repeat(Constants.MAX_WALLPAPER_LOAD_RETRIES) {
|
||||
currentCoroutineContext().ensureActive()
|
||||
val candidate = dequeueNext(albumId, screenType, shuffle)
|
||||
open(candidate)?.let { return it }
|
||||
unreadable += candidate
|
||||
}
|
||||
throw NoValidWallpaperException()
|
||||
unreadable.asReversed().forEach {
|
||||
wallpaperRepository.restoreWallpaperToQueueFront(albumId, screenType, it.id)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** Dequeue the next item, rebuilding an empty queue once. Throws [EmptyAlbumException] if none remain. */
|
||||
|
||||
+62
-20
@@ -7,7 +7,11 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.res.Configuration
|
||||
import android.database.ContentObserver
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.view.GestureDetector
|
||||
import android.view.MotionEvent
|
||||
@@ -20,7 +24,6 @@ import com.anthonyla.paperize.core.EmptyAlbumException
|
||||
import com.anthonyla.paperize.core.ScalingType
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
import com.anthonyla.paperize.core.WallpaperMode
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.core.util.isValid
|
||||
import com.anthonyla.paperize.domain.model.ScheduleSettings
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
@@ -126,6 +129,14 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
|
||||
}
|
||||
}
|
||||
|
||||
// Registered only while no wallpaper is readable, e.g. storage still mounting after boot.
|
||||
private var watchingSource = false
|
||||
private val sourceObserver = object : ContentObserver(Handler(Looper.getMainLooper())) {
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
renderController.reloadCurrentArtwork()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(surfaceHolder: SurfaceHolder) {
|
||||
super.onCreate(surfaceHolder)
|
||||
Log.d(TAG, "Engine created")
|
||||
@@ -135,9 +146,8 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
|
||||
setTouchEventsEnabled(true)
|
||||
|
||||
renderer = PaperizeWallpaperRenderer(applicationContext, this)
|
||||
renderController = PaperizeRenderController(renderer::queueWallpaper, engineScope) {
|
||||
withContext(Dispatchers.IO) { openNextWallpaper() }
|
||||
}
|
||||
renderController =
|
||||
PaperizeRenderController(renderer::queueWallpaper, engineScope, ::openNextWallpaper)
|
||||
|
||||
setRenderer(renderer)
|
||||
requestRender()
|
||||
@@ -161,29 +171,60 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
|
||||
)
|
||||
}
|
||||
|
||||
/** Dequeue the next readable live wallpaper. Queue and database errors reach the controller. */
|
||||
private suspend fun openNextWallpaper(): ImageLoader {
|
||||
/** Null while no wallpaper is readable. Queue and database errors reach the controller. */
|
||||
private suspend fun openNextWallpaper(): ImageLoader? {
|
||||
// In STATIC mode the static wallpaper worker owns HOME/LOCK; the engine stays empty.
|
||||
if (settingsRepository.getWallpaperMode() != WallpaperMode.LIVE) return EmptyImageLoader
|
||||
val settings = settingsRepository.getScheduleSettings()
|
||||
val albumId = settings.liveAlbumId ?: return EmptyImageLoader
|
||||
|
||||
repeat(Constants.MAX_WALLPAPER_LOAD_RETRIES) {
|
||||
val candidate = try {
|
||||
changeWallpaperUseCase.dequeueNext(albumId, ScreenType.LIVE, settings.shuffleEnabled)
|
||||
} catch (_: EmptyAlbumException) {
|
||||
Log.w(TAG, "No wallpapers in album $albumId")
|
||||
return EmptyImageLoader
|
||||
}
|
||||
// Skip unreadable items without deleting them: a permission or storage issue may be
|
||||
// transient. AlbumRefreshWorker prunes documents that are actually gone.
|
||||
if (candidate.uri.toUri().isValid(contentResolver)) {
|
||||
currentWallpaper = candidate
|
||||
return ContentUriImageLoader(contentResolver, candidate.uri.toUri(), settings.liveScalingType)
|
||||
var unreadable: Uri? = null
|
||||
suspend fun nextReadable() = withContext(Dispatchers.IO) {
|
||||
changeWallpaperUseCase.dequeueReadable(albumId, ScreenType.LIVE, settings.shuffleEnabled) { candidate ->
|
||||
val uri = candidate.uri.toUri()
|
||||
if (uri.isValid(contentResolver)) {
|
||||
currentWallpaper = candidate
|
||||
ContentUriImageLoader(contentResolver, uri, settings.liveScalingType)
|
||||
} else {
|
||||
unreadable = uri
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.w(TAG, "No valid wallpaper found after retries")
|
||||
return EmptyImageLoader
|
||||
|
||||
return try {
|
||||
var loader = nextReadable()
|
||||
if (loader == null && !watchingSource) {
|
||||
unreadable?.let(::watchSource)
|
||||
// The source may have come back before the observer was registered.
|
||||
loader = nextReadable()
|
||||
}
|
||||
if (loader == null) {
|
||||
Log.w(TAG, "No readable wallpaper in album $albumId")
|
||||
} else {
|
||||
stopWatchingSource()
|
||||
}
|
||||
loader
|
||||
} catch (_: EmptyAlbumException) {
|
||||
Log.w(TAG, "No wallpapers in album $albumId")
|
||||
EmptyImageLoader
|
||||
}
|
||||
}
|
||||
|
||||
/** A provider notifies its documents when their root changes, e.g. a volume is mounted. */
|
||||
private fun watchSource(uri: Uri) {
|
||||
try {
|
||||
contentResolver.registerContentObserver(uri, false, sourceObserver)
|
||||
watchingSource = true
|
||||
} catch (e: SecurityException) {
|
||||
Log.w(TAG, "Cannot watch $uri", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopWatchingSource() {
|
||||
if (!watchingSource) return
|
||||
contentResolver.unregisterContentObserver(sourceObserver)
|
||||
watchingSource = false
|
||||
}
|
||||
|
||||
private fun observeSettings() {
|
||||
@@ -287,6 +328,7 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
|
||||
override fun onDestroy() {
|
||||
engines -= this
|
||||
applicationContext.unregisterReceiver(screenOffReceiver)
|
||||
stopWatchingSource()
|
||||
|
||||
renderer.cancelLoading()
|
||||
|
||||
|
||||
+6
-3
@@ -5,11 +5,14 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/** All calls run on the engine's main dispatcher; its scope owns cancellation. */
|
||||
/**
|
||||
* All calls run on the engine's main dispatcher; its scope owns cancellation.
|
||||
* [openCurrentArtwork] returns null while no wallpaper is readable, which keeps what is shown.
|
||||
*/
|
||||
class PaperizeRenderController(
|
||||
private val queueWallpaper: (ImageLoader, Boolean) -> Unit,
|
||||
private val controllerScope: CoroutineScope,
|
||||
private val openCurrentArtwork: suspend () -> ImageLoader
|
||||
private val openCurrentArtwork: suspend () -> ImageLoader?
|
||||
) {
|
||||
var visible = false
|
||||
set(value) {
|
||||
@@ -42,7 +45,7 @@ class PaperizeRenderController(
|
||||
controllerScope.launch {
|
||||
try {
|
||||
val loader = openCurrentArtwork()
|
||||
if (isActive && !hasPendingReload) {
|
||||
if (loader != null && isActive && !hasPendingReload) {
|
||||
queueWallpaper(loader, skipCrossfade)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ class WallpaperChangeService : Service() {
|
||||
context: Context,
|
||||
wallpaperId: String,
|
||||
screen: ScreenType,
|
||||
startSequenceHere: Boolean = false
|
||||
startSequenceHere: Boolean
|
||||
) = start(context, ACTION_APPLY_SPECIFIC_WALLPAPER) {
|
||||
putExtra(EXTRA_WALLPAPER_ID, wallpaperId)
|
||||
putExtra(EXTRA_SCREEN_TYPE, screen.name)
|
||||
|
||||
@@ -95,7 +95,7 @@ class WallpaperController @Inject constructor(
|
||||
wallpaperId: String,
|
||||
screen: ScreenType,
|
||||
settings: ScheduleSettings,
|
||||
startSequenceHere: Boolean = false
|
||||
startSequenceHere: Boolean
|
||||
) {
|
||||
val targets = if (screen == ScreenType.BOTH && !settings.sameStaticPresentation()) {
|
||||
listOf(ScreenType.HOME, ScreenType.LOCK)
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.mockk.coVerify
|
||||
import io.mockk.coVerifyOrder
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@@ -95,6 +96,30 @@ class ChangeWallpaperUseCaseTest {
|
||||
coVerify(exactly = Constants.MAX_WALLPAPER_LOAD_RETRIES) { renderer.render(wallpaper, ScreenType.HOME, any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an unreadable source leaves the queue as it was`() = runTest {
|
||||
val queued = List(Constants.MAX_WALLPAPER_LOAD_RETRIES) { testWallpaper("image$it", "album") }
|
||||
coEvery { repository.getAndDequeueWallpaper("album", ScreenType.HOME) } returnsMany queued
|
||||
coEvery { renderer.render(any(), ScreenType.HOME, any()) } returns null
|
||||
|
||||
assertTrue(runCatching { useCase("album", ScreenType.HOME) }.exceptionOrNull() is NoValidWallpaperException)
|
||||
coVerifyOrder {
|
||||
queued.asReversed().forEach { repository.restoreWallpaperToQueueFront("album", ScreenType.HOME, it.id) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `unreadable items before a readable one stay skipped`() = runTest {
|
||||
val readable = testWallpaper("readable", "album")
|
||||
coEvery { repository.getAndDequeueWallpaper("album", ScreenType.HOME) } returnsMany
|
||||
listOf(testWallpaper("gone", "album"), readable)
|
||||
|
||||
val opened = useCase.dequeueReadable("album", ScreenType.HOME, shuffle = false) { candidate -> candidate.takeIf { it == readable } }
|
||||
|
||||
assertEquals(readable, opened)
|
||||
coVerify(exactly = 0) { repository.restoreWallpaperToQueueFront(any(), any(), any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `empty album stops after rebuilding once`() = runTest {
|
||||
coEvery { repository.getAndDequeueWallpaper("album", ScreenType.HOME) } returns null
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ class WallpaperControllerTest {
|
||||
@Test fun `specific selection commits both screens without advancing a queue`() = runTest {
|
||||
coEvery { render("album", ScreenType.HOME, "selected") } returns bitmap
|
||||
every { manager.setBitmap(bitmap, null, true, 3) } returns 1
|
||||
controller.applySpecific("album", "selected", ScreenType.BOTH, settings)
|
||||
controller.applySpecific("album", "selected", ScreenType.BOTH, settings, startSequenceHere = false)
|
||||
coVerify(exactly = 0) { prepare(any(), any()) }
|
||||
coVerify { prepare.completeSpecific("album", ScreenType.HOME, "selected", false, false) }
|
||||
coVerify { prepare.completeSpecific("album", ScreenType.LOCK, "selected", false, false) }
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@
|
||||
<div><dt>Static or live</dt><dd>Use ordinary static wallpapers, or the live wallpaper for smooth transitions between images.</dd></div>
|
||||
<div><dt>Your formats</dt><dd>JPG, PNG, WEBP, AVIF, HEIC/HEIF, BMP, GIF and TIFF.</dd></div>
|
||||
<div><dt>On your device</dt><dd>Wallpapers and settings stay on your phone. Paperize has no internet permission.</dd></div>
|
||||
<div><dt>In your language</dt><dd>38 languages. <a href="https://crowdin.com/project/paperize">Help translate or improve one on Crowdin</a>.</dd></div>
|
||||
<div><dt>In your language</dt><dd>More than 35 languages. <a href="https://crowdin.com/project/paperize">Help translate or improve one on Crowdin</a>.</dd></div>
|
||||
</dl>
|
||||
|
||||
<section class="privacy wrap" id="privacy">
|
||||
|
||||
Reference in new issue
Block a user