Proper DI instantiation for some more download related classes

This commit is contained in:
arkon
2022-10-21 14:29:44 -04:00
parent 01e13e59e5
commit b04807e53a
10 changed files with 28 additions and 37 deletions

View File

@@ -21,15 +21,10 @@ import java.util.concurrent.TimeUnit
* directory checking is expensive and it slows down the app. The cache is invalidated by the time
* defined in [renewInterval] as we don't have any control over the filesystem and the user can
* delete the folders at any time without the app noticing.
*
* @param context the application context.
* @param provider the downloads directories provider.
* @param sourceManager the source manager.
* @param downloadPreferences the preferences of the app.
*/
class DownloadCache(
private val context: Context,
private val provider: DownloadProvider,
private val provider: DownloadProvider = Injekt.get(),
private val sourceManager: SourceManager = Injekt.get(),
private val downloadPreferences: DownloadPreferences = Injekt.get(),
) {

View File

@@ -25,26 +25,16 @@ import uy.kohesive.injekt.api.get
* This class is used to manage chapter downloads in the application. It must be instantiated once
* and retrieved through dependency injection. You can use this class to queue new chapters or query
* downloaded chapters.
*
* @param context the application context.
*/
class DownloadManager(
private val context: Context,
private val provider: DownloadProvider = Injekt.get(),
private val cache: DownloadCache = Injekt.get(),
private val getCategories: GetCategories = Injekt.get(),
private val sourceManager: SourceManager = Injekt.get(),
private val downloadPreferences: DownloadPreferences = Injekt.get(),
) {
/**
* Downloads provider, used to retrieve the folders where the chapters are or should be stored.
*/
val provider = DownloadProvider(context)
/**
* Cache of downloaded chapters.
*/
private val cache = DownloadCache(context, provider)
/**
* Downloader whose only task is to download chapters.
*/

View File

@@ -14,7 +14,8 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import logcat.LogPriority
import uy.kohesive.injekt.injectLazy
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import eu.kanade.domain.chapter.model.Chapter as DomainChapter
/**
@@ -23,9 +24,10 @@ import eu.kanade.domain.chapter.model.Chapter as DomainChapter
*
* @param context the application context.
*/
class DownloadProvider(private val context: Context) {
private val downloadPreferences: DownloadPreferences by injectLazy()
class DownloadProvider(
private val context: Context,
downloadPreferences: DownloadPreferences = Injekt.get(),
) {
private val scope = MainScope()