mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Minor fixes and improvements. Dependency updates. Drop support for the old armeabi and use arm64-v8a instead
This commit is contained in:
		| @@ -0,0 +1,35 @@ | ||||
| package eu.kanade.tachiyomi.data.glide | ||||
|  | ||||
| import com.bumptech.glide.Priority | ||||
| import com.bumptech.glide.load.data.DataFetcher | ||||
| import java.io.File | ||||
| import java.io.IOException | ||||
| import java.io.InputStream | ||||
|  | ||||
| open class FileFetcher(private val file: File) : DataFetcher<InputStream> { | ||||
|  | ||||
|     private var data: InputStream? = null | ||||
|  | ||||
|     override fun loadData(priority: Priority): InputStream { | ||||
|         data = file.inputStream() | ||||
|         return data!! | ||||
|     } | ||||
|  | ||||
|     override fun cleanup() { | ||||
|         data?.let { data -> | ||||
|             try { | ||||
|                 data.close() | ||||
|             } catch (e: IOException) { | ||||
|                 // Ignore | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun cancel() { | ||||
|         // Do nothing. | ||||
|     } | ||||
|  | ||||
|     override fun getId(): String { | ||||
|         return file.toString() | ||||
|     } | ||||
| } | ||||
| @@ -1,29 +1,18 @@ | ||||
| package eu.kanade.tachiyomi.data.glide | ||||
|  | ||||
| import com.bumptech.glide.Priority | ||||
| import com.bumptech.glide.load.data.DataFetcher | ||||
| import eu.kanade.tachiyomi.data.database.models.Manga | ||||
| import java.io.File | ||||
| import java.io.InputStream | ||||
|  | ||||
| class MangaFileFetcher(private val fetcher: DataFetcher<InputStream>, | ||||
|                        private val file: File, | ||||
|                        private val manga: Manga) : DataFetcher<InputStream> { | ||||
|  | ||||
|  | ||||
|     override fun loadData(priority: Priority?): InputStream? { | ||||
|         return fetcher.loadData(priority) | ||||
|     } | ||||
| open class MangaFileFetcher(private val file: File, private val manga: Manga) : FileFetcher(file) { | ||||
|  | ||||
|     /** | ||||
|      * Returns the id for this manga's cover. | ||||
|      * | ||||
|      * Appending the file's modified date to the url, we can force Glide to skip its memory and disk | ||||
|      * lookup step and fetch from our custom cache. This allows us to invalidate Glide's cache when | ||||
|      * the file has changed. If the file doesn't exist it will append a 0. | ||||
|      */ | ||||
|     override fun getId(): String { | ||||
|         return manga.thumbnail_url + file.lastModified() | ||||
|     } | ||||
|  | ||||
|     override fun cancel() { | ||||
|         fetcher.cancel() | ||||
|     } | ||||
|  | ||||
|     override fun cleanup() { | ||||
|         fetcher.cleanup() | ||||
|     } | ||||
| } | ||||
| @@ -44,12 +44,6 @@ class MangaModelLoader(context: Context) : StreamModelLoader<Manga> { | ||||
|     private val baseUrlLoader = Glide.buildModelLoader(GlideUrl::class.java, | ||||
|             InputStream::class.java, context) | ||||
|  | ||||
|     /** | ||||
|      * Base file loader. | ||||
|      */ | ||||
|     private val baseFileLoader = Glide.buildModelLoader(File::class.java, | ||||
|             InputStream::class.java, context) | ||||
|  | ||||
|     /** | ||||
|      * LRU cache whose key is the thumbnail url of the manga, and the value contains the request url | ||||
|      * and the file where it should be stored in case the manga is a favorite. | ||||
| @@ -109,11 +103,8 @@ class MangaModelLoader(context: Context) : StreamModelLoader<Manga> { | ||||
|             // Get the file from the url, removing the scheme if present. | ||||
|             val file = File(url.substringAfter("file://")) | ||||
|  | ||||
|             // Get the resource fetcher for the given file. | ||||
|             val fileFetcher = baseFileLoader.getResourceFetcher(file, width, height) | ||||
|  | ||||
|             // Return an instance of the fetcher providing the needed elements. | ||||
|             return MangaFileFetcher(fileFetcher, file, manga) | ||||
|             return MangaFileFetcher(file, manga) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -21,10 +21,9 @@ import java.io.InputStream | ||||
| class MangaUrlFetcher(private val networkFetcher: DataFetcher<InputStream>, | ||||
|                       private val file: File, | ||||
|                       private val manga: Manga) | ||||
| : DataFetcher<InputStream> { | ||||
| : MangaFileFetcher(file, manga) { | ||||
|  | ||||
|     @Throws(Exception::class) | ||||
|     override fun loadData(priority: Priority): InputStream? { | ||||
|     override fun loadData(priority: Priority): InputStream { | ||||
|         if (manga.favorite) { | ||||
|             synchronized(file) { | ||||
|                 if (!file.exists()) { | ||||
| @@ -51,7 +50,7 @@ class MangaUrlFetcher(private val networkFetcher: DataFetcher<InputStream>, | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             return file.inputStream() | ||||
|             return super.loadData(priority) | ||||
|         } else { | ||||
|             if (file.exists()) { | ||||
|                 file.delete() | ||||
| @@ -60,22 +59,12 @@ class MangaUrlFetcher(private val networkFetcher: DataFetcher<InputStream>, | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the id for this manga's cover. | ||||
|      * | ||||
|      * Appending the file's modified date to the url, we can force Glide to skip its memory and disk | ||||
|      * lookup step and fetch from our custom cache. This allows us to invalidate Glide's cache when | ||||
|      * the file has changed. If the file doesn't exist it will append a 0. | ||||
|      */ | ||||
|     override fun getId(): String { | ||||
|         return manga.thumbnail_url + file.lastModified() | ||||
|     } | ||||
|  | ||||
|     override fun cancel() { | ||||
|         networkFetcher.cancel() | ||||
|     } | ||||
|  | ||||
|     override fun cleanup() { | ||||
|         super.cleanup() | ||||
|         networkFetcher.cleanup() | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -127,7 +127,7 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() { | ||||
|      */ | ||||
|     private fun applyFilters(map: Map<Int, List<Manga>>): Map<Int, List<Manga>> { | ||||
|         // Cached list of downloaded manga directories given a source id. | ||||
|         val mangaDirectories = mutableMapOf<Long, Array<UniFile>>() | ||||
|         val mangaDirsForSource = mutableMapOf<Long, Map<String?, UniFile>>() | ||||
|  | ||||
|         // Cached list of downloaded chapter directories for a manga. | ||||
|         val chapterDirectories = mutableMapOf<Long, Boolean>() | ||||
| @@ -147,15 +147,17 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() { | ||||
|  | ||||
|             // Filter when the download directory doesn't exist or is null. | ||||
|             if (filterDownloaded) { | ||||
|                 val mangaDirs = mangaDirectories.getOrPut(source.id) { | ||||
|                     downloadManager.findSourceDir(source)?.listFiles() ?: emptyArray() | ||||
|                 // Get the directories for the source of the manga. | ||||
|                 val dirsForSource = mangaDirsForSource.getOrPut(source.id) { | ||||
|                     val sourceDir = downloadManager.findSourceDir(source) | ||||
|                     sourceDir?.listFiles()?.associateBy { it.name }.orEmpty() | ||||
|                 } | ||||
|  | ||||
|                 val mangaDirName = downloadManager.getMangaDirName(manga) | ||||
|                 val mangaDir = mangaDirs.find { it.name == mangaDirName } ?: return@f false | ||||
|                 val mangaDir = dirsForSource[mangaDirName] ?: return@f false | ||||
|  | ||||
|                 val hasDirs = chapterDirectories.getOrPut(manga.id!!) { | ||||
|                     (mangaDir.listFiles() ?: emptyArray()).isNotEmpty() | ||||
|                     mangaDir.listFiles()?.isNotEmpty() ?: false | ||||
|                 } | ||||
|                 if (!hasDirs) { | ||||
|                     return@f false | ||||
|   | ||||
		Reference in New Issue
	
	Block a user