diff --git a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt index a7d4f3532..ef82b90d3 100644 --- a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt +++ b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt @@ -9,6 +9,7 @@ import eu.kanade.domain.chapter.repository.ChapterRepository import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.data.download.DownloadManager +import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.isLocal import eu.kanade.tachiyomi.source.model.SChapter @@ -22,6 +23,7 @@ import java.util.TreeSet class SyncChaptersWithSource( private val downloadManager: DownloadManager = Injekt.get(), + private val downloadProvider: DownloadProvider = Injekt.get(), private val chapterRepository: ChapterRepository = Injekt.get(), private val shouldUpdateDbChapter: ShouldUpdateDbChapter = Injekt.get(), private val updateManga: UpdateManga = Injekt.get(), @@ -105,13 +107,11 @@ class SyncChaptersWithSource( toAdd.add(toAddChapter) } else { if (shouldUpdateDbChapter.await(dbChapter, chapter)) { - downloadManager.run { - val shouldRenameChapter = provider.isChapterDirNameChanged(dbChapter, chapter) && - isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source) + val shouldRenameChapter = downloadProvider.isChapterDirNameChanged(dbChapter, chapter) && + downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source) - if (shouldRenameChapter) { - renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter()) - } + if (shouldRenameChapter) { + downloadManager.renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter()) } var toChangeChapter = dbChapter.copy( name = chapter.name, diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index c1a90ed95..f31d8343a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -28,7 +28,9 @@ import eu.kanade.tachiyomi.core.provider.AndroidDownloadFolderProvider import eu.kanade.tachiyomi.core.security.SecurityPreferences 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.saver.ImageSaver import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.job.DelayedTrackingStore @@ -116,7 +118,9 @@ class AppModule(val app: Application) : InjektModule { addSingletonFactory { SourceManager(app, get(), get()) } addSingletonFactory { ExtensionManager(app) } + addSingletonFactory { DownloadProvider(app) } addSingletonFactory { DownloadManager(app) } + addSingletonFactory { DownloadCache(app) } addSingletonFactory { TrackManager(app) } addSingletonFactory { DelayedTrackingStore(app) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index 8338c6486..34d549630 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt @@ -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(), ) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index f8379d728..7662fdea7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -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. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt index 1f97830de..be7300d50 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt @@ -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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt index 6521f1ed1..300e884dc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt @@ -17,9 +17,6 @@ import kotlinx.coroutines.launch import logcat.LogPriority import uy.kohesive.injekt.injectLazy -/** - * Presenter of [DownloadController]. - */ class DownloadPresenter : BasePresenter() { val downloadManager: DownloadManager by injectLazy() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index e73967ca8..63c30495e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -74,9 +74,6 @@ private data class Library(val categories: List, val mangaMap: Library */ typealias LibraryMap = Map> -/** - * Presenter of [LibraryController]. - */ class LibraryPresenter( private val state: LibraryStateImpl = LibraryState() as LibraryStateImpl, private val getLibraryManga: GetLibraryManga = Injekt.get(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 121504521..65df9c871 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -25,6 +25,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toDomainChapter import eu.kanade.tachiyomi.data.database.models.toDomainManga import eu.kanade.tachiyomi.data.download.DownloadManager +import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.saver.Image import eu.kanade.tachiyomi.data.saver.ImageSaver @@ -80,6 +81,7 @@ import eu.kanade.tachiyomi.data.database.models.Chapter as DbChapter class ReaderPresenter( private val sourceManager: SourceManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(), + private val downloadProvider: DownloadProvider = Injekt.get(), preferences: BasePreferences = Injekt.get(), private val downloadPreferences: DownloadPreferences = Injekt.get(), private val readerPreferences: ReaderPreferences = Injekt.get(), @@ -284,7 +286,7 @@ class ReaderPresenter( val context = Injekt.get() val source = sourceManager.getOrStub(manga.source) - loader = ChapterLoader(context, downloadManager, manga.toDomainManga()!!, source) + loader = ChapterLoader(context, downloadManager, downloadProvider, manga.toDomainManga()!!, source) Observable.just(manga).subscribeLatestCache(ReaderActivity::setManga) viewerChaptersRelay.subscribeLatestCache(ReaderActivity::setChapters) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ChapterLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ChapterLoader.kt index 0fafa2e97..7ccb0c1e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ChapterLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ChapterLoader.kt @@ -5,6 +5,7 @@ import com.github.junrar.exception.UnsupportedRarV5Exception import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.DownloadManager +import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager @@ -22,6 +23,7 @@ import rx.schedulers.Schedulers class ChapterLoader( private val context: Context, private val downloadManager: DownloadManager, + private val downloadProvider: DownloadProvider, private val manga: Manga, private val source: Source, ) { @@ -80,7 +82,7 @@ class ChapterLoader( val dbChapter = chapter.chapter val isDownloaded = downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source, skipCache = true) return when { - isDownloaded -> DownloadPageLoader(chapter, manga, source, downloadManager) + isDownloaded -> DownloadPageLoader(chapter, manga, source, downloadManager, downloadProvider) source is HttpSource -> HttpPageLoader(chapter, source) source is LocalSource -> source.getFormat(chapter.chapter).let { format -> when (format) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt index 7461c0c4c..ae852825e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt @@ -5,6 +5,7 @@ import android.net.Uri import com.hippo.unifile.UniFile import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.data.download.DownloadManager +import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter @@ -21,6 +22,7 @@ class DownloadPageLoader( private val manga: Manga, private val source: Source, private val downloadManager: DownloadManager, + private val downloadProvider: DownloadProvider, ) : PageLoader() { // Needed to open input streams @@ -31,7 +33,7 @@ class DownloadPageLoader( */ override fun getPages(): Observable> { val dbChapter = chapter.chapter - val chapterPath = downloadManager.provider.findChapterDir(dbChapter.name, dbChapter.scanlator, manga.title, source) + val chapterPath = downloadProvider.findChapterDir(dbChapter.name, dbChapter.scanlator, manga.title, source) return if (chapterPath?.isFile == true) { getPagesFromArchive(chapterPath) } else {