mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Handle content URIs for covers
Co-authored-by: jmir1 <jmir1@users.noreply.github.com>
This commit is contained in:
		| @@ -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( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user