Handle content URIs for covers
Co-authored-by: jmir1 <jmir1@users.noreply.github.com>
This commit is contained in:
parent
24e1b4034e
commit
e5263d0345
2 changed files with 23 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
package eu.kanade.tachiyomi.data.coil
|
package eu.kanade.tachiyomi.data.coil
|
||||||
|
|
||||||
|
import androidx.core.net.toUri
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import coil.decode.DataSource
|
import coil.decode.DataSource
|
||||||
import coil.decode.ImageSource
|
import coil.decode.ImageSource
|
||||||
|
@ -10,6 +11,7 @@ import coil.fetch.SourceResult
|
||||||
import coil.network.HttpException
|
import coil.network.HttpException
|
||||||
import coil.request.Options
|
import coil.request.Options
|
||||||
import coil.request.Parameters
|
import coil.request.Parameters
|
||||||
|
import com.hippo.unifile.UniFile
|
||||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||||
import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher.Companion.USE_CUSTOM_COVER
|
import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher.Companion.USE_CUSTOM_COVER
|
||||||
import eu.kanade.tachiyomi.network.await
|
import eu.kanade.tachiyomi.network.await
|
||||||
|
@ -24,6 +26,7 @@ import okio.Path.Companion.toOkioPath
|
||||||
import okio.Source
|
import okio.Source
|
||||||
import okio.buffer
|
import okio.buffer
|
||||||
import okio.sink
|
import okio.sink
|
||||||
|
import okio.source
|
||||||
import tachiyomi.core.util.system.logcat
|
import tachiyomi.core.util.system.logcat
|
||||||
import tachiyomi.domain.manga.model.Manga
|
import tachiyomi.domain.manga.model.Manga
|
||||||
import tachiyomi.domain.manga.model.MangaCover
|
import tachiyomi.domain.manga.model.MangaCover
|
||||||
|
@ -69,8 +72,9 @@ class MangaCoverFetcher(
|
||||||
// diskCacheKey is thumbnail_url
|
// diskCacheKey is thumbnail_url
|
||||||
if (url == null) error("No cover specified")
|
if (url == null) error("No cover specified")
|
||||||
return when (getResourceType(url)) {
|
return when (getResourceType(url)) {
|
||||||
Type.URL -> httpLoader()
|
|
||||||
Type.File -> fileLoader(File(url.substringAfter("file://")))
|
Type.File -> fileLoader(File(url.substringAfter("file://")))
|
||||||
|
Type.URI -> fileUriLoader(url)
|
||||||
|
Type.URL -> httpLoader()
|
||||||
null -> error("Invalid image")
|
null -> error("Invalid image")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +87,18 @@ class MangaCoverFetcher(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fileUriLoader(uri: String): FetchResult {
|
||||||
|
val source = UniFile.fromUri(options.context, uri.toUri())!!
|
||||||
|
.openInputStream()
|
||||||
|
.source()
|
||||||
|
.buffer()
|
||||||
|
return SourceResult(
|
||||||
|
source = ImageSource(source = source, context = options.context),
|
||||||
|
mimeType = "image/*",
|
||||||
|
dataSource = DataSource.DISK,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun httpLoader(): FetchResult {
|
private suspend fun httpLoader(): FetchResult {
|
||||||
// Only cache separately if it's a library item
|
// Only cache separately if it's a library item
|
||||||
val libraryCoverCacheFile = if (isLibraryManga) {
|
val libraryCoverCacheFile = if (isLibraryManga) {
|
||||||
|
@ -256,12 +272,15 @@ class MangaCoverFetcher(
|
||||||
cover.isNullOrEmpty() -> null
|
cover.isNullOrEmpty() -> null
|
||||||
cover.startsWith("http", true) || cover.startsWith("Custom-", true) -> Type.URL
|
cover.startsWith("http", true) || cover.startsWith("Custom-", true) -> Type.URL
|
||||||
cover.startsWith("/") || cover.startsWith("file://") -> Type.File
|
cover.startsWith("/") || cover.startsWith("file://") -> Type.File
|
||||||
|
cover.startsWith("content") -> Type.URI
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum class Type {
|
private enum class Type {
|
||||||
File, URL
|
File,
|
||||||
|
URI,
|
||||||
|
URL,
|
||||||
}
|
}
|
||||||
|
|
||||||
class MangaFactory(
|
class MangaFactory(
|
||||||
|
|
|
@ -127,7 +127,7 @@ actual class LocalSource(
|
||||||
|
|
||||||
// Try to find the cover
|
// Try to find the cover
|
||||||
coverManager.find(mangaDir.name.orEmpty())?.let {
|
coverManager.find(mangaDir.name.orEmpty())?.let {
|
||||||
thumbnail_url = it.filePath
|
thumbnail_url = it.uri.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ actual class LocalSource(
|
||||||
// Manga details related
|
// Manga details related
|
||||||
override suspend fun getMangaDetails(manga: SManga): SManga = withIOContext {
|
override suspend fun getMangaDetails(manga: SManga): SManga = withIOContext {
|
||||||
coverManager.find(manga.url)?.let {
|
coverManager.find(manga.url)?.let {
|
||||||
manga.thumbnail_url = it.filePath
|
manga.thumbnail_url = it.uri.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Augment manga details based on metadata files
|
// Augment manga details based on metadata files
|
||||||
|
|
Reference in a new issue