Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
Add retry all and boost page
Browse files Browse the repository at this point in the history
  • Loading branch information
NerdNumber9 committed Jun 10, 2018
1 parent c1abec3 commit a96c25c
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 7 deletions.
21 changes: 17 additions & 4 deletions app/src/main/java/eu/kanade/tachiyomi/ui/reader/ChapterLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,27 @@ class ChapterLoader(
}
}

fun loadPage(page: Page) {
queue.offer(PriorityPage(page, 0))
}

fun loadPriorizedPage(page: Page) {
queue.offer(PriorityPage(page, 1))
}

fun retryPage(page: Page) {
if(source is HttpSource && prefs.eh_readerInstantRetry().getOrDefault())
// --> EH
if(prefs.eh_readerInstantRetry().getOrDefault())
boostPage(page)
else
// <-- EH
queue.offer(PriorityPage(page, 2))
}


// --> EH
fun boostPage(page: Page) {
if(source is HttpSource && page.status == Page.QUEUE)
subscriptions += Observable.just(page)
.concatMap { source.fetchImageFromCacheThenNet(it) }
.subscribeOn(Schedulers.io())
Expand All @@ -133,10 +148,8 @@ class ChapterLoader(
Timber.e(error)
}
})
else
queue.offer(PriorityPage(page, 2))
}

// <-- EH


private data class PriorityPage(val page: Page, val priority: Int): Comparable<PriorityPage> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.all.EHentai
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
import eu.kanade.tachiyomi.ui.reader.viewer.base.BaseReader
import eu.kanade.tachiyomi.ui.reader.viewer.pager.horizontal.LeftToRightReader
Expand Down Expand Up @@ -201,6 +202,63 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
.positiveText("Ok")
.show()
}

subscriptions += eh_retry_all.clicks().subscribe {
viewer?.pages?.forEachIndexed { index, page ->
if(page.status == Page.ERROR)
page.status = Page.QUEUE
else
return@forEachIndexed

//If we are using EHentai/ExHentai, get a new image URL
if(presenter.source is EHentai)
page.imageUrl = null

if(viewer?.currentPage == index)
presenter.loader.loadPriorizedPage(page)
else
presenter.loader.loadPage(page)
}

toast("Retrying all failed pages...")
}

subscriptions += eh_retry_all_help.clicks().subscribe {
MaterialDialog.Builder(this)
.title("Retry all help")
.content("Re-add all failed pages to the download queue.")
.positiveText("Ok")
.show()
}

subscriptions += eh_boost_page.clicks().subscribe {
viewer?.let { viewer ->
val curPage = viewer.pages.getOrNull(viewer.currentPage)
?: run {
toast("Cannot find current page!")
return@let
}

if(curPage.status == Page.ERROR) {
toast("Page failed to load, press the retry button instead!")
} else if(curPage.status == Page.LOAD_PAGE || curPage.status == Page.DOWNLOAD_IMAGE) {
toast("This page is already downloading!")
} else if(curPage.status == Page.READY) {
toast("This page has already been downloaded!")
} else {
presenter.loader.boostPage(curPage)
toast("Boosted current page!")
}
}
}

subscriptions += eh_boost_page_help.clicks().subscribe {
MaterialDialog.Builder(this)
.title("Boost page help")
.content("Normally the downloader can only download a specific amount of pages at the same time. This means you can be waiting for a page to download but the downloader will not start downloading the page until it has a free download slot. Pressing 'Boost page' will force the downloader to begin downloading the current page, regardless of whether or not there is an available slot.")
.positiveText("Ok")
.show()
}
// <-- EH
}

Expand Down Expand Up @@ -630,7 +688,10 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
header.startAnimation(toolbarAnimation)

val bottomMenuAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_bottom)
// --> EH
// toolbar.startAnimation(bottomMenuAnimation)
reader_menu_bottom.startAnimation(bottomMenuAnimation)
// <-- EH
}
} else {
systemUi?.hide()
Expand All @@ -645,7 +706,10 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
header.startAnimation(toolbarAnimation)

val bottomMenuAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_bottom)
// --> EH
// toolbar.startAnimation(bottomMenuAnimation)
reader_menu_bottom.startAnimation(bottomMenuAnimation)
// <-- EH
}
}
}
Expand Down Expand Up @@ -691,7 +755,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {

// --> EH
private fun setupAutoscroll(interval: Float) {
autoscrollSubscription?.unsubscribe()
subscriptions.remove(autoscrollSubscription)
autoscrollSubscription = null

if(interval == -1f) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ReaderPresenter(
/**
* Source of the manga.
*/
private val source by lazy { sourceManager.get(manga.source)!! }
/* private */ val source by lazy { sourceManager.get(manga.source)!! }

/**
* Chapter list for the active manga. It's retrieved lazily and should be accessed for the first
Expand Down Expand Up @@ -106,7 +106,7 @@ class ReaderPresenter(
/**
* Chapter loader whose job is to obtain the chapter list and initialize every page.
*/
private val loader by lazy { ChapterLoader(downloadManager, manga, source) }
/* private */ val loader by lazy { ChapterLoader(downloadManager, manga, source) }

/**
* Subscription for appending a chapter to the reader (seamless mode).
Expand Down Expand Up @@ -334,9 +334,11 @@ class ReaderPresenter(
chapterCache.removeFileFromCache(key)
}

// --> EH
//If we are using EHentai/ExHentai, get a new image URL
if(source is EHentai)
page.imageUrl = null
// <-- EH

loader.retryPage(page)
}
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/res/layout/reader_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,44 @@
android:text="\?" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<Button
android:id="@+id/eh_retry_all"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Retry all" />

<Button
android:id="@+id/eh_retry_all_help"
style="?android:attr/borderlessButtonStyle"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="\?" />

<Button
android:id="@+id/eh_boost_page"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Boost page" />

<Button
android:id="@+id/eh_boost_page_help"
style="?android:attr/borderlessButtonStyle"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="\?" />
</LinearLayout>

</LinearLayout>

<ImageButton
Expand Down

0 comments on commit a96c25c

Please sign in to comment.