Fix bug w/Artist Images
Fix a bug where the app will crash if it attempts to load the artist image for an artist that has no albums.
This commit is contained in:
parent
309ed2dcff
commit
a81860bed2
3 changed files with 19 additions and 8 deletions
|
@ -9,6 +9,8 @@ import org.oxycblt.auxio.R
|
|||
import org.oxycblt.auxio.music.models.Album
|
||||
import org.oxycblt.auxio.music.models.Artist
|
||||
|
||||
// List of ID3 genres + Winamp extensions, each index corresponds to their int value.
|
||||
// There are a lot more int-genre extensions as far as Im aware, but this works for most cases.
|
||||
private val ID3_GENRES = arrayOf(
|
||||
"Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz",
|
||||
"Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno",
|
||||
|
|
|
@ -35,7 +35,10 @@ fun ImageView.getCoverArt(album: Album) {
|
|||
// Get the artist image
|
||||
@BindingAdapter("artistImage")
|
||||
fun ImageView.getArtistImage(artist: Artist) {
|
||||
val request = if (artist.numAlbums >= 4) {
|
||||
// If there are more than one albums, then create a mosaic of them.
|
||||
val request: ImageRequest
|
||||
|
||||
if (artist.numAlbums >= 4) {
|
||||
val uris = mutableListOf<Uri>()
|
||||
|
||||
for (i in 0..3) {
|
||||
|
@ -44,16 +47,24 @@ fun ImageView.getArtistImage(artist: Artist) {
|
|||
|
||||
val fetcher = ArtistImageFetcher(context)
|
||||
|
||||
getDefaultRequest(context, this)
|
||||
request = getDefaultRequest(context, this)
|
||||
.data(uris)
|
||||
.fetcher(fetcher)
|
||||
.error(R.drawable.ic_artist)
|
||||
.build()
|
||||
} else {
|
||||
getDefaultRequest(context, this)
|
||||
.data(artist.albums[0].coverUri)
|
||||
.error(R.drawable.ic_artist)
|
||||
.build()
|
||||
// Otherwise, just get the first cover and use that
|
||||
// If the artist doesn't have any albums [Which happens], then don't even bother with that.
|
||||
if (artist.albums.isNotEmpty()) {
|
||||
request = getDefaultRequest(context, this)
|
||||
.data(artist.albums[0].coverUri)
|
||||
.error(R.drawable.ic_artist)
|
||||
.build()
|
||||
} else {
|
||||
setImageResource(R.drawable.ic_artist)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Coil.imageLoader(context).enqueue(request)
|
||||
|
|
|
@ -75,8 +75,6 @@ class MusicSorter(
|
|||
// Find all albums that match the current artist name
|
||||
val artistAlbums = albums.filter { it.artistName == artist.name }
|
||||
|
||||
Log.d(this::class.simpleName, artist.id.toString())
|
||||
|
||||
// Then add them to the artist, along with refreshing the amount of albums
|
||||
for (album in artistAlbums) {
|
||||
album.artist = artist
|
||||
|
|
Loading…
Reference in a new issue