|
|
|
|
@ -1,8 +1,14 @@
|
|
|
|
|
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
|
|
|
|
|
@ -12,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(
|
|
|
|
|
@ -29,6 +36,13 @@ class ReaderSettings(
|
|
|
|
|
val colorFilter: ReaderColorFilter?
|
|
|
|
|
get() = colorFilterFlow.value?.takeUnless { it.isEmpty }
|
|
|
|
|
|
|
|
|
|
val bitmapConfig: Bitmap.Config
|
|
|
|
|
get() = if (settings.is32BitColorsEnabled) {
|
|
|
|
|
Bitmap.Config.ARGB_8888
|
|
|
|
|
} else {
|
|
|
|
|
Bitmap.Config.RGB_565
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val isPagesNumbersEnabled: Boolean
|
|
|
|
|
get() = settings.isPagesNumbersEnabled
|
|
|
|
|
|
|
|
|
|
@ -40,6 +54,22 @@ class ReaderSettings(
|
|
|
|
|
view.background = bg.resolve(view.context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@CheckResult
|
|
|
|
|
fun applyBitmapConfig(ssiv: SubsamplingScaleImageView): Boolean {
|
|
|
|
|
val config = bitmapConfig
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onInactive() {
|
|
|
|
|
super.onInactive()
|
|
|
|
|
settings.unsubscribe(internalObserver)
|
|
|
|
|
@ -78,7 +108,8 @@ class ReaderSettings(
|
|
|
|
|
key == AppSettings.KEY_PAGES_NUMBERS ||
|
|
|
|
|
key == AppSettings.KEY_WEBTOON_ZOOM ||
|
|
|
|
|
key == AppSettings.KEY_READER_ZOOM_BUTTONS ||
|
|
|
|
|
key == AppSettings.KEY_READER_BACKGROUND
|
|
|
|
|
key == AppSettings.KEY_READER_BACKGROUND ||
|
|
|
|
|
key == AppSettings.KEY_32BIT_COLOR
|
|
|
|
|
) {
|
|
|
|
|
notifyChanged()
|
|
|
|
|
}
|
|
|
|
|
|