Cleanup Page status (#8696)

* Cleanup Page statusSubject and statusCallback

* Convert Page status from Int to enum
This commit is contained in:
Two-Ai
2022-12-07 18:28:38 -05:00
committed by GitHub
parent f05e251991
commit 6ca32710be
17 changed files with 74 additions and 90 deletions

View File

@@ -179,7 +179,7 @@ class DownloadManager(
files.sortedBy { it.name }
.mapIndexed { i, file ->
Page(i, uri = file.uri).apply { status = Page.READY }
Page(i, uri = file.uri).apply { status = Page.State.READY }
}
}
}

View File

@@ -402,13 +402,13 @@ class Downloader(
page.uri = file.uri
page.progress = 100
download.downloadedImages++
page.status = Page.READY
page.status = Page.State.READY
}
.map { page }
// Mark this page as error and allow to download the remaining
.onErrorReturn {
page.progress = 0
page.status = Page.ERROR
page.status = Page.State.ERROR
notifier.onError(it.message, download.chapter.name, download.manga.title)
page
}
@@ -423,7 +423,7 @@ class Downloader(
* @param filename the filename of the image.
*/
private fun downloadImage(page: Page, source: HttpSource, tmpDir: UniFile, filename: String): Observable<UniFile> {
page.status = Page.DOWNLOAD_IMAGE
page.status = Page.State.DOWNLOAD_IMAGE
page.progress = 0
return source.fetchImage(page)
.map { response ->

View File

@@ -100,11 +100,11 @@ class DownloadQueue(
.startWith(getActiveDownloads())
.flatMap { download ->
if (download.status == Download.State.DOWNLOADING) {
val pageStatusSubject = PublishSubject.create<Int>()
val pageStatusSubject = PublishSubject.create<Page.State>()
setPagesSubject(download.pages, pageStatusSubject)
return@flatMap pageStatusSubject
.onBackpressureBuffer()
.filter { it == Page.READY }
.filter { it == Page.State.READY }
.map { download }
} else if (download.status == Download.State.DOWNLOADED || download.status == Download.State.ERROR) {
setPagesSubject(download.pages, null)
@@ -120,7 +120,7 @@ class DownloadQueue(
}
}
private fun setPagesSubject(pages: List<Page>?, subject: PublishSubject<Int>?) {
pages?.forEach { it.setStatusSubject(subject) }
private fun setPagesSubject(pages: List<Page>?, subject: PublishSubject<Page.State>?) {
pages?.forEach { it.statusSubject = subject }
}
}