mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 05:27:28 +01:00
Cleanup Page status (#8696)
* Cleanup Page statusSubject and statusCallback * Convert Page status from Int to enum
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user