diff --git a/app/src/main/java/code/name/monkey/retromusic/glide/ArtistGlideRequest.java b/app/src/main/java/code/name/monkey/retromusic/glide/ArtistGlideRequest.java index 4d9d2124..c11ffcc2 100644 --- a/app/src/main/java/code/name/monkey/retromusic/glide/ArtistGlideRequest.java +++ b/app/src/main/java/code/name/monkey/retromusic/glide/ArtistGlideRequest.java @@ -62,7 +62,7 @@ public class ArtistGlideRequest { boolean hasCustomImage = CustomArtistImageUtil.Companion.getInstance(App.Companion.getContext()) .hasCustomArtistImage(artist); if (noCustomImage || !hasCustomImage) { - return requestManager.load(new ArtistImage(artist.getName())); + return requestManager.load(new ArtistImage(artist)); } else { return requestManager.load(CustomArtistImageUtil.getFile(artist)); } diff --git a/app/src/main/java/code/name/monkey/retromusic/glide/artistimage/ArtistImageLoader.kt b/app/src/main/java/code/name/monkey/retromusic/glide/artistimage/ArtistImageLoader.kt index 43d23120..f9992d12 100644 --- a/app/src/main/java/code/name/monkey/retromusic/glide/artistimage/ArtistImageLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/glide/artistimage/ArtistImageLoader.kt @@ -15,6 +15,7 @@ package code.name.monkey.retromusic.glide.artistimage import android.content.Context +import code.name.monkey.retromusic.model.Artist import code.name.monkey.retromusic.model.Data import code.name.monkey.retromusic.network.DeezerService import code.name.monkey.retromusic.util.MusicUtil @@ -34,7 +35,15 @@ import java.io.IOException import java.io.InputStream import java.util.concurrent.TimeUnit -class ArtistImage(val artistName: String) +class ArtistImage { + val artist: Artist + val artistName: String + + constructor(artist: Artist) { + this.artist = artist + this.artistName = artist.name + } +} class ArtistImageFetcher( private val context: Context, @@ -85,9 +94,12 @@ class ArtistImageFetcher( val glideUrl = GlideUrl(imageUrl) urlFetcher = urlLoader.getResourceFetcher(glideUrl, width, height) urlFetcher?.loadData(priority) - } else null + } else { + // Image not found by deezer. Use an album cover instead + getFallbackAlbumImage() + } } catch (e: Exception) { - null + getFallbackAlbumImage() } } else return null } @@ -102,6 +114,11 @@ class ArtistImageFetcher( else -> "" } } + + private fun getFallbackAlbumImage(): InputStream? { + val imageUri = MusicUtil.getMediaStoreAlbumCoverUri(model.artist.safeGetFirstAlbum().id) + return context.getContentResolver().openInputStream(imageUri) + } } class ArtistImageLoader(