diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/config/ReaderSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/config/ReaderSettings.kt index e9b4a6e81..083f3f3fb 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/config/ReaderSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/config/ReaderSettings.kt @@ -3,10 +3,12 @@ package org.koitharu.kotatsu.reader.ui.config import android.content.SharedPreferences import android.graphics.Bitmap import android.view.View +import androidx.annotation.CheckResult import androidx.lifecycle.MediatorLiveData import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder import com.davemorrissey.labs.subscaleview.decoder.SkiaImageRegionDecoder +import com.davemorrissey.labs.subscaleview.decoder.SkiaPooledImageRegionDecoder import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -16,6 +18,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.koitharu.kotatsu.core.model.ZoomMode import org.koitharu.kotatsu.core.prefs.AppSettings +import org.koitharu.kotatsu.core.util.ext.isLowRamDevice import org.koitharu.kotatsu.reader.domain.ReaderColorFilter class ReaderSettings( @@ -51,11 +54,19 @@ class ReaderSettings( view.background = bg.resolve(view.context) } - fun applyBitmapConfig(ssiv: SubsamplingScaleImageView) { + @CheckResult + fun applyBitmapConfig(ssiv: SubsamplingScaleImageView): Boolean { val config = bitmapConfig - if (ssiv.regionDecoderFactory.bitmapConfig != config) { - ssiv.regionDecoderFactory = SkiaImageRegionDecoder.Factory(config) + return if (ssiv.regionDecoderFactory.bitmapConfig != config) { + ssiv.regionDecoderFactory = if (ssiv.context.isLowRamDevice()) { + SkiaImageRegionDecoder.Factory(config) + } else { + SkiaPooledImageRegionDecoder.Factory(config) + } ssiv.bitmapDecoderFactory = SkiaImageDecoder.Factory(config) + true + } else { + false } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/PageHolderDelegate.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/PageHolderDelegate.kt index d874a12b1..9ac31c5f8 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/PageHolderDelegate.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/PageHolderDelegate.kt @@ -84,6 +84,14 @@ class PageHolderDelegate( job?.cancel() } + fun reload() { + if (state == State.SHOWN ) { + file?.let { + callback.onImageReady(it.toUri()) + } + } + } + override fun onReady() { state = State.SHOWING error = null diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/standard/PageHolder.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/standard/PageHolder.kt index 5fca3d011..6882bf874 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/standard/PageHolder.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/standard/PageHolder.kt @@ -46,7 +46,10 @@ open class PageHolder( override fun onConfigChanged() { super.onConfigChanged() binding.zoomControl.isVisible = settings.isZoomControlsEnabled - settings.applyBitmapConfig(binding.ssiv) + @Suppress("SENSELESS_COMPARISON") + if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) { + delegate.reload() + } } @SuppressLint("SetTextI18n") diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonHolder.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonHolder.kt index 6765ed66a..d2edc326a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonHolder.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonHolder.kt @@ -40,7 +40,10 @@ class WebtoonHolder( override fun onConfigChanged() { super.onConfigChanged() - settings.applyBitmapConfig(binding.ssiv) + @Suppress("SENSELESS_COMPARISON") + if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) { + delegate.reload() + } } override fun onBind(data: ReaderPage) {