Artist fallback
Fallback to fetch Album cover for missing artists
This commit is contained in:
parent
6fd3f36e31
commit
2af13a4e6c
2 changed files with 16 additions and 7 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,7 @@ 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)
|
||||||
|
|
||||||
class ArtistImageFetcher(
|
class ArtistImageFetcher(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
|
@ -53,7 +54,7 @@ class ArtistImageFetcher(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getId(): String {
|
override fun getId(): String {
|
||||||
return model.artistName
|
return model.artist.name
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
|
@ -62,10 +63,10 @@ class ArtistImageFetcher(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadData(priority: Priority?): InputStream? {
|
override fun loadData(priority: Priority?): InputStream? {
|
||||||
if (!MusicUtil.isArtistNameUnknown(model.artistName) &&
|
if (!MusicUtil.isArtistNameUnknown(model.artist.name) &&
|
||||||
PreferenceUtil.isAllowedToDownloadMetadata()
|
PreferenceUtil.isAllowedToDownloadMetadata()
|
||||||
) {
|
) {
|
||||||
val artists = model.artistName.split(",")
|
val artists = model.artist.name.split(",")
|
||||||
val response = deezerService.getArtistImage(artists[0]).execute()
|
val response = deezerService.getArtistImage(artists[0]).execute()
|
||||||
|
|
||||||
if (!response.isSuccessful) {
|
if (!response.isSuccessful) {
|
||||||
|
@ -85,13 +86,21 @@ 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 {
|
||||||
|
getFallbackAlbumImage()
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
null
|
getFallbackAlbumImage()
|
||||||
}
|
}
|
||||||
} else return null
|
} else return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFallbackAlbumImage(): InputStream? {
|
||||||
|
val imageUri = MusicUtil.getMediaStoreAlbumCoverUri(model.artist.safeGetFirstAlbum().id)
|
||||||
|
return context.contentResolver.openInputStream(imageUri)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getHighestQuality(imageUrl: Data): String {
|
private fun getHighestQuality(imageUrl: Data): String {
|
||||||
return when {
|
return when {
|
||||||
imageUrl.pictureXl.isNotEmpty() -> imageUrl.pictureXl
|
imageUrl.pictureXl.isNotEmpty() -> imageUrl.pictureXl
|
||||||
|
|
Loading…
Reference in a new issue