fix: Fix Playlist image loading

This commit is contained in:
Prathamesh More 2023-03-08 18:41:22 +05:30
parent b9f3e7979b
commit 125681b938
5 changed files with 15 additions and 18 deletions

View file

@ -107,9 +107,7 @@ class PlaylistAdapter(
holder.image?.setImageDrawable(getIconRes())
} else {
Glide.with(activity)
.load(
PlaylistPreview(playlist)
)
.load(PlaylistPreview(playlist))
.playlistOptions()
.into(holder.image!!)
}

View file

@ -76,7 +76,7 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
viewModel.getPlaylist().observe(viewLifecycleOwner) { playlistWithSongs ->
playlist = playlistWithSongs
Glide.with(this)
.load(PlaylistPreview(playlist))
.load(PlaylistPreview(playlistWithSongs))
.playlistOptions()
.into(binding.image)
binding.title.text = playlist.playlistEntity.playlistName

View file

@ -148,9 +148,9 @@ object RetroGlideExtension {
.signature(createSignature(file))
}
fun <T> RequestBuilder<T>.playlistOptions(
): RequestBuilder<T> {
return diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
fun <T> RequestBuilder<T>.playlistOptions(): RequestBuilder<T> {
return diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.placeholder(getDrawable(DEFAULT_ALBUM_IMAGE))
.error(getDrawable(DEFAULT_ALBUM_IMAGE))
}

View file

@ -11,21 +11,20 @@ class PlaylistPreview(val playlistWithSongs: PlaylistWithSongs) {
val songs: List<Song> get() = playlistWithSongs.songs.toSongs()
override fun equals(other: Any?): Boolean {
if (other is PlaylistPreview) {
if (other.playlistEntity.playListId != playlistEntity.playListId) {
return false
}
if (other.songs.size != songs.size) {
return false
}
println("Glide equals $this $other")
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as PlaylistPreview
if (other.playlistEntity.playListId != playlistEntity.playListId) return false
if (other.songs.size != songs.size) return false
return true
}
return false
}
override fun hashCode(): Int {
var result = playlistEntity.playListId.hashCode()
result = 31 * result + playlistWithSongs.songs.size
println("Glide $result")
return result
}
}

View file

@ -17,7 +17,7 @@ class PlaylistPreviewFetcher(val context: Context, private val playlistPreview:
val bitmap =
AutoGeneratedPlaylistBitmap.getBitmap(
context,
playlistPreview.songs.shuffled()
playlistPreview.songs
)
callback.onDataReady(bitmap)
} catch (e: Exception) {