From 81425cc0a461c3ebde8d8f90db2082cc2d72bd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Fri, 13 Jan 2023 15:19:14 +0100 Subject: [PATCH 1/2] Add `backgroundColor` preference for fixed-layout EPUB --- CHANGELOG.md | 8 +++++++- .../r2/navigator/epub/EpubNavigatorFragment.kt | 11 ++++++----- .../r2/navigator/epub/EpubPreferencesEditor.kt | 3 +-- .../r2/testapp/reader/preferences/UserPreferences.kt | 12 ++++++++++++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c45abc3207..73130c3c6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file. Take a look **Warning:** Features marked as *experimental* may change or be removed in a future release without notice. Use with caution. - +## [Unreleased] + +### Added + +#### Navigator + +* The EPUB `backgroundColor` preference is now available with fixed-layout publications. ## [2.3.0] diff --git a/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubNavigatorFragment.kt b/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubNavigatorFragment.kt index 5ebca0739f..4abdf5946e 100644 --- a/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubNavigatorFragment.kt +++ b/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubNavigatorFragment.kt @@ -492,14 +492,15 @@ class EpubNavigatorFragment internal constructor( } private fun onSettingsChange(previous: EpubSettings, new: EpubSettings) { - if (viewModel.layout == EpubLayout.FIXED) return - - if (previous.fontSize != new.fontSize) { - r2PagerAdapter?.setFontSize(new.fontSize) - } if (previous.effectiveBackgroundColor != new.effectiveBackgroundColor) { resourcePager.setBackgroundColor(new.effectiveBackgroundColor) } + + if (viewModel.layout == EpubLayout.REFLOWABLE) { + if (previous.fontSize != new.fontSize) { + r2PagerAdapter?.setFontSize(new.fontSize) + } + } } private fun R2PagerAdapter.setFontSize(fontSize: Double) { diff --git a/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubPreferencesEditor.kt b/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubPreferencesEditor.kt index 8ebea85b05..c5df0085e6 100644 --- a/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubPreferencesEditor.kt +++ b/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubPreferencesEditor.kt @@ -55,13 +55,12 @@ class EpubPreferencesEditor internal constructor( * Default page background color. * * When unset, the current [theme] background color is effective. - * Only effective with fixed-layout publications. */ val backgroundColor: Preference = PreferenceDelegate( getValue = { preferences.backgroundColor }, getEffectiveValue = { state.settings.backgroundColor ?: Color((theme.value ?: theme.effectiveValue).backgroundColor) }, - getIsEffective = { layout == EpubLayout.REFLOWABLE && preferences.backgroundColor != null }, + getIsEffective = { preferences.backgroundColor != null }, updateValue = { value -> updateValues { it.copy(backgroundColor = value) } }, ) diff --git a/test-app/src/main/java/org/readium/r2/testapp/reader/preferences/UserPreferences.kt b/test-app/src/main/java/org/readium/r2/testapp/reader/preferences/UserPreferences.kt index 6cc167d785..c44be733b5 100644 --- a/test-app/src/main/java/org/readium/r2/testapp/reader/preferences/UserPreferences.kt +++ b/test-app/src/main/java/org/readium/r2/testapp/reader/preferences/UserPreferences.kt @@ -125,6 +125,7 @@ private fun

, E : PreferencesEditor

> UserPref EpubLayout.FIXED -> FixedLayoutUserPreferences( commit = commit, + backgroundColor = editor.backgroundColor, language = editor.language, readingProgression = editor.readingProgression, spread = editor.spread, @@ -142,6 +143,7 @@ private fun ColumnScope.FixedLayoutUserPreferences( commit: () -> Unit, language: Preference? = null, readingProgression: EnumPreference? = null, + backgroundColor: Preference? = null, scroll: Preference? = null, scrollAxis: EnumPreference? = null, fit: EnumPreference? = null, @@ -175,6 +177,16 @@ private fun ColumnScope.FixedLayoutUserPreferences( Divider() } + if (backgroundColor != null) { + ColorItem( + title = "Background color", + preference = backgroundColor, + commit = commit + ) + + Divider() + } + if (scroll != null) { SwitchItem( title = "Scroll", From 379ca4d5ff6d095f97d927cec27f848411cadfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Fri, 20 Jan 2023 12:41:29 +0100 Subject: [PATCH 2/2] Adjust documentation --- .../org/readium/r2/navigator/epub/EpubPreferencesEditor.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubPreferencesEditor.kt b/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubPreferencesEditor.kt index c5df0085e6..9012728078 100644 --- a/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubPreferencesEditor.kt +++ b/readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubPreferencesEditor.kt @@ -52,7 +52,10 @@ class EpubPreferencesEditor internal constructor( } /** - * Default page background color. + * Default background color. + * + * For fixed-layout publications, it applies to the navigator background but not the publication + * pages. * * When unset, the current [theme] background color is effective. */