From 879fa484f62cde489b5ce7fff8be578efeee729b Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 29 Mar 2020 12:44:17 -0400 Subject: [PATCH] Remove dead code from DownloadQueue --- .../data/download/model/DownloadQueue.kt | 42 ++----------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt index 4d9773d22e..6f376bd286 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/model/DownloadQueue.kt @@ -5,21 +5,19 @@ import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.DownloadStore import eu.kanade.tachiyomi.source.model.Page -import java.util.concurrent.CopyOnWriteArrayList import rx.Observable import rx.subjects.PublishSubject +import java.util.concurrent.CopyOnWriteArrayList class DownloadQueue( private val store: DownloadStore, - private val queue: MutableList = CopyOnWriteArrayList() + private val queue: MutableList = CopyOnWriteArrayList() ) : List by queue { private val statusSubject = PublishSubject.create() private val updatedRelay = PublishRelay.create() - private val downloadListeners = mutableListOf() - fun addAll(downloads: List) { downloads.forEach { download -> download.setStatusSubject(statusSubject) @@ -39,7 +37,6 @@ class DownloadQueue( if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) { download.status = Download.NOT_DOWNLOADED } - callListeners(download) if (removed) { updatedRelay.call(Unit) } @@ -66,7 +63,6 @@ class DownloadQueue( if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) { download.status = Download.NOT_DOWNLOADED } - callListeners(download) } queue.clear() store.clear() @@ -83,21 +79,9 @@ class DownloadQueue( .map { this } private fun setPagesFor(download: Download) { - if (download.status == Download.DOWNLOADING) { - download.pages?.forEach { page -> - page.setStatusCallback { - callListeners(download) - } - } - } else if (download.status == Download.DOWNLOADED || download.status == Download.ERROR) { + if (download.status == Download.DOWNLOADED || download.status == Download.ERROR) { setPagesSubject(download.pages, null) } - - callListeners(download) - } - - private fun callListeners(download: Download) { - downloadListeners.forEach { it.updateDownload(download) } } fun getProgressObservable(): Observable { @@ -107,14 +91,12 @@ class DownloadQueue( if (download.status == Download.DOWNLOADING) { val pageStatusSubject = PublishSubject.create() setPagesSubject(download.pages, pageStatusSubject) - callListeners(download) return@flatMap pageStatusSubject .onBackpressureBuffer() .filter { it == Page.READY } .map { download } } else if (download.status == Download.DOWNLOADED || download.status == Download.ERROR) { setPagesSubject(download.pages, null) - callListeners(download) } Observable.just(download) } @@ -122,22 +104,6 @@ class DownloadQueue( } private fun setPagesSubject(pages: List?, subject: PublishSubject?) { - if (pages != null) { - for (page in pages) { - page.setStatusSubject(subject) - } - } - } - - fun addListener(listener: DownloadListener) { - downloadListeners.add(listener) - } - - fun removeListener(listener: DownloadListener) { - downloadListeners.remove(listener) - } - - interface DownloadListener { - fun updateDownload(download: Download) + pages?.forEach { it.setStatusSubject(subject) } } }