Add ability to tune reader threads and instant retry
This commit is contained in:
parent
4342584c32
commit
0f2be86d5a
@ -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"
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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,17 +46,18 @@ class ChapterLoader(
|
||||
private fun prepareOnlineReading() {
|
||||
if (source !is HttpSource) return
|
||||
|
||||
subscriptions += Observable.defer { Observable.just(queue.take().page) }
|
||||
.filter { it.status == Page.QUEUE }
|
||||
.concatMap { source.fetchImageFromCacheThenNet(it) }
|
||||
.repeat()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe({
|
||||
}, { error ->
|
||||
if (error !is InterruptedException) {
|
||||
Timber.e(error)
|
||||
}
|
||||
})
|
||||
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) }
|
||||
.repeat()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe({
|
||||
}, { error ->
|
||||
if (error !is InterruptedException) {
|
||||
Timber.e(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun loadChapter(chapter: ReaderChapter) = Observable.just(chapter)
|
||||
@ -117,7 +123,18 @@ class ChapterLoader(
|
||||
}
|
||||
|
||||
fun retryPage(page: Page) {
|
||||
queue.offer(PriorityPage(page, 2))
|
||||
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))
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user