mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 09:31:47 +01:00
Webtoon Split: Improve performance (#7947)
This commit is contained in:
parent
6b2b21edfa
commit
d55c854ebf
@ -1,15 +1,16 @@
|
||||
package eu.kanade.tachiyomi.ui.reader.model
|
||||
|
||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||
import java.io.InputStream
|
||||
|
||||
class StencilPage(
|
||||
parent: ReaderPage,
|
||||
val splitData: ImageUtil.SplitData,
|
||||
stencilStream: () -> InputStream,
|
||||
) : ReaderPage(parent.index, parent.url, parent.imageUrl) {
|
||||
|
||||
override var chapter: ReaderChapter = parent.chapter
|
||||
|
||||
init {
|
||||
stream = parent.stream
|
||||
status = READY
|
||||
stream = stencilStream
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV
|
||||
var currentChapter: ReaderChapter? = null
|
||||
|
||||
fun onLongStripSplit(currentStrip: Any?, newStrips: List<StencilPage>) {
|
||||
if (newStrips.isEmpty()) return
|
||||
if (currentStrip is StencilPage) return
|
||||
|
||||
val placeAtIndex = items.indexOf(currentStrip) + 1
|
||||
|
@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
|
||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||
import eu.kanade.tachiyomi.util.system.ImageUtil.SplitData
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
@ -286,27 +285,31 @@ class WebtoonPageHolder(
|
||||
|
||||
if (viewer.config.longStripSplit) {
|
||||
if (page is StencilPage) {
|
||||
val splitData = (page as StencilPage).splitData
|
||||
return ImageUtil.splitStrip(imageStream, splitData)
|
||||
return imageStream
|
||||
}
|
||||
|
||||
val isStripSplitNeeded = ImageUtil.isStripSplitNeeded(imageStream)
|
||||
if (isStripSplitNeeded) {
|
||||
val splitData = onStripSplit(imageStream)
|
||||
splitData?.let { return ImageUtil.splitStrip(imageStream, it) }
|
||||
onStripSplit(imageStream)?.let { return it }
|
||||
}
|
||||
}
|
||||
|
||||
return imageStream
|
||||
}
|
||||
|
||||
private fun onStripSplit(imageStream: BufferedInputStream): SplitData? {
|
||||
private fun onStripSplit(imageStream: BufferedInputStream): InputStream? {
|
||||
val page = page ?: return null
|
||||
val splitData = ImageUtil.getSplitDataForStream(imageStream).toMutableList()
|
||||
val toReturn = splitData.removeFirstOrNull()
|
||||
val newPages = splitData.map { StencilPage(page, it) }
|
||||
viewer.onLongStripSplit(page, newPages)
|
||||
return toReturn
|
||||
val streamFn = page.stream ?: return null
|
||||
val splitData = ImageUtil.getSplitDataForStream(imageStream)
|
||||
if (splitData.size == 1) return imageStream
|
||||
val newPages = splitData.map {
|
||||
StencilPage(page) { ImageUtil.splitStrip(it, streamFn) }
|
||||
}.toMutableList()
|
||||
return newPages.removeFirst().stream?.invoke()
|
||||
.also {
|
||||
// Doing this first and then returning InputStream
|
||||
// results in various issues with splitting
|
||||
viewer.onLongStripSplit(page, newPages)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,8 +268,8 @@ object ImageUtil {
|
||||
/**
|
||||
* Split the imageStream according to the provided splitData
|
||||
*/
|
||||
fun splitStrip(imageStream: InputStream, splitData: SplitData): InputStream {
|
||||
val bitmapRegionDecoder = getBitmapRegionDecoder(imageStream)
|
||||
fun splitStrip(splitData: SplitData, streamFn: () -> InputStream): InputStream {
|
||||
val bitmapRegionDecoder = getBitmapRegionDecoder(streamFn())
|
||||
?: throw Exception("Failed to create new instance of BitmapRegionDecoder")
|
||||
|
||||
logcat {
|
||||
|
Loading…
Reference in New Issue
Block a user