From 927700f4e2252b7dcab2190a76c5e8ebe0ae35dc Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 9 May 2020 13:18:37 -0400 Subject: [PATCH] Fixed cover being fetched multiple times on update Should fix bad caching of images as well --- .../tachiyomi/ui/library/LibraryGridHolder.kt | 2 +- .../ui/manga/MangaDetailsController.kt | 4 +++- .../tachiyomi/ui/manga/MangaHeaderHolder.kt | 20 +++++++++++++------ .../tachiyomi/ui/recents/RecentMangaHolder.kt | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 22d8216c8c..1f7a662ed6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -81,7 +81,7 @@ class LibraryGridHolder( private fun setCover(manga: Manga, id: Long) { if ((adapter.recyclerView.context as? Activity)?.isDestroyed == true) return GlideApp.with(adapter.recyclerView.context).load(manga) - .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .signature(ObjectKey(MangaImpl.getLastCoverFetch(id).toString())) .apply { if (fixedSize) centerCrop() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index 5727c816eb..1d83a1292c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -368,8 +368,9 @@ class MangaDetailsController : BaseController, /** Get the color of the manga cover based on the current theme */ fun setPaletteColor() { val view = view ?: return + coverColor = null GlideApp.with(view.context).load(manga) - .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .signature(ObjectKey(MangaImpl.getLastCoverFetch(manga!!.id!!).toString())) .into(object : CustomTarget() { override fun onResourceReady( @@ -390,6 +391,7 @@ class MangaDetailsController : BaseController, } coverColor = backDropColor getHeader()?.setBackDrop(backDropColor) + getHeader()?.updateCover(presenter.manga, resource) if (toolbarIsColored) { val translucentColor = ColorUtils.setAlphaComponent(backDropColor, 175) (activity as MainActivity).toolbar.setBackgroundColor(translucentColor) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt index 51d2fc272d..6f67080a11 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.manga import android.annotation.SuppressLint import android.content.res.ColorStateList import android.graphics.Color +import android.graphics.drawable.Drawable import android.view.MotionEvent import android.view.View import android.view.ViewGroup @@ -255,12 +256,7 @@ class MangaHeaderHolder( } if (!manga.initialized) return - GlideApp.with(view.context).load(manga).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) - .signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())) - .into(manga_cover) - GlideApp.with(view.context).load(manga).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) - .signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())).centerCrop() - .transition(DrawableTransitionOptions.withCrossFade()).into(backdrop) + updateCover(manga) } private fun MaterialButton.checked(checked: Boolean) { @@ -312,6 +308,18 @@ class MangaHeaderHolder( } } + fun updateCover(manga: Manga, cover: Drawable? = null) { + if (adapter.delegate.coverColor() == null) return + GlideApp.with(view.context).load(cover ?: manga) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())) + .into(manga_cover) + GlideApp.with(view.context).load(cover ?: manga) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())).centerCrop() + .transition(DrawableTransitionOptions.withCrossFade()).into(backdrop) + } + fun expand() { sub_item_group.visible() if (!showMoreButton) more_button_group.gone() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt index 0c0caddf2f..6cd71f10c0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt @@ -71,7 +71,7 @@ class RecentMangaHolder( ) } GlideApp.with(itemView.context).load(item.mch.manga).diskCacheStrategy(DiskCacheStrategy - .AUTOMATIC) + .RESOURCE) .signature(ObjectKey(MangaImpl.getLastCoverFetch(item.mch.manga.id!!).toString())).into(cover_thumbnail) notifyStatus( if (adapter.isSelected(adapterPosition)) Download.CHECKED else item.status,