Global color filter initial implementation #562
This commit is contained in:
@@ -90,7 +90,12 @@ class ColorFilterConfigActivity :
|
||||
|
||||
override fun onClick(v: View) {
|
||||
when (v.id) {
|
||||
R.id.button_done -> viewModel.save()
|
||||
R.id.button_done -> if (viewBinding.checkBoxGlobal.isChecked) {
|
||||
viewModel.saveGlobally()
|
||||
} else {
|
||||
viewModel.save()
|
||||
}
|
||||
|
||||
R.id.button_reset -> viewModel.reset()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class ColorFilterConfigViewModel @Inject constructor(
|
||||
|
||||
init {
|
||||
launchLoadingJob {
|
||||
initialColorFilter = mangaDataRepository.getColorFilter(manga.id)
|
||||
initialColorFilter = mangaDataRepository.getColorFilter(manga.id) ?: settings.readerColorFilter
|
||||
colorFilter.value = initialColorFilter
|
||||
}
|
||||
}
|
||||
@@ -83,4 +83,9 @@ class ColorFilterConfigViewModel @Inject constructor(
|
||||
onDismiss.call(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
fun saveGlobally() {
|
||||
settings.readerColorFilter = colorFilter.value
|
||||
onDismiss.call(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class ReaderSettings(
|
||||
get() = settings.zoomMode
|
||||
|
||||
val colorFilter: ReaderColorFilter?
|
||||
get() = colorFilterFlow.value?.takeUnless { it.isEmpty }
|
||||
get() = colorFilterFlow.value?.takeUnless { it.isEmpty } ?: settings.readerColorFilter
|
||||
|
||||
val isReaderOptimizationEnabled: Boolean
|
||||
get() = settings.isReaderOptimizationEnabled
|
||||
@@ -96,6 +96,18 @@ class ReaderSettings(
|
||||
FlowCollector<ReaderColorFilter?>,
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private val settingsKeys = setOf(
|
||||
AppSettings.KEY_ZOOM_MODE,
|
||||
AppSettings.KEY_PAGES_NUMBERS,
|
||||
AppSettings.KEY_READER_BACKGROUND,
|
||||
AppSettings.KEY_32BIT_COLOR,
|
||||
AppSettings.KEY_READER_OPTIMIZE,
|
||||
AppSettings.KEY_CF_ENABLED,
|
||||
AppSettings.KEY_CF_CONTRAST,
|
||||
AppSettings.KEY_CF_BRIGHTNESS,
|
||||
AppSettings.KEY_CF_INVERTED,
|
||||
)
|
||||
|
||||
override suspend fun emit(value: ReaderColorFilter?) {
|
||||
withContext(Dispatchers.Main.immediate) {
|
||||
notifyChanged()
|
||||
@@ -103,13 +115,7 @@ class ReaderSettings(
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
if (
|
||||
key == AppSettings.KEY_ZOOM_MODE ||
|
||||
key == AppSettings.KEY_PAGES_NUMBERS ||
|
||||
key == AppSettings.KEY_READER_BACKGROUND ||
|
||||
key == AppSettings.KEY_32BIT_COLOR ||
|
||||
key == AppSettings.KEY_READER_OPTIMIZE
|
||||
) {
|
||||
if (key in settingsKeys) {
|
||||
notifyChanged()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user