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())
|
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,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(
|
||||||
|
|
Loading…
Reference in a new issue