Add ability to tune reader threads and instant retry

This commit is contained in:
NerdNumber9 2018-06-09 23:12:53 -04:00
parent 4342584c32
commit 0f2be86d5a
5 changed files with 53 additions and 12 deletions

View File

@ -166,4 +166,8 @@ object PreferenceKeys {
const val eh_hl_lastRealmIndex = "eh_hl_lastRealmIndex"
const val eh_expandFilters = "eh_expand_filters"
const val eh_readerThreads = "eh_reader_threads"
const val eh_readerInstantRetry = "eh_reader_instant_retry"
}

View File

@ -238,4 +238,8 @@ class PreferencesHelper(val context: Context) {
// <-- EH
fun eh_expandFilters() = rxPrefs.getBoolean(Keys.eh_expandFilters, false)
fun eh_readerThreads() = rxPrefs.getInteger(Keys.eh_readerThreads, 2)
fun eh_readerInstantRetry() = rxPrefs.getBoolean(Keys.eh_readerInstantRetry, true)
}

View File

@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.ui.reader
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource
@ -12,6 +14,7 @@ import rx.Observable
import rx.schedulers.Schedulers
import rx.subscriptions.CompositeSubscription
import timber.log.Timber
import uy.kohesive.injekt.injectLazy
import java.util.concurrent.PriorityBlockingQueue
import java.util.concurrent.atomic.AtomicInteger
@ -21,6 +24,8 @@ class ChapterLoader(
private val source: Source
) {
private val prefs by injectLazy<PreferencesHelper>()
private val queue = PriorityBlockingQueue<PriorityPage>()
private val subscriptions = CompositeSubscription()
@ -41,6 +46,7 @@ class ChapterLoader(
private fun prepareOnlineReading() {
if (source !is HttpSource) return
for(i in 1 .. prefs.eh_readerThreads().getOrDefault())
subscriptions += Observable.defer { Observable.just(queue.take().page) }
.filter { it.status == Page.QUEUE }
.concatMap { source.fetchImageFromCacheThenNet(it) }
@ -117,6 +123,17 @@ class ChapterLoader(
}
fun retryPage(page: Page) {
if(source is HttpSource && prefs.eh_readerInstantRetry().getOrDefault())
subscriptions += Observable.just(page)
.concatMap { source.fetchImageFromCacheThenNet(it) }
.subscribeOn(Schedulers.io())
.subscribe({
}, { error ->
if (error !is InterruptedException) {
Timber.e(error)
}
})
else
queue.offer(PriorityPage(page, 2))
}

View File

@ -1,6 +1,8 @@
package eu.kanade.tachiyomi.ui.setting
import android.app.Dialog
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.preference.PreferenceScreen
import android.view.View

View File

@ -85,6 +85,20 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pref_show_page_number
defaultValue = true
}
intListPreference {
key = Keys.eh_readerThreads
title = "Download threads"
entries = arrayOf("1", "2", "3", "4", "5")
entryValues = entries
defaultValue = "2"
summary = "Higher values can speed up image downloading significantly, but can also trigger bans. Recommended value is 2 or 3. Current value is: %s"
}
switchPreference {
key = Keys.eh_readerInstantRetry
title = "Skip queue on retry"
summary = "Normally, pressing the retry button on a failed download will wait until the downloader has finished downloading the last page before beginning to re-download the failed page. Enabling this will force the downloader to begin re-downloading the failed page as soon as you press the retry button."
defaultValue = true
}
preferenceCategory {
titleRes = R.string.pager_viewer