mirror of
https://github.com/null2264/yokai.git
synced 2025-06-20 18:24:42 +00:00
refactor(download): Singleton cache and provider
This commit is contained in:
parent
bfbbd1b4f3
commit
629f1891f6
4 changed files with 20 additions and 22 deletions
|
@ -62,8 +62,8 @@ import yokai.domain.storage.StorageManager
|
|||
*/
|
||||
class DownloadCache(
|
||||
private val context: Context,
|
||||
private val provider: DownloadProvider,
|
||||
private val sourceManager: SourceManager,
|
||||
private val provider: DownloadProvider = Injekt.get(),
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val storageManager: StorageManager = Injekt.get(),
|
||||
) {
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ import kotlinx.coroutines.flow.flatMapLatest
|
|||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.domain.download.DownloadPreferences
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
|
@ -32,31 +34,21 @@ import yokai.util.lang.getString
|
|||
*
|
||||
* @param context the application context.
|
||||
*/
|
||||
class DownloadManager(val context: Context) {
|
||||
|
||||
/**
|
||||
* The sources manager.
|
||||
*/
|
||||
private val sourceManager by injectLazy<SourceManager>()
|
||||
class DownloadManager(
|
||||
val context: Context,
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val provider: DownloadProvider = Injekt.get(),
|
||||
private val cache: DownloadCache = Injekt.get(),
|
||||
) {
|
||||
|
||||
private val preferences by injectLazy<PreferencesHelper>()
|
||||
|
||||
private val downloadPreferences by injectLazy<DownloadPreferences>()
|
||||
|
||||
/**
|
||||
* Downloads provider, used to retrieve the folders where the chapters are or should be stored.
|
||||
*/
|
||||
private val provider = DownloadProvider(context)
|
||||
|
||||
/**
|
||||
* Cache of downloaded chapters.
|
||||
*/
|
||||
private val cache = DownloadCache(context, provider, sourceManager)
|
||||
|
||||
/**
|
||||
* Downloader whose only task is to download chapters.
|
||||
*/
|
||||
private val downloader = Downloader(context, provider, cache, sourceManager)
|
||||
private val downloader = Downloader(context)
|
||||
|
||||
val isRunning: Boolean get() = downloader.isRunning
|
||||
|
||||
|
|
|
@ -54,7 +54,9 @@ import kotlinx.coroutines.runBlocking
|
|||
import kotlinx.coroutines.supervisorScope
|
||||
import nl.adaptivity.xmlutil.serialization.XML
|
||||
import okhttp3.Response
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.core.archive.ZipWriter
|
||||
import yokai.core.metadata.COMIC_INFO_FILE
|
||||
import yokai.core.metadata.ComicInfo
|
||||
|
@ -71,9 +73,9 @@ import yokai.util.lang.getString
|
|||
*/
|
||||
class Downloader(
|
||||
private val context: Context,
|
||||
private val provider: DownloadProvider,
|
||||
private val cache: DownloadCache,
|
||||
private val sourceManager: SourceManager,
|
||||
private val provider: DownloadProvider = Injekt.get(),
|
||||
private val cache: DownloadCache = Injekt.get(),
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
) {
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
private val downloadPreferences: DownloadPreferences by injectLazy()
|
||||
|
|
|
@ -12,7 +12,9 @@ import eu.kanade.tachiyomi.BuildConfig
|
|||
import eu.kanade.tachiyomi.core.storage.AndroidStorageFolderProvider
|
||||
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.download.DownloadCache
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.download.DownloadProvider
|
||||
import eu.kanade.tachiyomi.data.library.CustomMangaManager
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||
|
@ -118,7 +120,9 @@ fun appModule(app: Application) = module {
|
|||
single { SourceManager(app, get()) }
|
||||
single { ExtensionManager(app) }
|
||||
|
||||
single { DownloadProvider(app) }
|
||||
single { DownloadManager(app) }
|
||||
single { DownloadCache(app) }
|
||||
|
||||
single { CustomMangaManager(app) }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue