diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt b/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt index f3c8cc60a..561d32b91 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverFetcher.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.data.coil +import androidx.core.net.toUri import coil.ImageLoader import coil.decode.DataSource import coil.decode.ImageSource @@ -10,6 +11,7 @@ import coil.fetch.SourceResult import coil.network.HttpException import coil.request.Options import coil.request.Parameters +import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher.Companion.USE_CUSTOM_COVER import eu.kanade.tachiyomi.network.await @@ -24,6 +26,7 @@ import okio.Path.Companion.toOkioPath import okio.Source import okio.buffer import okio.sink +import okio.source import tachiyomi.core.util.system.logcat import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.manga.model.MangaCover @@ -69,8 +72,9 @@ class MangaCoverFetcher( // diskCacheKey is thumbnail_url if (url == null) error("No cover specified") return when (getResourceType(url)) { - Type.URL -> httpLoader() Type.File -> fileLoader(File(url.substringAfter("file://"))) + Type.URI -> fileUriLoader(url) + Type.URL -> httpLoader() 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 { // Only cache separately if it's a library item val libraryCoverCacheFile = if (isLibraryManga) { @@ -256,12 +272,15 @@ class MangaCoverFetcher( cover.isNullOrEmpty() -> null cover.startsWith("http", true) || cover.startsWith("Custom-", true) -> Type.URL cover.startsWith("/") || cover.startsWith("file://") -> Type.File + cover.startsWith("content") -> Type.URI else -> null } } private enum class Type { - File, URL + File, + URI, + URL, } class MangaFactory( diff --git a/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt b/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt index 1305001f5..6177e7746 100644 --- a/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt +++ b/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt @@ -127,7 +127,7 @@ actual class LocalSource( // Try to find the cover 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 override suspend fun getMangaDetails(manga: SManga): SManga = withIOContext { coverManager.find(manga.url)?.let { - manga.thumbnail_url = it.filePath + manga.thumbnail_url = it.uri.toString() } // Augment manga details based on metadata files