Remove dead code from DownloadQueue
This commit is contained in:
parent
e86103fdcc
commit
879fa484f6
1 changed files with 4 additions and 38 deletions
|
@ -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.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadStore
|
import eu.kanade.tachiyomi.data.download.DownloadStore
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import java.util.concurrent.CopyOnWriteArrayList
|
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.subjects.PublishSubject
|
import rx.subjects.PublishSubject
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList
|
||||||
|
|
||||||
class DownloadQueue(
|
class DownloadQueue(
|
||||||
private val store: DownloadStore,
|
private val store: DownloadStore,
|
||||||
private val queue: MutableList<Download> = CopyOnWriteArrayList<Download>()
|
private val queue: MutableList<Download> = CopyOnWriteArrayList()
|
||||||
) : List<Download> by queue {
|
) : List<Download> by queue {
|
||||||
|
|
||||||
private val statusSubject = PublishSubject.create<Download>()
|
private val statusSubject = PublishSubject.create<Download>()
|
||||||
|
|
||||||
private val updatedRelay = PublishRelay.create<Unit>()
|
private val updatedRelay = PublishRelay.create<Unit>()
|
||||||
|
|
||||||
private val downloadListeners = mutableListOf<DownloadListener>()
|
|
||||||
|
|
||||||
fun addAll(downloads: List<Download>) {
|
fun addAll(downloads: List<Download>) {
|
||||||
downloads.forEach { download ->
|
downloads.forEach { download ->
|
||||||
download.setStatusSubject(statusSubject)
|
download.setStatusSubject(statusSubject)
|
||||||
|
@ -39,7 +37,6 @@ class DownloadQueue(
|
||||||
if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) {
|
if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) {
|
||||||
download.status = Download.NOT_DOWNLOADED
|
download.status = Download.NOT_DOWNLOADED
|
||||||
}
|
}
|
||||||
callListeners(download)
|
|
||||||
if (removed) {
|
if (removed) {
|
||||||
updatedRelay.call(Unit)
|
updatedRelay.call(Unit)
|
||||||
}
|
}
|
||||||
|
@ -66,7 +63,6 @@ class DownloadQueue(
|
||||||
if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) {
|
if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) {
|
||||||
download.status = Download.NOT_DOWNLOADED
|
download.status = Download.NOT_DOWNLOADED
|
||||||
}
|
}
|
||||||
callListeners(download)
|
|
||||||
}
|
}
|
||||||
queue.clear()
|
queue.clear()
|
||||||
store.clear()
|
store.clear()
|
||||||
|
@ -83,21 +79,9 @@ class DownloadQueue(
|
||||||
.map { this }
|
.map { this }
|
||||||
|
|
||||||
private fun setPagesFor(download: Download) {
|
private fun setPagesFor(download: Download) {
|
||||||
if (download.status == Download.DOWNLOADING) {
|
if (download.status == Download.DOWNLOADED || download.status == Download.ERROR) {
|
||||||
download.pages?.forEach { page ->
|
|
||||||
page.setStatusCallback {
|
|
||||||
callListeners(download)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (download.status == Download.DOWNLOADED || download.status == Download.ERROR) {
|
|
||||||
setPagesSubject(download.pages, null)
|
setPagesSubject(download.pages, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
callListeners(download)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun callListeners(download: Download) {
|
|
||||||
downloadListeners.forEach { it.updateDownload(download) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getProgressObservable(): Observable<Download> {
|
fun getProgressObservable(): Observable<Download> {
|
||||||
|
@ -107,14 +91,12 @@ class DownloadQueue(
|
||||||
if (download.status == Download.DOWNLOADING) {
|
if (download.status == Download.DOWNLOADING) {
|
||||||
val pageStatusSubject = PublishSubject.create<Int>()
|
val pageStatusSubject = PublishSubject.create<Int>()
|
||||||
setPagesSubject(download.pages, pageStatusSubject)
|
setPagesSubject(download.pages, pageStatusSubject)
|
||||||
callListeners(download)
|
|
||||||
return@flatMap pageStatusSubject
|
return@flatMap pageStatusSubject
|
||||||
.onBackpressureBuffer()
|
.onBackpressureBuffer()
|
||||||
.filter { it == Page.READY }
|
.filter { it == Page.READY }
|
||||||
.map { download }
|
.map { download }
|
||||||
} else if (download.status == Download.DOWNLOADED || download.status == Download.ERROR) {
|
} else if (download.status == Download.DOWNLOADED || download.status == Download.ERROR) {
|
||||||
setPagesSubject(download.pages, null)
|
setPagesSubject(download.pages, null)
|
||||||
callListeners(download)
|
|
||||||
}
|
}
|
||||||
Observable.just(download)
|
Observable.just(download)
|
||||||
}
|
}
|
||||||
|
@ -122,22 +104,6 @@ class DownloadQueue(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setPagesSubject(pages: List<Page>?, subject: PublishSubject<Int>?) {
|
private fun setPagesSubject(pages: List<Page>?, subject: PublishSubject<Int>?) {
|
||||||
if (pages != null) {
|
pages?.forEach { it.setStatusSubject(subject) }
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue