mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix: Try loading custom cover if non-custom cover is not found
Fixes GH-150
This commit is contained in:
parent
84a3f91b80
commit
65260e8bd7
2 changed files with 18 additions and 12 deletions
|
@ -40,6 +40,7 @@
|
|||
- Fixed status bar stuck in dark mode when app is following system theme
|
||||
- Fixed splash screen state only getting updates if library is empty (Should slightly reduce splash screen duration)
|
||||
- Fixed kitsu tracker issue due to domain change
|
||||
- Fixed entry custom cover won't load if entry doesn't have cover from source
|
||||
|
||||
## Translation
|
||||
- Update Japanese translation (akir45)
|
||||
|
|
|
@ -20,6 +20,9 @@ import eu.kanade.tachiyomi.network.await
|
|||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.util.manga.MangaCoverMetadata
|
||||
import java.io.File
|
||||
import java.net.HttpURLConnection
|
||||
import java.util.Date
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
|
@ -35,9 +38,6 @@ import okio.buffer
|
|||
import okio.sink
|
||||
import okio.source
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.File
|
||||
import java.net.HttpURLConnection
|
||||
import java.util.*
|
||||
|
||||
class MangaCoverFetcher(
|
||||
private val manga: Manga,
|
||||
|
@ -56,7 +56,7 @@ class MangaCoverFetcher(
|
|||
|
||||
override suspend fun fetch(): FetchResult {
|
||||
// diskCacheKey is thumbnail_url
|
||||
url = manga.thumbnail_url ?: error("No cover specified")
|
||||
url = manga.thumbnail_url.orEmpty()
|
||||
return when (getResourceType(url)) {
|
||||
Type.URL -> httpLoader()
|
||||
Type.File -> {
|
||||
|
@ -64,23 +64,28 @@ class MangaCoverFetcher(
|
|||
fileLoader(File(url.substringAfter("file://")))
|
||||
}
|
||||
Type.URI -> fileUriLoader(url)
|
||||
null -> error("Invalid image")
|
||||
null -> tryCustomCover() ?: error("No cover specified")
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("RedundantSuspendModifier")
|
||||
private suspend fun tryCustomCover(): FetchResult? {
|
||||
val customCoverFile by lazy { coverCache.getCustomCoverFile(manga) }
|
||||
if (options.extras.getOrDefault(USE_CUSTOM_COVER_KEY) && customCoverFile.exists()) {
|
||||
setRatioAndColorsInScope(manga, customCoverFile)
|
||||
return fileLoader(customCoverFile)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private suspend fun httpLoader(): FetchResult {
|
||||
val diskRead = options.diskCachePolicy.readEnabled
|
||||
val networkRead = options.networkCachePolicy.readEnabled
|
||||
val onlyCache = !networkRead && diskRead
|
||||
val shouldFetchRemotely = networkRead && !diskRead && !onlyCache
|
||||
val useCustomCover = options.extras.getOrDefault(USE_CUSTOM_COVER_KEY)
|
||||
// Use custom cover if exists
|
||||
if (!shouldFetchRemotely) {
|
||||
val customCoverFile by lazy { coverCache.getCustomCoverFile(manga) }
|
||||
if (useCustomCover && customCoverFile.exists()) {
|
||||
setRatioAndColorsInScope(manga, customCoverFile)
|
||||
return fileLoader(customCoverFile)
|
||||
}
|
||||
val customCoverLoader = tryCustomCover()
|
||||
if (customCoverLoader != null) return customCoverLoader
|
||||
}
|
||||
val coverFile = coverCache.getCoverFile(manga)
|
||||
if (!shouldFetchRemotely && coverFile.exists() && options.diskCachePolicy.readEnabled) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue