Downsample offscreen pages option
This commit is contained in:
@@ -36,6 +36,9 @@ class ReaderSettings(
|
||||
val colorFilter: ReaderColorFilter?
|
||||
get() = colorFilterFlow.value?.takeUnless { it.isEmpty }
|
||||
|
||||
val isReaderOptimizationEnabled: Boolean
|
||||
get() = settings.isReaderOptimizationEnabled
|
||||
|
||||
val bitmapConfig: Bitmap.Config
|
||||
get() = if (settings.is32BitColorsEnabled) {
|
||||
Bitmap.Config.ARGB_8888
|
||||
@@ -104,7 +107,8 @@ class ReaderSettings(
|
||||
key == AppSettings.KEY_ZOOM_MODE ||
|
||||
key == AppSettings.KEY_PAGES_NUMBERS ||
|
||||
key == AppSettings.KEY_READER_BACKGROUND ||
|
||||
key == AppSettings.KEY_32BIT_COLOR
|
||||
key == AppSettings.KEY_32BIT_COLOR ||
|
||||
key == AppSettings.KEY_READER_OPTIMIZE
|
||||
) {
|
||||
notifyChanged()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.viewbinding.ViewBinding
|
||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
import org.koitharu.kotatsu.core.ui.list.lifecycle.LifecycleAwareViewHolder
|
||||
import org.koitharu.kotatsu.core.util.ext.isLowRamDevice
|
||||
import org.koitharu.kotatsu.databinding.LayoutPageInfoBinding
|
||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||
@@ -67,4 +68,10 @@ abstract class BasePageHolder<B : ViewBinding>(
|
||||
open fun onRecycled() {
|
||||
delegate.onRecycle()
|
||||
}
|
||||
|
||||
protected fun getBackgroundDownsampling() = when {
|
||||
!settings.isReaderOptimizationEnabled -> 1
|
||||
context.isLowRamDevice() -> 8
|
||||
else -> 4
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,9 @@ class PageHolderDelegate(
|
||||
private var error: Throwable? = null
|
||||
|
||||
init {
|
||||
callback.onConfigChanged()
|
||||
scope.launch(Dispatchers.Main) { // the same as post() -- wait until child fields init
|
||||
callback.onConfigChanged()
|
||||
}
|
||||
}
|
||||
|
||||
fun isLoading() = job?.isActive == true
|
||||
|
||||
@@ -45,12 +45,22 @@ open class PageHolder(
|
||||
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
binding.ssiv.downsampling = 1
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
binding.ssiv.downsampling = getBackgroundDownsampling()
|
||||
}
|
||||
|
||||
override fun onConfigChanged() {
|
||||
super.onConfigChanged()
|
||||
@Suppress("SENSELESS_COMPARISON")
|
||||
if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) {
|
||||
if (settings.applyBitmapConfig(binding.ssiv)) {
|
||||
delegate.reload()
|
||||
}
|
||||
binding.ssiv.downsampling = if (isResumed()) 1 else getBackgroundDownsampling()
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
||||
@@ -40,10 +40,20 @@ class WebtoonHolder(
|
||||
|
||||
override fun onConfigChanged() {
|
||||
super.onConfigChanged()
|
||||
@Suppress("SENSELESS_COMPARISON")
|
||||
if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) {
|
||||
if (settings.applyBitmapConfig(binding.ssiv)) {
|
||||
delegate.reload()
|
||||
}
|
||||
binding.ssiv.downsampling = if (isResumed()) 1 else getBackgroundDownsampling()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
binding.ssiv.downsampling = 1
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
binding.ssiv.downsampling = getBackgroundDownsampling()
|
||||
}
|
||||
|
||||
override fun onBind(data: ReaderPage) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.yield
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
import org.koitharu.kotatsu.core.ui.list.lifecycle.RecyclerViewLifecycleDispatcher
|
||||
import org.koitharu.kotatsu.core.util.ext.findCenterViewPosition
|
||||
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
|
||||
import org.koitharu.kotatsu.core.util.ext.observe
|
||||
@@ -44,6 +45,7 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
||||
setHasFixedSize(true)
|
||||
adapter = readerAdapter
|
||||
addOnPageScrollListener(PageScrollListener())
|
||||
addOnScrollListener(RecyclerViewLifecycleDispatcher())
|
||||
}
|
||||
viewModel.isWebtoonZooEnabled.observe(viewLifecycleOwner) {
|
||||
binding.frame.isZoomEnable = it
|
||||
|
||||
Reference in New Issue
Block a user