Albirew/tachiyomi
Archivé
1
0
Bifurcation 0

Proper DI instantiation for some more download related classes

Cette révision appartient à :
arkon 2022-10-21 14:29:44 -04:00
Parent 01e13e59e5
révision b04807e53a
10 fichiers modifiés avec 28 ajouts et 37 suppressions

Voir le fichier

@ -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,

Voir le fichier

@ -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) }

Voir le fichier

@ -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(),
) {

Voir le fichier

@ -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.
*/

Voir le fichier

@ -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()

Voir le fichier

@ -17,9 +17,6 @@ import kotlinx.coroutines.launch
import logcat.LogPriority
import uy.kohesive.injekt.injectLazy
/**
* Presenter of [DownloadController].
*/
class DownloadPresenter : BasePresenter<DownloadController>() {
val downloadManager: DownloadManager by injectLazy()

Voir le fichier

@ -74,9 +74,6 @@ private data class Library(val categories: List<Category>, val mangaMap: Library
*/
typealias LibraryMap = Map<Long, List<LibraryItem>>
/**
* Presenter of [LibraryController].
*/
class LibraryPresenter(
private val state: LibraryStateImpl = LibraryState() as LibraryStateImpl,
private val getLibraryManga: GetLibraryManga = Injekt.get(),

Voir le fichier

@ -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<Application>()
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)

Voir le fichier

@ -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) {

Voir le fichier

@ -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<List<ReaderPage>> {
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 {