Cleanup Page status (#8696)
* Cleanup Page statusSubject and statusCallback * Convert Page status from Int to enum (cherry picked from commit 6ca32710be5bfed851ab695a0d9438c7ab609b24) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt
This commit is contained in:
parent
9e8cd05c13
commit
5eca2bdf28
@ -182,7 +182,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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -414,13 +414,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
|
||||
}
|
||||
@ -435,7 +435,7 @@ class Downloader(
|
||||
* @param filename the filename of the image.
|
||||
*/
|
||||
private fun downloadImage(page: Page, source: HttpSource, tmpDir: UniFile, filename: String, dataSaver: DataSaver): Observable<UniFile> {
|
||||
page.status = Page.DOWNLOAD_IMAGE
|
||||
page.status = Page.State.DOWNLOAD_IMAGE
|
||||
page.progress = 0
|
||||
return source.fetchImage(page, dataSaver)
|
||||
.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 }
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ class LibraryScreenModel(
|
||||
combine(
|
||||
state.map { it.groupType }.distinctUntilChanged(),
|
||||
libraryPreferences.libraryDisplayMode().changes(),
|
||||
libraryPreferences.librarySortingMode().changes()
|
||||
libraryPreferences.librarySortingMode().changes(),
|
||||
) { a, b, c ->
|
||||
Triple(a, b, c)
|
||||
},
|
||||
@ -178,7 +178,7 @@ class LibraryScreenModel(
|
||||
// SY -->
|
||||
.applyGrouping(groupType, displayMode)
|
||||
// SY <--
|
||||
.applySort(/* SY --> */sort.takeIf { groupType != LibraryGroup.BY_DEFAULT }/* SY <-- */)
|
||||
.applySort(/* SY --> */sort.takeIf { groupType != LibraryGroup.BY_DEFAULT } /* SY <-- */)
|
||||
.mapValues { (_, value) ->
|
||||
if (searchQuery != null) {
|
||||
// Filter query
|
||||
@ -1175,7 +1175,7 @@ class LibraryScreenModel(
|
||||
private fun getGroupedMangaItems(
|
||||
groupType: Int,
|
||||
libraryManga: List<LibraryItem>,
|
||||
displayMode: LibraryDisplayMode
|
||||
displayMode: LibraryDisplayMode,
|
||||
): LibraryMap {
|
||||
val context = preferences.context
|
||||
return when (groupType) {
|
||||
|
@ -809,7 +809,7 @@ class ReaderActivity :
|
||||
.pages
|
||||
?.forEachIndexed { _, page ->
|
||||
var shouldQueuePage = false
|
||||
if (page.status == Page.ERROR) {
|
||||
if (page.status == Page.State.ERROR) {
|
||||
shouldQueuePage = true
|
||||
} /*else if (page.status == Page.LOAD_PAGE ||
|
||||
page.status == Page.DOWNLOAD_IMAGE) {
|
||||
@ -817,7 +817,7 @@ class ReaderActivity :
|
||||
}*/
|
||||
|
||||
if (shouldQueuePage) {
|
||||
page.status = Page.QUEUE
|
||||
page.status = Page.State.QUEUE
|
||||
} else {
|
||||
return@forEachIndexed
|
||||
}
|
||||
@ -858,11 +858,11 @@ class ReaderActivity :
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (curPage.status == Page.ERROR) {
|
||||
if (curPage.status == Page.State.ERROR) {
|
||||
toast(R.string.eh_boost_page_errored)
|
||||
} else if (curPage.status == Page.LOAD_PAGE || curPage.status == Page.DOWNLOAD_IMAGE) {
|
||||
} else if (curPage.status == Page.State.LOAD_PAGE || curPage.status == Page.State.DOWNLOAD_IMAGE) {
|
||||
toast(R.string.eh_boost_page_downloading)
|
||||
} else if (curPage.status == Page.READY) {
|
||||
} else if (curPage.status == Page.State.READY) {
|
||||
toast(R.string.eh_boost_page_downloaded)
|
||||
} else {
|
||||
val loader = (presenter.viewerChaptersRelay.value.currChapter.pageLoader as? HttpPageLoader)
|
||||
|
@ -55,7 +55,7 @@ class ReaderPageSheet(
|
||||
* Sets the image of this page as the cover of the manga.
|
||||
*/
|
||||
private fun setAsCover(page: ReaderPage) {
|
||||
if (page.status != Page.READY) return
|
||||
if (page.status != Page.State.READY) return
|
||||
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setMessage(R.string.confirm_set_image_as_cover)
|
||||
|
@ -848,7 +848,7 @@ class ReaderPresenter(
|
||||
* There's also a notification to allow sharing the image somewhere else or deleting it.
|
||||
*/
|
||||
fun saveImage(page: ReaderPage) {
|
||||
if (page.status != Page.READY) return
|
||||
if (page.status != Page.State.READY) return
|
||||
val manga = manga ?: return
|
||||
|
||||
val context = Injekt.get<Application>()
|
||||
@ -883,8 +883,8 @@ class ReaderPresenter(
|
||||
|
||||
// SY -->
|
||||
fun saveImages(firstPage: ReaderPage, secondPage: ReaderPage, isLTR: Boolean, @ColorInt bg: Int) {
|
||||
if (firstPage.status != Page.READY) return
|
||||
if (secondPage.status != Page.READY) return
|
||||
if (firstPage.status != Page.State.READY) return
|
||||
if (secondPage.status != Page.State.READY) return
|
||||
val manga = manga ?: return
|
||||
|
||||
val context = Injekt.get<Application>()
|
||||
@ -957,7 +957,7 @@ class ReaderPresenter(
|
||||
* image will be kept so it won't be taking lots of internal disk space.
|
||||
*/
|
||||
fun shareImage(page: ReaderPage) {
|
||||
if (page.status != Page.READY) return
|
||||
if (page.status != Page.State.READY) return
|
||||
val manga = manga ?: return
|
||||
|
||||
val context = Injekt.get<Application>()
|
||||
@ -986,8 +986,8 @@ class ReaderPresenter(
|
||||
|
||||
// SY -->
|
||||
fun shareImages(firstPage: ReaderPage, secondPage: ReaderPage, isLTR: Boolean, @ColorInt bg: Int) {
|
||||
if (firstPage.status != Page.READY) return
|
||||
if (secondPage.status != Page.READY) return
|
||||
if (firstPage.status != Page.State.READY) return
|
||||
if (secondPage.status != Page.State.READY) return
|
||||
val manga = manga ?: return
|
||||
|
||||
val context = Injekt.get<Application>()
|
||||
@ -1018,7 +1018,7 @@ class ReaderPresenter(
|
||||
* Sets the image of this [page] as cover and notifies the UI of the result.
|
||||
*/
|
||||
fun setAsCover(context: Context, page: ReaderPage) {
|
||||
if (page.status != Page.READY) return
|
||||
if (page.status != Page.State.READY) return
|
||||
val manga = manga?.toDomainManga() ?: return
|
||||
val stream = page.stream ?: return
|
||||
|
||||
|
@ -25,7 +25,7 @@ class DirectoryPageLoader(val file: File) : PageLoader() {
|
||||
val streamFn = { FileInputStream(file) }
|
||||
ReaderPage(i).apply {
|
||||
stream = streamFn
|
||||
status = Page.READY
|
||||
status = Page.State.READY
|
||||
}
|
||||
}
|
||||
.let { Observable.just(it) }
|
||||
@ -34,7 +34,7 @@ class DirectoryPageLoader(val file: File) : PageLoader() {
|
||||
/**
|
||||
* Returns an observable that emits a ready state.
|
||||
*/
|
||||
override fun getPage(page: ReaderPage): Observable<Int> {
|
||||
return Observable.just(Page.READY)
|
||||
override fun getPage(page: ReaderPage): Observable<Page.State> {
|
||||
return Observable.just(Page.State.READY)
|
||||
}
|
||||
}
|
||||
|
@ -54,13 +54,13 @@ class DownloadPageLoader(
|
||||
ReaderPage(page.index, page.url, page.imageUrl) {
|
||||
context.contentResolver.openInputStream(page.uri ?: Uri.EMPTY)!!
|
||||
}.apply {
|
||||
status = Page.READY
|
||||
status = Page.State.READY
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPage(page: ReaderPage): Observable<Int> {
|
||||
return Observable.just(Page.READY)
|
||||
override fun getPage(page: ReaderPage): Observable<Page.State> {
|
||||
return Observable.just(Page.State.READY)
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class EpubPageLoader(file: File) : PageLoader() {
|
||||
val streamFn = { epub.getInputStream(epub.getEntry(path)!!) }
|
||||
ReaderPage(i).apply {
|
||||
stream = streamFn
|
||||
status = Page.READY
|
||||
status = Page.State.READY
|
||||
}
|
||||
}
|
||||
.let { Observable.just(it) }
|
||||
@ -43,12 +43,12 @@ class EpubPageLoader(file: File) : PageLoader() {
|
||||
/**
|
||||
* Returns an observable that emits a ready state unless the loader was recycled.
|
||||
*/
|
||||
override fun getPage(page: ReaderPage): Observable<Int> {
|
||||
override fun getPage(page: ReaderPage): Observable<Page.State> {
|
||||
return Observable.just(
|
||||
if (isRecycled) {
|
||||
Page.ERROR
|
||||
Page.State.ERROR
|
||||
} else {
|
||||
Page.READY
|
||||
Page.State.READY
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class HttpPageLoader(
|
||||
repeat(readerPreferences.readerThreads().get()) {
|
||||
// EXH <--
|
||||
subscriptions += Observable.defer { Observable.just(queue.take().page) }
|
||||
.filter { it.status == Page.QUEUE }
|
||||
.filter { it.status == Page.State.QUEUE }
|
||||
.concatMap { source.fetchImageFromCacheThenNet(it) }
|
||||
.repeat()
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -116,7 +116,7 @@ class HttpPageLoader(
|
||||
}
|
||||
if (readerPreferences.aggressivePageLoading().get()) {
|
||||
rp.forEach {
|
||||
if (it.status == Page.QUEUE) {
|
||||
if (it.status == Page.State.QUEUE) {
|
||||
queue.offer(PriorityPage(it, 0))
|
||||
}
|
||||
}
|
||||
@ -130,25 +130,25 @@ class HttpPageLoader(
|
||||
* Returns an observable that loads a page through the queue and listens to its result to
|
||||
* emit new states. It handles re-enqueueing pages if they were evicted from the cache.
|
||||
*/
|
||||
override fun getPage(page: ReaderPage): Observable<Int> {
|
||||
override fun getPage(page: ReaderPage): Observable<Page.State> {
|
||||
return Observable.defer {
|
||||
val imageUrl = page.imageUrl
|
||||
|
||||
// Check if the image has been deleted
|
||||
if (page.status == Page.READY && imageUrl != null && !chapterCache.isImageInCache(imageUrl)) {
|
||||
page.status = Page.QUEUE
|
||||
if (page.status == Page.State.READY && imageUrl != null && !chapterCache.isImageInCache(imageUrl)) {
|
||||
page.status = Page.State.QUEUE
|
||||
}
|
||||
|
||||
// Automatically retry failed pages when subscribed to this page
|
||||
if (page.status == Page.ERROR) {
|
||||
page.status = Page.QUEUE
|
||||
if (page.status == Page.State.ERROR) {
|
||||
page.status = Page.State.QUEUE
|
||||
}
|
||||
|
||||
val statusSubject = SerializedSubject(PublishSubject.create<Int>())
|
||||
page.setStatusSubject(statusSubject)
|
||||
val statusSubject = SerializedSubject(PublishSubject.create<Page.State>())
|
||||
page.statusSubject = statusSubject
|
||||
|
||||
val queuedPages = mutableListOf<PriorityPage>()
|
||||
if (page.status == Page.QUEUE) {
|
||||
if (page.status == Page.State.QUEUE) {
|
||||
queuedPages += PriorityPage(page, 1).also { queue.offer(it) }
|
||||
}
|
||||
queuedPages += preloadNextPages(page, preloadSize)
|
||||
@ -156,7 +156,7 @@ class HttpPageLoader(
|
||||
statusSubject.startWith(page.status)
|
||||
.doOnUnsubscribe {
|
||||
queuedPages.forEach {
|
||||
if (it.page.status == Page.QUEUE) {
|
||||
if (it.page.status == Page.State.QUEUE) {
|
||||
queue.remove(it)
|
||||
}
|
||||
}
|
||||
@ -178,7 +178,7 @@ class HttpPageLoader(
|
||||
return pages
|
||||
.subList(pageIndex + 1, min(pageIndex + 1 + amount, pages.size))
|
||||
.mapNotNull {
|
||||
if (it.status == Page.QUEUE) {
|
||||
if (it.status == Page.State.QUEUE) {
|
||||
PriorityPage(it, 0).apply { queue.offer(this) }
|
||||
} else {
|
||||
null
|
||||
@ -190,8 +190,8 @@ class HttpPageLoader(
|
||||
* Retries a page. This method is only called from user interaction on the viewer.
|
||||
*/
|
||||
override fun retryPage(page: ReaderPage) {
|
||||
if (page.status == Page.ERROR) {
|
||||
page.status = Page.QUEUE
|
||||
if (page.status == Page.State.ERROR) {
|
||||
page.status = Page.State.QUEUE
|
||||
}
|
||||
// EXH -->
|
||||
// Grab a new image URL on EXH sources
|
||||
@ -241,9 +241,9 @@ class HttpPageLoader(
|
||||
}
|
||||
|
||||
private fun HttpSource.getImageUrl(page: ReaderPage): Observable<ReaderPage> {
|
||||
page.status = Page.LOAD_PAGE
|
||||
page.status = Page.State.LOAD_PAGE
|
||||
return fetchImageUrl(page)
|
||||
.doOnError { page.status = Page.ERROR }
|
||||
.doOnError { page.status = Page.State.ERROR }
|
||||
.onErrorReturn { null }
|
||||
.doOnNext { page.imageUrl = it }
|
||||
.map { page }
|
||||
@ -268,9 +268,9 @@ class HttpPageLoader(
|
||||
}
|
||||
.doOnNext {
|
||||
page.stream = { chapterCache.getImageFile(imageUrl).inputStream() }
|
||||
page.status = Page.READY
|
||||
page.status = Page.State.READY
|
||||
}
|
||||
.doOnError { page.status = Page.ERROR }
|
||||
.doOnError { page.status = Page.State.ERROR }
|
||||
.onErrorReturn { page }
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ class HttpPageLoader(
|
||||
* @param page the page.
|
||||
*/
|
||||
private fun HttpSource.cacheImage(page: ReaderPage): Observable<ReaderPage> {
|
||||
page.status = Page.DOWNLOAD_IMAGE
|
||||
page.status = Page.State.DOWNLOAD_IMAGE
|
||||
return fetchImage(page, dataSaver)
|
||||
.doOnNext {
|
||||
chapterCache.putImageToCache(page.imageUrl!!, it)
|
||||
@ -290,7 +290,7 @@ class HttpPageLoader(
|
||||
|
||||
// EXH -->
|
||||
fun boostPage(page: ReaderPage) {
|
||||
if (page.status == Page.QUEUE) {
|
||||
if (page.status == Page.State.QUEUE) {
|
||||
subscriptions += Observable.just(page)
|
||||
.concatMap { source.fetchImageFromCacheThenNet(it) }
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
@ -1,6 +1,7 @@
|
||||
package eu.kanade.tachiyomi.ui.reader.loader
|
||||
|
||||
import androidx.annotation.CallSuper
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import rx.Observable
|
||||
|
||||
@ -32,10 +33,9 @@ abstract class PageLoader {
|
||||
abstract fun getPages(): Observable<List<ReaderPage>>
|
||||
|
||||
/**
|
||||
* Returns an observable that should inform of the progress of the page (see the Page class
|
||||
* for the available states)
|
||||
* Returns an observable that should inform of the progress of the page
|
||||
*/
|
||||
abstract fun getPage(page: ReaderPage): Observable<Int>
|
||||
abstract fun getPage(page: ReaderPage): Observable<Page.State>
|
||||
|
||||
/**
|
||||
* Retries the given [page] in case it failed to load. This method only makes sense when an
|
||||
|
@ -48,7 +48,7 @@ class RarPageLoader(file: File) : PageLoader() {
|
||||
.mapIndexed { i, header ->
|
||||
ReaderPage(i).apply {
|
||||
stream = { getStream(header) }
|
||||
status = Page.READY
|
||||
status = Page.State.READY
|
||||
}
|
||||
}
|
||||
.let { Observable.just(it.toList()) }
|
||||
@ -57,12 +57,12 @@ class RarPageLoader(file: File) : PageLoader() {
|
||||
/**
|
||||
* Returns an observable that emits a ready state unless the loader was recycled.
|
||||
*/
|
||||
override fun getPage(page: ReaderPage): Observable<Int> {
|
||||
override fun getPage(page: ReaderPage): Observable<Page.State> {
|
||||
return Observable.just(
|
||||
if (isRecycled) {
|
||||
Page.ERROR
|
||||
Page.State.ERROR
|
||||
} else {
|
||||
Page.READY
|
||||
Page.State.READY
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class ZipPageLoader(file: File) : PageLoader() {
|
||||
.mapIndexed { i, entry ->
|
||||
ReaderPage(i).apply {
|
||||
stream = { zip.getInputStream(entry) }
|
||||
status = Page.READY
|
||||
status = Page.State.READY
|
||||
}
|
||||
}
|
||||
.let { Observable.just(it.toList()) }
|
||||
@ -52,12 +52,12 @@ class ZipPageLoader(file: File) : PageLoader() {
|
||||
/**
|
||||
* Returns an observable that emits a ready state unless the loader was recycled.
|
||||
*/
|
||||
override fun getPage(page: ReaderPage): Observable<Int> {
|
||||
override fun getPage(page: ReaderPage): Observable<Page.State> {
|
||||
return Observable.just(
|
||||
if (isRecycled) {
|
||||
Page.ERROR
|
||||
Page.State.ERROR
|
||||
} else {
|
||||
Page.READY
|
||||
Page.State.READY
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class StencilPage(
|
||||
override var chapter: ReaderChapter = parent.chapter
|
||||
|
||||
init {
|
||||
status = READY
|
||||
status = State.READY
|
||||
stream = stencilStream
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +89,8 @@ class PagerPageHolder(
|
||||
private var readImageHeaderSubscription: Subscription? = null
|
||||
|
||||
// SY -->
|
||||
var status: Int = 0
|
||||
var extraStatus: Int = 0
|
||||
var status: Page.State = Page.State.QUEUE
|
||||
var extraStatus: Page.State = Page.State.QUEUE
|
||||
var progress: Int = 0
|
||||
var extraProgress: Int = 0
|
||||
// SY <--
|
||||
@ -172,21 +172,21 @@ class PagerPageHolder(
|
||||
*
|
||||
* @param status the new status of the page.
|
||||
*/
|
||||
private fun processStatus(status: Int) {
|
||||
private fun processStatus(status: Page.State) {
|
||||
when (status) {
|
||||
Page.QUEUE -> setQueued()
|
||||
Page.LOAD_PAGE -> setLoading()
|
||||
Page.DOWNLOAD_IMAGE -> {
|
||||
Page.State.QUEUE -> setQueued()
|
||||
Page.State.LOAD_PAGE -> setLoading()
|
||||
Page.State.DOWNLOAD_IMAGE -> {
|
||||
observeProgress()
|
||||
setDownloading()
|
||||
}
|
||||
Page.READY -> {
|
||||
if (extraStatus == Page.READY || extraPage == null) {
|
||||
Page.State.READY -> {
|
||||
if (extraStatus == Page.State.READY || extraPage == null) {
|
||||
setImage()
|
||||
}
|
||||
unsubscribeProgress(1)
|
||||
}
|
||||
Page.ERROR -> {
|
||||
Page.State.ERROR -> {
|
||||
setError()
|
||||
unsubscribeProgress(1)
|
||||
}
|
||||
@ -198,21 +198,21 @@ class PagerPageHolder(
|
||||
*
|
||||
* @param status the new status of the page.
|
||||
*/
|
||||
private fun processStatus2(status: Int) {
|
||||
private fun processStatus2(status: Page.State) {
|
||||
when (status) {
|
||||
Page.QUEUE -> setQueued()
|
||||
Page.LOAD_PAGE -> setLoading()
|
||||
Page.DOWNLOAD_IMAGE -> {
|
||||
Page.State.QUEUE -> setQueued()
|
||||
Page.State.LOAD_PAGE -> setLoading()
|
||||
Page.State.DOWNLOAD_IMAGE -> {
|
||||
observeProgress2()
|
||||
setDownloading()
|
||||
}
|
||||
Page.READY -> {
|
||||
if (this.status == Page.READY) {
|
||||
Page.State.READY -> {
|
||||
if (this.status == Page.State.READY) {
|
||||
setImage()
|
||||
}
|
||||
unsubscribeProgress(2)
|
||||
}
|
||||
Page.ERROR -> {
|
||||
Page.State.ERROR -> {
|
||||
setError()
|
||||
unsubscribeProgress(2)
|
||||
}
|
||||
|
@ -165,19 +165,19 @@ class WebtoonPageHolder(
|
||||
*
|
||||
* @param status the new status of the page.
|
||||
*/
|
||||
private fun processStatus(status: Int) {
|
||||
private fun processStatus(status: Page.State) {
|
||||
when (status) {
|
||||
Page.QUEUE -> setQueued()
|
||||
Page.LOAD_PAGE -> setLoading()
|
||||
Page.DOWNLOAD_IMAGE -> {
|
||||
Page.State.QUEUE -> setQueued()
|
||||
Page.State.LOAD_PAGE -> setLoading()
|
||||
Page.State.DOWNLOAD_IMAGE -> {
|
||||
observeProgress()
|
||||
setDownloading()
|
||||
}
|
||||
Page.READY -> {
|
||||
Page.State.READY -> {
|
||||
setImage()
|
||||
unsubscribeProgress()
|
||||
}
|
||||
Page.ERROR -> {
|
||||
Page.State.ERROR -> {
|
||||
setError()
|
||||
unsubscribeProgress()
|
||||
}
|
||||
|
@ -20,26 +20,18 @@ open class Page(
|
||||
|
||||
@Transient
|
||||
@Volatile
|
||||
var status: Int = 0
|
||||
var status: State = State.QUEUE
|
||||
set(value) {
|
||||
field = value
|
||||
statusSubject?.onNext(value)
|
||||
statusCallback?.invoke(this)
|
||||
}
|
||||
|
||||
@Transient
|
||||
@Volatile
|
||||
var progress: Int = 0
|
||||
set(value) {
|
||||
field = value
|
||||
statusCallback?.invoke(this)
|
||||
}
|
||||
|
||||
@Transient
|
||||
private var statusSubject: Subject<Int, Int>? = null
|
||||
|
||||
@Transient
|
||||
private var statusCallback: ((Page) -> Unit)? = null
|
||||
var statusSubject: Subject<State, State>? = null
|
||||
|
||||
override fun update(bytesRead: Long, contentLength: Long, done: Boolean) {
|
||||
progress = if (contentLength > 0) {
|
||||
@ -49,19 +41,11 @@ open class Page(
|
||||
}
|
||||
}
|
||||
|
||||
fun setStatusSubject(subject: Subject<Int, Int>?) {
|
||||
this.statusSubject = subject
|
||||
}
|
||||
|
||||
fun setStatusCallback(f: ((Page) -> Unit)?) {
|
||||
statusCallback = f
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val QUEUE = 0
|
||||
const val LOAD_PAGE = 1
|
||||
const val DOWNLOAD_IMAGE = 2
|
||||
const val READY = 3
|
||||
const val ERROR = 4
|
||||
enum class State {
|
||||
QUEUE,
|
||||
LOAD_PAGE,
|
||||
DOWNLOAD_IMAGE,
|
||||
READY,
|
||||
ERROR,
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import eu.kanade.tachiyomi.source.model.Page
|
||||
import rx.Observable
|
||||
|
||||
fun HttpSource.getImageUrl(page: Page): Observable<Page> {
|
||||
page.status = Page.LOAD_PAGE
|
||||
page.status = Page.State.LOAD_PAGE
|
||||
return fetchImageUrl(page)
|
||||
.doOnError { page.status = Page.ERROR }
|
||||
.doOnError { page.status = Page.State.ERROR }
|
||||
.onErrorReturn { null }
|
||||
.doOnNext { page.imageUrl = it }
|
||||
.map { page }
|
||||
|
Loading…
x
Reference in New Issue
Block a user