mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Add toggle to invert page color in reader color filter settings (#5713)
This commit is contained in:
parent
2b9dbfb390
commit
4c8dfd0c0c
6 changed files with 39 additions and 8 deletions
|
@ -53,6 +53,8 @@ object PreferenceKeys {
|
||||||
|
|
||||||
const val grayscale = "pref_grayscale"
|
const val grayscale = "pref_grayscale"
|
||||||
|
|
||||||
|
const val invertedColors = "pref_inverted_colors"
|
||||||
|
|
||||||
const val defaultReadingMode = "pref_default_reading_mode_key"
|
const val defaultReadingMode = "pref_default_reading_mode_key"
|
||||||
|
|
||||||
const val defaultOrientationType = "pref_default_orientation_type_key"
|
const val defaultOrientationType = "pref_default_orientation_type_key"
|
||||||
|
|
|
@ -129,6 +129,8 @@ class PreferencesHelper(val context: Context) {
|
||||||
|
|
||||||
fun grayscale() = flowPrefs.getBoolean(Keys.grayscale, false)
|
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 defaultReadingMode() = prefs.getInt(Keys.defaultReadingMode, ReadingModeType.RIGHT_TO_LEFT.flagValue)
|
||||||
|
|
||||||
fun defaultOrientationType() = prefs.getInt(Keys.defaultOrientationType, OrientationType.FREE.flagValue)
|
fun defaultOrientationType() = prefs.getInt(Keys.defaultOrientationType, OrientationType.FREE.flagValue)
|
||||||
|
|
|
@ -76,6 +76,7 @@ import eu.kanade.tachiyomi.widget.listener.SimpleAnimationListener
|
||||||
import eu.kanade.tachiyomi.widget.listener.SimpleSeekBarListener
|
import eu.kanade.tachiyomi.widget.listener.SimpleSeekBarListener
|
||||||
import kotlinx.coroutines.flow.drop
|
import kotlinx.coroutines.flow.drop
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.merge
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.sample
|
import kotlinx.coroutines.flow.sample
|
||||||
import nucleus.factory.RequiresPresenter
|
import nucleus.factory.RequiresPresenter
|
||||||
|
@ -879,11 +880,25 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||||
*/
|
*/
|
||||||
private inner class ReaderConfig {
|
private inner class ReaderConfig {
|
||||||
|
|
||||||
private val grayscalePaint by lazy {
|
private fun getCombinedPaint(grayscale: Boolean, invertedColors: Boolean): Paint {
|
||||||
Paint().apply {
|
return Paint().apply {
|
||||||
colorFilter = ColorMatrixColorFilter(
|
colorFilter = ColorMatrixColorFilter(
|
||||||
ColorMatrix().apply {
|
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()) }
|
.onEach { setColorFilter(preferences.colorFilter().get()) }
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.grayscale().asFlow()
|
merge(preferences.grayscale().asFlow(), preferences.invertedColors().asFlow())
|
||||||
.onEach { setGrayscale(it) }
|
.onEach { setLayerPaint(preferences.grayscale().get(), preferences.invertedColors().get()) }
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.fullscreen().asFlow()
|
preferences.fullscreen().asFlow()
|
||||||
|
@ -1065,8 +1080,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||||
binding.colorOverlay.setFilterColor(value, preferences.colorFilterMode().get())
|
binding.colorOverlay.setFilterColor(value, preferences.colorFilterMode().get())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setGrayscale(enabled: Boolean) {
|
private fun setLayerPaint(grayscale: Boolean, invertedColors: Boolean) {
|
||||||
val paint = if (enabled) grayscalePaint else null
|
val paint = if (grayscale || invertedColors) getCombinedPaint(grayscale, invertedColors) else null
|
||||||
binding.viewerContainer.setLayerType(LAYER_TYPE_HARDWARE, paint)
|
binding.viewerContainer.setLayerType(LAYER_TYPE_HARDWARE, paint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
|
||||||
binding.customBrightness.bindToPreference(preferences.customBrightness())
|
binding.customBrightness.bindToPreference(preferences.customBrightness())
|
||||||
binding.colorFilterMode.bindToPreference(preferences.colorFilterMode())
|
binding.colorFilterMode.bindToPreference(preferences.colorFilterMode())
|
||||||
binding.grayscale.bindToPreference(preferences.grayscale())
|
binding.grayscale.bindToPreference(preferences.grayscale())
|
||||||
|
binding.invertedColors.bindToPreference(preferences.invertedColors())
|
||||||
|
|
||||||
binding.seekbarColorFilterAlpha.setOnSeekBarChangeListener(
|
binding.seekbarColorFilterAlpha.setOnSeekBarChangeListener(
|
||||||
object : SimpleSeekBarListener() {
|
object : SimpleSeekBarListener() {
|
||||||
|
|
|
@ -193,6 +193,16 @@
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
app:layout_constraintTop_toBottomOf="@id/color_filter_mode" />
|
app:layout_constraintTop_toBottomOf="@id/color_filter_mode" />
|
||||||
|
|
||||||
|
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
|
android:id="@+id/inverted_colors"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:text="@string/pref_inverted_colors"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/grayscale" />
|
||||||
|
|
||||||
<!-- Brightness -->
|
<!-- Brightness -->
|
||||||
|
|
||||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
|
@ -203,7 +213,7 @@
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingEnd="16dp"
|
||||||
android:text="@string/pref_custom_brightness"
|
android:text="@string/pref_custom_brightness"
|
||||||
app:layout_constraintTop_toBottomOf="@id/grayscale" />
|
app:layout_constraintTop_toBottomOf="@id/inverted_colors" />
|
||||||
|
|
||||||
<!-- Brightness value -->
|
<!-- Brightness value -->
|
||||||
|
|
||||||
|
|
|
@ -275,6 +275,7 @@
|
||||||
<string name="off">Off</string>
|
<string name="off">Off</string>
|
||||||
<string name="pref_custom_brightness">Custom brightness</string>
|
<string name="pref_custom_brightness">Custom brightness</string>
|
||||||
<string name="pref_grayscale">Grayscale</string>
|
<string name="pref_grayscale">Grayscale</string>
|
||||||
|
<string name="pref_inverted_colors">Inverted</string>
|
||||||
<string name="pref_custom_color_filter">Custom color filter</string>
|
<string name="pref_custom_color_filter">Custom color filter</string>
|
||||||
<string name="pref_color_filter_mode">Color filter blend mode</string>
|
<string name="pref_color_filter_mode">Color filter blend mode</string>
|
||||||
<string name="filter_mode_default">Default</string>
|
<string name="filter_mode_default">Default</string>
|
||||||
|
|
Loading…
Reference in a new issue