From 77a02443734df3ffd695400cf137293f1cef38ec Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sun, 21 Mar 2021 13:59:51 -0400 Subject: [PATCH] Clear cover cache when refreshing manga, even if it's the same url --- .../kanade/tachiyomi/data/cache/CoverCache.kt | 5 ++- .../ui/manga/MangaDetailsPresenter.kt | 3 ++ .../kanade/tachiyomi/util/MangaExtensions.kt | 43 ------------------- 3 files changed, 7 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt index ce01535bb1..d3016a89a3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/CoverCache.kt @@ -228,7 +228,10 @@ class CoverCache(val context: Context) { // Remove file val file = getCoverFile(manga) if (deleteCustom) deleteCustomCover(manga) - if (file.exists()) file.delete() + if (file.exists()) { + Coil.imageLoader(context).invalidate(file.name) + file.delete() + } } private fun getCacheDir(dir: String): File { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index ed06e0852a..b96cdfc48d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -4,6 +4,7 @@ import android.app.Application import android.graphics.Bitmap import android.net.Uri import android.os.Environment +import coil.Coil import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper @@ -341,6 +342,8 @@ class MangaDetailsPresenter( if (thumbnailUrl != networkManga.thumbnail_url) { coverCache.deleteFromCache(thumbnailUrl) + } else { + coverCache.deleteFromCache(manga, false) } withContext(Dispatchers.Main) { controller.setPaletteColor() diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt index 54f564e233..dc5421a602 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/MangaExtensions.kt @@ -10,49 +10,6 @@ import java.util.Date fun Manga.isLocal() = source == LocalSource.ID -/* -/** - * Call before updating [Manga.thumbnail_url] to ensure old cover can be cleared from cache - */ -fun Manga.prepUpdateCover(coverCache: CoverCache, remoteManga: SManga, refreshSameUrl: Boolean) { - // Never refresh covers if the new url is null, as the current url has possibly become invalid - val newUrl = remoteManga.thumbnail_url ?: return - - // Never refresh covers if the url is empty to avoid "losing" existing covers - if (newUrl.isEmpty()) return - - if (!refreshSameUrl && thumbnail_url == newUrl) return - - when { - isLocal() -> { - cover_last_modified = Date().time - } - hasCustomCover(coverCache) -> { - coverCache.deleteFromCache(this, false) - } - else -> { - cover_last_modified = Date().time - coverCache.deleteFromCache(this, false) - } - } -} - -fun Manga.hasCustomCover(coverCache: CoverCache): Boolean { - return coverCache.getCustomCoverFile(this).exists() -} - -fun Manga.removeCovers(coverCache: CoverCache) { - if (isLocal()) return - - cover_last_modified = Date().time - coverCache.deleteFromCache(this, true) -} - -fun Manga.updateCoverLastModified(db: DatabaseHelper) { - cover_last_modified = Date().time - db.updateMangaCoverLastModified(this).executeAsBlocking() -}*/ - fun Manga.shouldDownloadNewChapters(db: DatabaseHelper, prefs: PreferencesHelper): Boolean { if (!favorite) return false