|
@@ -76,6 +76,7 @@ import eu.kanade.tachiyomi.widget.listener.SimpleAnimationListener
|
|
|
import eu.kanade.tachiyomi.widget.listener.SimpleSeekBarListener
|
|
|
import kotlinx.coroutines.flow.drop
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
+import kotlinx.coroutines.flow.merge
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
|
import kotlinx.coroutines.flow.sample
|
|
|
import nucleus.factory.RequiresPresenter
|
|
@@ -879,11 +880,25 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
*/
|
|
|
private inner class ReaderConfig {
|
|
|
|
|
|
- private val grayscalePaint by lazy {
|
|
|
- Paint().apply {
|
|
|
+ private fun getCombinedPaint(grayscale: Boolean, invertedColors: Boolean): Paint {
|
|
|
+ return Paint().apply {
|
|
|
colorFilter = ColorMatrixColorFilter(
|
|
|
ColorMatrix().apply {
|
|
|
- setSaturation(0f)
|
|
|
+ if (grayscale) {
|
|
|
+ setSaturation(0f)
|
|
|
+ }
|
|
|
+ if (invertedColors) {
|
|
|
+ postConcat(
|
|
|
+ ColorMatrix(
|
|
|
+ floatArrayOf(
|
|
|
+ -1f, 0f, 0f, 0f, 255f,
|
|
|
+ 0f, -1f, 0f, 0f, 255f,
|
|
|
+ 0f, 0f, -1f, 0f, 255f,
|
|
|
+ 0f, 0f, 0f, 1f, 0f
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
)
|
|
|
}
|
|
@@ -936,8 +951,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
.onEach { setColorFilter(preferences.colorFilter().get()) }
|
|
|
.launchIn(lifecycleScope)
|
|
|
|
|
|
- preferences.grayscale().asFlow()
|
|
|
- .onEach { setGrayscale(it) }
|
|
|
+ merge(preferences.grayscale().asFlow(), preferences.invertedColors().asFlow())
|
|
|
+ .onEach { setLayerPaint(preferences.grayscale().get(), preferences.invertedColors().get()) }
|
|
|
.launchIn(lifecycleScope)
|
|
|
|
|
|
preferences.fullscreen().asFlow()
|
|
@@ -1065,8 +1080,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
|
binding.colorOverlay.setFilterColor(value, preferences.colorFilterMode().get())
|
|
|
}
|
|
|
|
|
|
- private fun setGrayscale(enabled: Boolean) {
|
|
|
- val paint = if (enabled) grayscalePaint else null
|
|
|
+ private fun setLayerPaint(grayscale: Boolean, invertedColors: Boolean) {
|
|
|
+ val paint = if (grayscale || invertedColors) getCombinedPaint(grayscale, invertedColors) else null
|
|
|
binding.viewerContainer.setLayerType(LAYER_TYPE_HARDWARE, paint)
|
|
|
}
|
|
|
}
|