|
@@ -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(
|