Skip to content

Commit af2f764

Browse files
authored
Add backgroundColor preference for fixed-layout EPUB (#324)
1 parent e44c60b commit af2f764

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. Take a look
1010

1111
#### Navigator
1212

13+
* The EPUB `backgroundColor` preference is now available with fixed-layout publications.
1314
* New `EPUBNavigatorFragment.Configuration.useReadiumCssFontSize` option to revert to the 2.2.0 strategy for setting the font size of reflowable EPUB publications.
1415
* The native font size strategy introduced in 2.3.0 uses the Android web view's [`WebSettings.textZoom`](https://developer.android.com/reference/android/webkit/WebSettings#setTextZoom(int)) property to adjust the font size. 2.2.0 was using Readium CSS's [`--USER__fontSize` variable](https://readium.org/readium-css/docs/CSS12-user_prefs.html#font-size).
1516
* `WebSettings.textZoom` will work with more publications than `--USER__fontSize`, even the ones poorly authored. However the page width is not adjusted when changing the font size to keep the optimal line length.

readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubNavigatorFragment.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,14 +508,15 @@ class EpubNavigatorFragment internal constructor(
508508
}
509509

510510
private fun onSettingsChange(previous: EpubSettings, new: EpubSettings) {
511-
if (viewModel.layout == EpubLayout.FIXED) return
512-
513-
if (previous.fontSize != new.fontSize) {
514-
r2PagerAdapter?.setFontSize(new.fontSize)
515-
}
516511
if (previous.effectiveBackgroundColor != new.effectiveBackgroundColor) {
517512
resourcePager.setBackgroundColor(new.effectiveBackgroundColor)
518513
}
514+
515+
if (viewModel.layout == EpubLayout.REFLOWABLE) {
516+
if (previous.fontSize != new.fontSize) {
517+
r2PagerAdapter?.setFontSize(new.fontSize)
518+
}
519+
}
519520
}
520521

521522
private fun R2PagerAdapter.setFontSize(fontSize: Double) {

readium/navigator/src/main/java/org/readium/r2/navigator/epub/EpubPreferencesEditor.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ class EpubPreferencesEditor internal constructor(
5252
}
5353

5454
/**
55-
* Default page background color.
55+
* Default background color.
56+
*
57+
* For fixed-layout publications, it applies to the navigator background but not the publication
58+
* pages.
5659
*
5760
* When unset, the current [theme] background color is effective.
58-
* Only effective with fixed-layout publications.
5961
*/
6062
val backgroundColor: Preference<Color> =
6163
PreferenceDelegate(
6264
getValue = { preferences.backgroundColor },
6365
getEffectiveValue = { state.settings.backgroundColor ?: Color((theme.value ?: theme.effectiveValue).backgroundColor) },
64-
getIsEffective = { layout == EpubLayout.REFLOWABLE && preferences.backgroundColor != null },
66+
getIsEffective = { preferences.backgroundColor != null },
6567
updateValue = { value -> updateValues { it.copy(backgroundColor = value) } },
6668
)
6769

test-app/src/main/java/org/readium/r2/testapp/reader/preferences/UserPreferences.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private fun <P : Configurable.Preferences<P>, E : PreferencesEditor<P>> UserPref
125125
EpubLayout.FIXED ->
126126
FixedLayoutUserPreferences(
127127
commit = commit,
128+
backgroundColor = editor.backgroundColor,
128129
language = editor.language,
129130
readingProgression = editor.readingProgression,
130131
spread = editor.spread,
@@ -142,6 +143,7 @@ private fun ColumnScope.FixedLayoutUserPreferences(
142143
commit: () -> Unit,
143144
language: Preference<Language?>? = null,
144145
readingProgression: EnumPreference<ReadingProgression>? = null,
146+
backgroundColor: Preference<ReadiumColor>? = null,
145147
scroll: Preference<Boolean>? = null,
146148
scrollAxis: EnumPreference<Axis>? = null,
147149
fit: EnumPreference<Fit>? = null,
@@ -175,6 +177,16 @@ private fun ColumnScope.FixedLayoutUserPreferences(
175177
Divider()
176178
}
177179

180+
if (backgroundColor != null) {
181+
ColorItem(
182+
title = "Background color",
183+
preference = backgroundColor,
184+
commit = commit
185+
)
186+
187+
Divider()
188+
}
189+
178190
if (scroll != null) {
179191
SwitchItem(
180192
title = "Scroll",

0 commit comments

Comments
 (0)