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:
parent
b04611c3be
commit
3de5fecf4a
2 changed files with 13 additions and 5 deletions
|
@ -50,11 +50,15 @@ abstract class AuxioFetcher : Fetcher {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (settingsManager.useQualityCovers) {
|
return try {
|
||||||
|
if (settingsManager.useQualityCovers) {
|
||||||
fetchQualityCovers(context, album)
|
fetchQualityCovers(context, album)
|
||||||
} else {
|
} else {
|
||||||
fetchMediaStoreCovers(context, album)
|
fetchMediaStoreCovers(context, album)
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
|
@ -205,7 +209,7 @@ abstract class AuxioFetcher : Fetcher {
|
||||||
*/
|
*/
|
||||||
protected fun createMosaic(context: Context, streams: List<InputStream>, size: Size): FetchResult? {
|
protected fun createMosaic(context: Context, streams: List<InputStream>, size: Size): FetchResult? {
|
||||||
if (streams.size < 4) {
|
if (streams.size < 4) {
|
||||||
return streams.getOrNull(0)?.let { stream ->
|
return streams.firstOrNull()?.let { stream ->
|
||||||
return SourceResult(
|
return SourceResult(
|
||||||
source = ImageSource(stream.source().buffer(), context),
|
source = ImageSource(stream.source().buffer(), context),
|
||||||
mimeType = null,
|
mimeType = null,
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.oxycblt.auxio.music.Artist
|
||||||
import org.oxycblt.auxio.music.Genre
|
import org.oxycblt.auxio.music.Genre
|
||||||
import org.oxycblt.auxio.music.Song
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.ui.Sort
|
import org.oxycblt.auxio.ui.Sort
|
||||||
|
import org.oxycblt.auxio.util.logD
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,9 +82,12 @@ class ArtistImageFetcher private constructor(
|
||||||
.sortAlbums(artist.albums)
|
.sortAlbums(artist.albums)
|
||||||
|
|
||||||
val results = albums.mapAtMost(4) { album ->
|
val results = albums.mapAtMost(4) { album ->
|
||||||
|
logD("${artist.name} ${album.name}")
|
||||||
fetchArt(context, album)
|
fetchArt(context, album)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logD("OK: ${artist.name}")
|
||||||
|
|
||||||
return createMosaic(context, results, size)
|
return createMosaic(context, results, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue