Clear cover cache when refreshing manga, even if it's the same url

This commit is contained in:
Jays2Kings 2021-03-21 13:59:51 -04:00
parent 73df525939
commit 77a0244373
3 changed files with 7 additions and 44 deletions

View File

@ -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 {

View File

@ -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()

View File

@ -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