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