Merge branch 'feature/32-bit' into devel
This commit is contained in:
@@ -336,6 +336,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
return policy.isNetworkAllowed(connectivityManager)
|
||||
}
|
||||
|
||||
val is32BitColorsEnabled: Boolean
|
||||
get() = prefs.getBoolean(KEY_32BIT_COLOR, false)
|
||||
|
||||
fun isTipEnabled(tip: String): Boolean {
|
||||
return prefs.getStringSet(KEY_TIPS_CLOSED, emptySet())?.contains(tip) != true
|
||||
}
|
||||
@@ -491,6 +494,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
const val KEY_DISABLE_NSFW = "no_nsfw"
|
||||
const val KEY_RELATED_MANGA = "related_manga"
|
||||
const val KEY_NAV_MAIN = "nav_main"
|
||||
const val KEY_32BIT_COLOR = "enhanced_colors"
|
||||
|
||||
// About
|
||||
const val KEY_APP_UPDATE = "app_update"
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -46,6 +46,10 @@ open class PageHolder(
|
||||
override fun onConfigChanged() {
|
||||
super.onConfigChanged()
|
||||
binding.zoomControl.isVisible = settings.isZoomControlsEnabled
|
||||
@Suppress("SENSELESS_COMPARISON")
|
||||
if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) {
|
||||
delegate.reload()
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
||||
@@ -6,7 +6,6 @@ import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.davemorrissey.labs.subscaleview.ImageSource
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
import com.davemorrissey.labs.subscaleview.decoder.SkiaPooledImageRegionDecoder
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
@@ -34,12 +33,19 @@ class WebtoonHolder(
|
||||
|
||||
init {
|
||||
binding.ssiv.bindToLifecycle(owner)
|
||||
binding.ssiv.regionDecoderFactory = SkiaPooledImageRegionDecoder.Factory()
|
||||
binding.ssiv.addOnImageEventListener(delegate)
|
||||
bindingInfo.buttonRetry.setOnClickListener(this)
|
||||
bindingInfo.buttonErrorDetails.setOnClickListener(this)
|
||||
}
|
||||
|
||||
override fun onConfigChanged() {
|
||||
super.onConfigChanged()
|
||||
@Suppress("SENSELESS_COMPARISON")
|
||||
if (settings.applyBitmapConfig(binding.ssiv) && delegate != null) {
|
||||
delegate.reload()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBind(data: ReaderPage) {
|
||||
delegate.onBind(data.toMangaPage())
|
||||
}
|
||||
|
||||
@@ -492,4 +492,6 @@
|
||||
<string name="keep_screen_on">Keep screen on</string>
|
||||
<string name="keep_screen_on_summary">Do not turn the screen off while you\'re reading manga</string>
|
||||
<string name="state_abandoned">Dropped</string>
|
||||
<string name="enhanced_colors_summary">Reduces banding, but may impact performance</string>
|
||||
<string name="enhanced_colors">32-bit color mode</string>
|
||||
</resources>
|
||||
|
||||
@@ -54,6 +54,12 @@
|
||||
android:title="@string/pages_animation"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="enhanced_colors"
|
||||
android:summary="@string/enhanced_colors_summary"
|
||||
android:title="@string/enhanced_colors" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="reader_bar"
|
||||
|
||||
Reference in New Issue
Block a user