Merge pull request #890 from tnyeanderson/fixartistart

Fix Artist Images
This commit is contained in:
Hemanth S 2020-10-06 09:32:41 +05:30 committed by GitHub
commit ccf123a481
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View file

@ -62,7 +62,7 @@ public class ArtistGlideRequest {
boolean hasCustomImage = CustomArtistImageUtil.Companion.getInstance(App.Companion.getContext()) boolean hasCustomImage = CustomArtistImageUtil.Companion.getInstance(App.Companion.getContext())
.hasCustomArtistImage(artist); .hasCustomArtistImage(artist);
if (noCustomImage || !hasCustomImage) { if (noCustomImage || !hasCustomImage) {
return requestManager.load(new ArtistImage(artist.getName())); return requestManager.load(new ArtistImage(artist));
} else { } else {
return requestManager.load(CustomArtistImageUtil.getFile(artist)); return requestManager.load(CustomArtistImageUtil.getFile(artist));
} }

View file

@ -15,6 +15,7 @@
package code.name.monkey.retromusic.glide.artistimage package code.name.monkey.retromusic.glide.artistimage
import android.content.Context import android.content.Context
import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.model.Data import code.name.monkey.retromusic.model.Data
import code.name.monkey.retromusic.network.DeezerService import code.name.monkey.retromusic.network.DeezerService
import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.MusicUtil
@ -34,7 +35,15 @@ import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.util.concurrent.TimeUnit 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( class ArtistImageFetcher(
private val context: Context, private val context: Context,
@ -85,9 +94,12 @@ class ArtistImageFetcher(
val glideUrl = GlideUrl(imageUrl) val glideUrl = GlideUrl(imageUrl)
urlFetcher = urlLoader.getResourceFetcher(glideUrl, width, height) urlFetcher = urlLoader.getResourceFetcher(glideUrl, width, height)
urlFetcher?.loadData(priority) urlFetcher?.loadData(priority)
} else null } else {
// Image not found by deezer. Use an album cover instead
getFallbackAlbumImage()
}
} catch (e: Exception) { } catch (e: Exception) {
null getFallbackAlbumImage()
} }
} else return null } else return null
} }
@ -102,6 +114,11 @@ class ArtistImageFetcher(
else -> "" else -> ""
} }
} }
private fun getFallbackAlbumImage(): InputStream? {
val imageUri = MusicUtil.getMediaStoreAlbumCoverUri(model.artist.safeGetFirstAlbum().id)
return context.getContentResolver().openInputStream(imageUri)
}
} }
class ArtistImageLoader( class ArtistImageLoader(