mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Fix crash after last screensaver image in list (#1055)
## Description Fix a screensaver crash after the last item Also adds some extra error checking ### Related issues Fixes #1053 ### Testing Emulator ## Screenshots N/A ## AI or LLM usage None
This commit is contained in:
parent
8a4be3dd32
commit
256bb3f988
2 changed files with 32 additions and 28 deletions
|
|
@ -250,7 +250,7 @@ suspend fun upgradeApp(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previous.isEqualOrBefore(Version.fromString("0.5.0-6-g0"))) {
|
if (previous.isEqualOrBefore(Version.fromString("0.5.3-0-g0"))) {
|
||||||
appPreferences.updateData {
|
appPreferences.updateData {
|
||||||
it.updateScreensaverPreferences {
|
it.updateScreensaverPreferences {
|
||||||
startDelay = ScreensaverPreference.DEFAULT_START_DELAY
|
startDelay = ScreensaverPreference.DEFAULT_START_DELAY
|
||||||
|
|
|
||||||
|
|
@ -161,27 +161,32 @@ class ScreensaverService
|
||||||
if (pager.isEmpty()) {
|
if (pager.isEmpty()) {
|
||||||
emit(null)
|
emit(null)
|
||||||
} else {
|
} else {
|
||||||
|
val duration =
|
||||||
|
userPreferencesService
|
||||||
|
.getCurrent()
|
||||||
|
.appPreferences
|
||||||
|
.interfacePreferences.screensaverPreference.duration.milliseconds
|
||||||
while (true) {
|
while (true) {
|
||||||
val item = pager.getBlocking(index)
|
try {
|
||||||
Timber.v("Next index=%s, item=%s", index, item?.id)
|
val item = pager.getBlocking(index)
|
||||||
if (item != null) {
|
Timber.v("Next index=%s, item=%s", index, item?.id)
|
||||||
val backdropUrl =
|
if (item != null) {
|
||||||
if (item.type == BaseItemKind.PHOTO) {
|
val backdropUrl =
|
||||||
api.libraryApi.getDownloadUrl(item.id)
|
if (item.type == BaseItemKind.PHOTO) {
|
||||||
} else {
|
api.libraryApi.getDownloadUrl(item.id)
|
||||||
imageUrlService.getItemImageUrl(item, ImageType.BACKDROP)
|
} else {
|
||||||
}
|
imageUrlService.getItemImageUrl(item, ImageType.BACKDROP)
|
||||||
val title =
|
|
||||||
if (item.type == BaseItemKind.PHOTO) {
|
|
||||||
item.data.premiereDate?.let {
|
|
||||||
formatDate(it.toLocalDate())
|
|
||||||
}
|
}
|
||||||
} else {
|
val title =
|
||||||
item.title
|
if (item.type == BaseItemKind.PHOTO) {
|
||||||
}
|
item.data.premiereDate?.let {
|
||||||
val logoUrl = imageUrlService.getItemImageUrl(item, ImageType.LOGO)
|
formatDate(it.toLocalDate())
|
||||||
if (backdropUrl != null) {
|
}
|
||||||
try {
|
} else {
|
||||||
|
item.title
|
||||||
|
}
|
||||||
|
val logoUrl = imageUrlService.getItemImageUrl(item, ImageType.LOGO)
|
||||||
|
if (backdropUrl != null) {
|
||||||
context.imageLoader
|
context.imageLoader
|
||||||
.enqueue(
|
.enqueue(
|
||||||
ImageRequest
|
ImageRequest
|
||||||
|
|
@ -191,18 +196,17 @@ class ScreensaverService
|
||||||
).job
|
).job
|
||||||
.await()
|
.await()
|
||||||
emit(CurrentItem(item, backdropUrl, logoUrl, title ?: ""))
|
emit(CurrentItem(item, backdropUrl, logoUrl, title ?: ""))
|
||||||
} catch (_: CancellationException) {
|
delay(duration)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
val duration =
|
|
||||||
userPreferencesService
|
|
||||||
.getCurrent()
|
|
||||||
.appPreferences
|
|
||||||
.interfacePreferences.screensaverPreference.duration.milliseconds
|
|
||||||
delay(duration)
|
|
||||||
}
|
}
|
||||||
|
} catch (_: CancellationException) {
|
||||||
|
break
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Timber.e(ex, "Error fetching next item")
|
||||||
|
delay(duration)
|
||||||
}
|
}
|
||||||
index++
|
index++
|
||||||
|
if (index > pager.lastIndex) index = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.flowOn(Dispatchers.Default).cancellable()
|
}.flowOn(Dispatchers.Default).cancellable()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue