Album art fallback working
This commit is contained in:
parent
0069253043
commit
1982ccd710
2 changed files with 25 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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,11 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.glide.artistimage
|
package code.name.monkey.retromusic.glide.artistimage
|
||||||
|
|
||||||
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import androidx.core.net.toFile
|
||||||
|
import code.name.monkey.retromusic.repository.ArtistRepository
|
||||||
|
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
|
||||||
|
@ -30,11 +34,20 @@ import com.bumptech.glide.load.model.stream.StreamModelLoader
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
import java.io.File
|
||||||
import java.io.IOException
|
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 +98,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 +118,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