Add toggle to invert page color in reader color filter settings (#5713)
(cherry picked from commit 4c8dfd0c0c)
This commit is contained in:
@@ -55,6 +55,8 @@ object PreferenceKeys {
|
||||
|
||||
const val grayscale = "pref_grayscale"
|
||||
|
||||
const val invertedColors = "pref_inverted_colors"
|
||||
|
||||
const val defaultReadingMode = "pref_default_reading_mode_key"
|
||||
|
||||
const val defaultOrientationType = "pref_default_orientation_type_key"
|
||||
|
||||
@@ -133,6 +133,8 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
fun grayscale() = flowPrefs.getBoolean(Keys.grayscale, false)
|
||||
|
||||
fun invertedColors() = flowPrefs.getBoolean(Keys.invertedColors, false)
|
||||
|
||||
fun defaultReadingMode() = prefs.getInt(Keys.defaultReadingMode, ReadingModeType.RIGHT_TO_LEFT.flagValue)
|
||||
|
||||
fun defaultOrientationType() = prefs.getInt(Keys.defaultOrientationType, OrientationType.FREE.flagValue)
|
||||
|
||||
@@ -100,6 +100,7 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
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 kotlinx.coroutines.launch
|
||||
@@ -1466,11 +1467,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
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -1523,8 +1538,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()
|
||||
@@ -1675,8 +1690,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
|
||||
binding.customBrightness.bindToPreference(preferences.customBrightness())
|
||||
binding.colorFilterMode.bindToPreference(preferences.colorFilterMode())
|
||||
binding.grayscale.bindToPreference(preferences.grayscale())
|
||||
binding.invertedColors.bindToPreference(preferences.invertedColors())
|
||||
|
||||
binding.seekbarColorFilterAlpha.setOnSeekBarChangeListener(
|
||||
object : SimpleSeekBarListener() {
|
||||
|
||||
Reference in New Issue
Block a user