The App class implements SingletonImageLoader.Factory to provide a custom ImageLoader for the application. This configuration includes specialized fetchers and decoders for manga covers and page previews, as well as memory cache management and coroutine context limits to optimize performance.
Key components configured:
OkHttpNetworkFetcherFactory: Uses the application's NetworkHelper client.TachiyomiImageDecoder:BufferedSourceFetcher:MangaCoverFetcher (MangaCoverFactory and MangaFactory):PagePreviewFetcher and PagePreviewKeyer:MangaCoverKeyer and MangaKeyer:
Performance settings:
memoryCache: Uses a percentage of the available context memory.crossfade: Duration is scaled by animatorDurationScale.allowRgb565: Enabled on low-RAM devices.fetcherCoroutineContext: Limited to 8 parallel threads on Dispatchers.IO.decoderCoroutineContext: Limited to 3 parallel threads on Dispatchers.IO.
override fun newImageLoader(context: Context): ImageLoader {
return ImageLoader.Builder(this).apply {
val callFactoryLazy = lazy { Injekt.get<NetworkHelper>().client }
components {
add(OkHttpNetworkFetcherFactory(callFactoryLazy::value))
add(TachiyomiImageDecoder.Factory())
add(BufferedSourceFetcher.Factory())
add(MangaCoverFetcher.MangaCoverFactory(callFactoryLazy))
add(MangaCoverFetcher.MangaFactory(callFactoryLazy))
add(PagePreviewFetcher.Factory(callFactoryLazy))
add(MangaCoverKeyer())
add(MangaKeyer())
add(PagePreviewKeyer())
}
memoryCache(MemoryCache.Builder().maxSizePercent(context).build())
crossfade((300 * this@App.animatorDurationScale).toInt())
allowRgb565(DeviceUtil.isLowRamDevice(this))
if (networkPreferences.verboseLogging.get()) logger(DebugLogger())
fetcherCoroutineContext(Dispatchers.IO.limitedParallelism(8))
decoderCoroutineContext(Dispatchers.IO.limitedParallelism(3))
}.build()
}