mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix(coil): Set ratio and colors never called for URI
This commit is contained in:
parent
b220705492
commit
2c0c17f287
2 changed files with 18 additions and 12 deletions
|
@ -61,7 +61,7 @@ class MangaCoverFetcher(
|
|||
if (options.extras.getOrDefault(USE_CUSTOM_COVER_KEY)) {
|
||||
val customCoverFile = customCoverFileLazy.value
|
||||
if (customCoverFile.exists()) {
|
||||
setRatioAndColorsInScope(manga, customCoverFile)
|
||||
setRatioAndColorsInScope(manga, UniFile.fromFile(customCoverFile))
|
||||
return fileLoader(customCoverFile)
|
||||
}
|
||||
}
|
||||
|
@ -70,10 +70,14 @@ class MangaCoverFetcher(
|
|||
return when (getResourceType(url)) {
|
||||
Type.URL -> httpLoader()
|
||||
Type.File -> {
|
||||
setRatioAndColorsInScope(manga, File(url.substringAfter("file://")))
|
||||
fileLoader(File(url.substringAfter("file://")))
|
||||
val file = File(url.substringAfter("file://"))
|
||||
setRatioAndColorsInScope(manga, UniFile.fromFile(file))
|
||||
fileLoader(file)
|
||||
}
|
||||
Type.URI -> {
|
||||
setRatioAndColorsInScope(manga, UniFile.fromUri(options.context, url.toUri()))
|
||||
fileUriLoader(url)
|
||||
}
|
||||
Type.URI -> fileUriLoader(url)
|
||||
null -> error("Invalid image")
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +112,7 @@ class MangaCoverFetcher(
|
|||
if (!manga.favorite) {
|
||||
coverFile.setLastModified(Date().time)
|
||||
}
|
||||
setRatioAndColorsInScope(manga, coverFile)
|
||||
setRatioAndColorsInScope(manga, UniFile.fromFile(coverFile))
|
||||
return fileLoader(coverFile)
|
||||
}
|
||||
|
||||
|
@ -119,7 +123,7 @@ class MangaCoverFetcher(
|
|||
val snapshotCoverCache = moveSnapshotToCoverCache(snapshot, coverFile)
|
||||
if (snapshotCoverCache != null) {
|
||||
// Read from cover cache after added to library
|
||||
setRatioAndColorsInScope(manga, snapshotCoverCache)
|
||||
setRatioAndColorsInScope(manga, UniFile.fromFile(snapshotCoverCache))
|
||||
return fileLoader(snapshotCoverCache)
|
||||
}
|
||||
|
||||
|
@ -288,7 +292,7 @@ class MangaCoverFetcher(
|
|||
)
|
||||
}
|
||||
|
||||
private fun setRatioAndColorsInScope(manga: Manga, ogFile: File? = null, force: Boolean = false) {
|
||||
private fun setRatioAndColorsInScope(manga: Manga, ogFile: UniFile? = null, force: Boolean = false) {
|
||||
fileScope.launch {
|
||||
MangaCoverMetadata.setRatioAndColors(manga, ogFile, force)
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package eu.kanade.tachiyomi.util.manga
|
|||
import android.graphics.BitmapFactory
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.palette.graphics.Palette
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.coil.getBestColor
|
||||
import eu.kanade.tachiyomi.data.database.models.dominantCoverColors
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import java.io.File
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
|
@ -49,14 +49,16 @@ object MangaCoverMetadata {
|
|||
)
|
||||
}
|
||||
|
||||
fun setRatioAndColors(manga: Manga, ogFile: File? = null, force: Boolean = false) {
|
||||
fun setRatioAndColors(manga: Manga, ogFile: UniFile? = null, force: Boolean = false) {
|
||||
if (!manga.favorite) {
|
||||
remove(manga)
|
||||
}
|
||||
if (manga.vibrantCoverColor != null && !manga.favorite) return
|
||||
val file = ogFile ?: coverCache.getCustomCoverFile(manga).takeIf { it.exists() } ?: coverCache.getCoverFile(manga.thumbnail_url, !manga.favorite)
|
||||
val file = ogFile
|
||||
?: UniFile.fromFile(coverCache.getCustomCoverFile(manga))?.takeIf { it.exists() }
|
||||
?: UniFile.fromFile(coverCache.getCoverFile(manga.thumbnail_url, !manga.favorite))
|
||||
// if the file exists and the there was still an error then the file is corrupted
|
||||
if (file != null && file.exists()) {
|
||||
if (file?.exists() == true) {
|
||||
val options = BitmapFactory.Options()
|
||||
val hasVibrantColor = if (manga.favorite) manga.vibrantCoverColor != null else true
|
||||
if (manga.dominantCoverColors != null && hasVibrantColor && !force) {
|
||||
|
@ -64,7 +66,7 @@ object MangaCoverMetadata {
|
|||
} else {
|
||||
options.inSampleSize = 4
|
||||
}
|
||||
val bitmap = BitmapFactory.decodeFile(file.path, options)
|
||||
val bitmap = BitmapFactory.decodeFile(file.filePath, options)
|
||||
if (bitmap != null) {
|
||||
Palette.from(bitmap).generate {
|
||||
if (it == null) return@generate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue