Cover Update Followup to Address #3139 (#3150)

* update cover logic when thumbnail url becomes null

* always clear cover on refresh even if custom cover is set

* remove concurrency changes
This commit is contained in:
MCAxiaz
2020-05-10 20:10:31 -07:00
committed by GitHub
parent dd1b5c7ea7
commit 5723c184b1
4 changed files with 42 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.model.SManga
import java.util.Date
fun Manga.isLocal() = source == LocalSource.ID
@@ -11,14 +12,30 @@ 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) {
cover_last_modified = Date().time
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
if (!isLocal()) {
coverCache.deleteFromCache(this, false)
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