Moved logic to first load of page stream
This commit is contained in:
parent
afde195534
commit
dc4555f032
@ -1,11 +1,17 @@
|
||||
package eu.kanade.tachiyomi.ui.reader.loader
|
||||
|
||||
import android.graphics.BitmapFactory
|
||||
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||
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.HttpSource
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerConfig
|
||||
import eu.kanade.tachiyomi.util.ImageUtil
|
||||
import eu.kanade.tachiyomi.util.plusAssign
|
||||
import kotlinx.coroutines.experimental.async
|
||||
import rx.Completable
|
||||
import rx.Observable
|
||||
import rx.schedulers.Schedulers
|
||||
@ -15,6 +21,7 @@ import rx.subscriptions.CompositeSubscription
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.concurrent.PriorityBlockingQueue
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
@ -37,6 +44,11 @@ class HttpPageLoader(
|
||||
*/
|
||||
private val subscriptions = CompositeSubscription()
|
||||
|
||||
/**
|
||||
* Preferences helper.
|
||||
*/
|
||||
private val preferences by injectLazy<PreferencesHelper>()
|
||||
|
||||
init {
|
||||
subscriptions += Observable.defer { Observable.just(queue.take().page) }
|
||||
.filter { it.status == Page.QUEUE }
|
||||
@ -206,6 +218,10 @@ class HttpPageLoader(
|
||||
}
|
||||
.doOnNext {
|
||||
page.stream = { chapterCache.getImageFile(imageUrl).inputStream() }
|
||||
if (preferences.readerTheme().get() == 2) {
|
||||
val image = BitmapFactory.decodeStream(chapterCache.getImageFile(imageUrl).inputStream())
|
||||
page.bg = ImageUtil.autoSetBackground(image)
|
||||
}
|
||||
page.status = Page.READY
|
||||
}
|
||||
.doOnError { page.status = Page.ERROR }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.reader.model
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import java.io.InputStream
|
||||
|
||||
@ -7,7 +8,8 @@ class ReaderPage(
|
||||
index: Int,
|
||||
url: String = "",
|
||||
imageUrl: String? = null,
|
||||
var stream: (() -> InputStream)? = null
|
||||
var stream: (() -> InputStream)? = null,
|
||||
var bg: Drawable? = null
|
||||
) : Page(index, url, imageUrl, null) {
|
||||
|
||||
lateinit var chapter: ReaderChapter
|
||||
|
@ -244,16 +244,23 @@ class PagerPageHolder(
|
||||
.doOnNext { isAnimated ->
|
||||
if (!isAnimated) {
|
||||
if (viewer.config.readerTheme == 2) {
|
||||
val bytesArray = openStream!!.readBytes()
|
||||
|
||||
val imageView = initSubsamplingImageView()
|
||||
val bytesStream = bytesArray.inputStream()
|
||||
imageView.setImage(ImageSource.inputStream(bytesStream))
|
||||
bytesStream.close()
|
||||
if (page.bg != null) {
|
||||
imageView.setImage(ImageSource.inputStream(openStream!!))
|
||||
imageView.background = page.bg
|
||||
}
|
||||
// if the user switches to automatic when pages are already cached, the bg needs to be loaded
|
||||
else {
|
||||
val bytesArray = openStream!!.readBytes()
|
||||
val bytesStream = bytesArray.inputStream()
|
||||
imageView.setImage(ImageSource.inputStream(bytesStream))
|
||||
bytesStream.close()
|
||||
|
||||
launchUI {
|
||||
val image = async { BitmapFactory.decodeByteArray(bytesArray, 0, bytesArray.size) }
|
||||
imageView.background = ImageUtil.autoSetBackground(image.await())
|
||||
launchUI {
|
||||
val image = async { BitmapFactory.decodeByteArray(bytesArray, 0, bytesArray.size) }
|
||||
imageView.background = ImageUtil.autoSetBackground(image.await())
|
||||
page.bg = imageView.background
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -98,7 +98,7 @@ object ImageUtil {
|
||||
|
||||
var overallWhitePixels = 0
|
||||
var overallBlackPixels = 0
|
||||
outer@ for (x in intArrayOf(left, left - offsetX, right, right + offsetX)) {
|
||||
outer@ for (x in intArrayOf(left, right, left - offsetX, right + offsetX)) {
|
||||
var whitePixelsStreak = 0
|
||||
var whitePixels = 0
|
||||
var blackPixelsStreak = 0
|
||||
|
Loading…
Reference in New Issue
Block a user