Merge pull request #890 from tnyeanderson/fixartistart
Fix Artist Images
This commit is contained in:
commit
ccf123a481
2 changed files with 21 additions and 4 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue