From b3611eef9d81388f4e6aa153e1c123311b3ca881 Mon Sep 17 00:00:00 2001 From: MCAxiaz Date: Tue, 21 Apr 2020 06:13:23 -0700 Subject: [PATCH] Bug/2894 covers not updating (#2908) * Use a wrapper around Manga to supply glide with proper equals() and hashCode() impl. for caching * reload image if url has changed * ignore case for http scheme comparison * more ignore case for http scheme comparison * fix indenting * use data class for MangaThumbnail --- .../tachiyomi/data/glide/MangaThumbnail.kt | 7 ++++++ ...Loader.kt => MangaThumbnailModelLoader.kt} | 22 ++++++++++--------- .../tachiyomi/data/glide/TachiGlideModule.kt | 3 +-- .../data/library/LibraryUpdateService.kt | 3 ++- .../tachiyomi/ui/library/LibraryGridHolder.kt | 3 ++- .../tachiyomi/ui/library/LibraryListHolder.kt | 3 ++- .../ui/manga/info/MangaInfoController.kt | 12 +++++++--- .../tachiyomi/ui/migration/MangaHolder.kt | 3 ++- .../ui/reader/viewer/pager/PagerPageHolder.kt | 2 +- .../viewer/webtoon/WebtoonPageHolder.kt | 2 +- .../ui/recent/history/HistoryHolder.kt | 3 ++- .../ui/recent/updates/UpdatesHolder.kt | 3 ++- .../ui/source/browse/SourceGridHolder.kt | 3 ++- .../ui/source/browse/SourceListHolder.kt | 3 ++- .../global_search/GlobalSearchCardHolder.kt | 3 ++- 15 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaThumbnail.kt rename app/src/main/java/eu/kanade/tachiyomi/data/glide/{MangaModelLoader.kt => MangaThumbnailModelLoader.kt} (88%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaThumbnail.kt b/app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaThumbnail.kt new file mode 100644 index 0000000000..8fcab915c9 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaThumbnail.kt @@ -0,0 +1,7 @@ +package eu.kanade.tachiyomi.data.glide + +import eu.kanade.tachiyomi.data.database.models.Manga + +data class MangaThumbnail(val manga: Manga, val url: String?) + +fun Manga.toMangaThumbnail() = MangaThumbnail(this, this.thumbnail_url) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaModelLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaThumbnailModelLoader.kt similarity index 88% rename from app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaModelLoader.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaThumbnailModelLoader.kt index 3a1aeedd1f..44f23243af 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaModelLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/glide/MangaThumbnailModelLoader.kt @@ -31,7 +31,7 @@ import uy.kohesive.injekt.injectLazy * * @param context the application context. */ -class MangaModelLoader : ModelLoader { +class MangaThumbnailModelLoader : ModelLoader { /** * Cover cache where persistent covers are stored. @@ -60,18 +60,18 @@ class MangaModelLoader : ModelLoader { private val cachedHeaders = hashMapOf() /** - * Factory class for creating [MangaModelLoader] instances. + * Factory class for creating [MangaThumbnailModelLoader] instances. */ - class Factory : ModelLoaderFactory { + class Factory : ModelLoaderFactory { - override fun build(multiFactory: MultiModelLoaderFactory): ModelLoader { - return MangaModelLoader() + override fun build(multiFactory: MultiModelLoaderFactory): ModelLoader { + return MangaThumbnailModelLoader() } override fun teardown() {} } - override fun handles(model: Manga): Boolean { + override fun handles(model: MangaThumbnail): Boolean { return true } @@ -83,18 +83,20 @@ class MangaModelLoader : ModelLoader { * @param height the height of the view where the resource will be loaded. */ override fun buildLoadData( - manga: Manga, + mangaThumbnail: MangaThumbnail, width: Int, height: Int, options: Options ): ModelLoader.LoadData? { // Check thumbnail is not null or empty - val url = manga.thumbnail_url + val url = mangaThumbnail.url if (url == null || url.isEmpty()) { return null } - if (url.startsWith("http")) { + val manga = mangaThumbnail.manga + + if (url.startsWith("http", true)) { val source = sourceManager.get(manga.source) as? HttpSource val glideUrl = GlideUrl(url, getHeaders(manga, source)) @@ -126,7 +128,7 @@ class MangaModelLoader : ModelLoader { * * @param manga the model. */ - fun getHeaders(manga: Manga, source: HttpSource?): Headers { + private fun getHeaders(manga: Manga, source: HttpSource?): Headers { if (source == null) return LazyHeaders.DEFAULT return cachedHeaders.getOrPut(manga.source) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt b/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt index eb65782fc6..40d57b6fdd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/glide/TachiGlideModule.kt @@ -13,7 +13,6 @@ import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.module.AppGlideModule import com.bumptech.glide.request.RequestOptions -import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.network.NetworkHelper import java.io.InputStream import uy.kohesive.injekt.Injekt @@ -36,7 +35,7 @@ class TachiGlideModule : AppGlideModule() { val networkFactory = OkHttpUrlLoader.Factory(Injekt.get().client) registry.replace(GlideUrl::class.java, InputStream::class.java, networkFactory) - registry.append(Manga::class.java, InputStream::class.java, MangaModelLoader.Factory()) + registry.append(MangaThumbnail::class.java, InputStream::class.java, MangaThumbnailModelLoader.Factory()) registry.append(InputStream::class.java, InputStream::class.java, PassthroughModelLoader .Factory()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index f7e4d32974..0d52a29803 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadService +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.library.LibraryUpdateRanker.rankingScheme import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start import eu.kanade.tachiyomi.data.notification.NotificationReceiver @@ -557,7 +558,7 @@ class LibraryUpdateService( return try { Glide.with(this) .asBitmap() - .load(manga) + .load(manga.toMangaThumbnail()) .dontTransform() .centerCrop() .circleCrop() 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 45af95fc85..8a2c159899 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 @@ -4,6 +4,7 @@ import android.view.View import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.util.view.visibleIf import kotlinx.android.synthetic.main.source_grid_item.download_text @@ -52,7 +53,7 @@ class LibraryGridHolder( // Update the cover. GlideApp.with(view.context).clear(thumbnail) GlideApp.with(view.context) - .load(item.manga) + .load(item.manga.toMangaThumbnail()) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() .into(thumbnail) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 8d49e2ebae..201c965662 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -4,6 +4,7 @@ import android.view.View import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.util.view.visibleIf import kotlinx.android.synthetic.main.source_list_item.download_text @@ -59,7 +60,7 @@ class LibraryListHolder( // Update the cover. GlideApp.with(itemView.context).clear(thumbnail) GlideApp.with(itemView.context) - .load(item.manga) + .load(item.manga.toMangaThumbnail()) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() .circleCrop() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index e8545a0f55..038de78e0a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.MangaInfoControllerBinding import eu.kanade.tachiyomi.source.Source @@ -61,6 +62,8 @@ class MangaInfoController(private val fromSource: Boolean = false) : private var initialLoad: Boolean = true + private var thumbnailUrl: String? = null + override fun createPresenter(): MangaInfoPresenter { val ctrl = parentController as MangaController return MangaInfoPresenter(ctrl.manga!!, ctrl.source!!, ctrl.mangaFavoriteRelay) @@ -224,15 +227,18 @@ class MangaInfoController(private val fromSource: Boolean = false) : setFavoriteButtonState(manga.favorite) // Set cover if it wasn't already. - if (binding.mangaCover.drawable == null && !manga.thumbnail_url.isNullOrEmpty()) { + if (binding.mangaCover.drawable == null || manga.thumbnail_url != thumbnailUrl) { + thumbnailUrl = manga.thumbnail_url + val mangaThumbnail = manga.toMangaThumbnail() + GlideApp.with(view.context) - .load(manga) + .load(mangaThumbnail) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() .into(binding.mangaCover) GlideApp.with(view.context) - .load(manga) + .load(mangaThumbnail) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() .into(binding.backdrop) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaHolder.kt index 62f322a617..69c608a12f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MangaHolder.kt @@ -4,6 +4,7 @@ import android.view.View import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import kotlinx.android.synthetic.main.source_list_item.thumbnail import kotlinx.android.synthetic.main.source_list_item.title @@ -26,7 +27,7 @@ class MangaHolder( // Update the cover. GlideApp.with(itemView.context).clear(thumbnail) GlideApp.with(itemView.context) - .load(item.manga) + .load(item.manga.toMangaThumbnail()) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() .circleCrop() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index 3c68472086..7babac154e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt @@ -411,7 +411,7 @@ class PagerPageHolder( } val imageUrl = page.imageUrl - if (imageUrl.orEmpty().startsWith("http")) { + if (imageUrl.orEmpty().startsWith("http", true)) { PagerButton(context, viewer).apply { layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { setMargins(margins, margins, margins, margins) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt index d72cacb054..b963c749ba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt @@ -454,7 +454,7 @@ class WebtoonPageHolder( } val imageUrl = page?.imageUrl - if (imageUrl.orEmpty().startsWith("http")) { + if (imageUrl.orEmpty().startsWith("http", true)) { AppCompatButton(context).apply { layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { setMargins(0, margins, 0, margins) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryHolder.kt index 1a3ea2e4b8..2847af3559 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryHolder.kt @@ -5,6 +5,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.util.lang.toTimestampString import java.util.Date @@ -67,7 +68,7 @@ class HistoryHolder( GlideApp.with(itemView.context).clear(cover) if (!manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(itemView.context) - .load(manga) + .load(manga.toMangaThumbnail()) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .centerCrop() .into(cover) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt index 140478e5e2..b5a52a9a8d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt @@ -6,6 +6,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.util.system.getResourceColor import kotlinx.android.synthetic.main.updates_item.chapter_title @@ -58,7 +59,7 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) GlideApp.with(itemView.context).clear(manga_cover) if (!item.manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(itemView.context) - .load(item.manga) + .load(item.manga.toMangaThumbnail()) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .circleCrop() .into(manga_cover) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceGridHolder.kt index 6cf49dc3cf..ffdf84b0e1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceGridHolder.kt @@ -5,6 +5,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.widget.StateImageViewTarget import kotlinx.android.synthetic.main.source_grid_item.progress import kotlinx.android.synthetic.main.source_grid_item.thumbnail @@ -41,7 +42,7 @@ class SourceGridHolder(private val view: View, private val adapter: FlexibleAdap GlideApp.with(view.context).clear(thumbnail) if (!manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(view.context) - .load(manga) + .load(manga.toMangaThumbnail()) .diskCacheStrategy(DiskCacheStrategy.DATA) .centerCrop() .placeholder(android.R.color.transparent) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceListHolder.kt index dc87a898c4..9ab6493ce0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceListHolder.kt @@ -7,6 +7,7 @@ import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.util.system.getResourceColor import kotlinx.android.synthetic.main.source_list_item.thumbnail import kotlinx.android.synthetic.main.source_list_item.title @@ -42,7 +43,7 @@ class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) : GlideApp.with(view.context).clear(thumbnail) if (!manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(view.context) - .load(manga) + .load(manga.toMangaThumbnail()) .diskCacheStrategy(DiskCacheStrategy.DATA) .centerCrop() .circleCrop() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchCardHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchCardHolder.kt index 55ae253ac2..cfd36f8659 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchCardHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchCardHolder.kt @@ -4,6 +4,7 @@ import android.view.View import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.glide.GlideApp +import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.widget.StateImageViewTarget import kotlinx.android.synthetic.main.global_search_controller_card_item.itemImage @@ -42,7 +43,7 @@ class GlobalSearchCardHolder(view: View, adapter: GlobalSearchCardAdapter) : GlideApp.with(itemView.context).clear(itemImage) if (!manga.thumbnail_url.isNullOrEmpty()) { GlideApp.with(itemView.context) - .load(manga) + .load(manga.toMangaThumbnail()) .diskCacheStrategy(DiskCacheStrategy.DATA) .centerCrop() .skipMemoryCache(true)