coil: gracefully handle file handling failures

Wrap the basic fetchArt call in a try statement to prevent exceptions
from being unable to open a file from propagating outwards. This allows
us to safely degrade when creating mosaics.
This commit is contained in:
OxygenCobalt 2022-01-23 11:30:26 -07:00
parent b04611c3be
commit 3de5fecf4a
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 13 additions and 5 deletions

View file

@ -50,10 +50,14 @@ abstract class AuxioFetcher : Fetcher {
return null
}
return if (settingsManager.useQualityCovers) {
fetchQualityCovers(context, album)
} else {
fetchMediaStoreCovers(context, album)
return try {
if (settingsManager.useQualityCovers) {
fetchQualityCovers(context, album)
} else {
fetchMediaStoreCovers(context, album)
}
} catch (e: Exception) {
null
}
}
@ -205,7 +209,7 @@ abstract class AuxioFetcher : Fetcher {
*/
protected fun createMosaic(context: Context, streams: List<InputStream>, size: Size): FetchResult? {
if (streams.size < 4) {
return streams.getOrNull(0)?.let { stream ->
return streams.firstOrNull()?.let { stream ->
return SourceResult(
source = ImageSource(stream.source().buffer(), context),
mimeType = null,

View file

@ -34,6 +34,7 @@ import org.oxycblt.auxio.music.Artist
import org.oxycblt.auxio.music.Genre
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.ui.Sort
import org.oxycblt.auxio.util.logD
import kotlin.math.min
/**
@ -81,9 +82,12 @@ class ArtistImageFetcher private constructor(
.sortAlbums(artist.albums)
val results = albums.mapAtMost(4) { album ->
logD("${artist.name} ${album.name}")
fetchArt(context, album)
}
logD("OK: ${artist.name}")
return createMosaic(context, results, size)
}