Skip to content

Commit 1521e33

Browse files
authored
Navigator: Fix EPUB layout fallback (#57)
Fallback on `reflowable` if the `presentation.layout` hint is missing from a manifest.
1 parent c801648 commit 1521e33

File tree

3 files changed

+59
-53
lines changed

3 files changed

+59
-53
lines changed

CHANGELOG.md

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

3232
* Fixed turning pages of an EPUB reflowable resource with an odd number of columns. A virtual blank trailing column is appended to the resource when displayed as two columns.
33+
* EPUB: Fallback on `reflowable` if the `presentation.layout` hint is missing from a manifest.
3334

3435

3536
## [2.1.1]

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

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -139,64 +139,72 @@ class EpubNavigatorFragment private constructor(
139139
resourcePager = binding.resourcePager
140140
resourcePager.type = Publication.TYPE.EPUB
141141

142-
if (publication.metadata.presentation.layout == EpubLayout.REFLOWABLE) {
143-
resourcesSingle = publication.readingOrder.mapIndexed { index, link ->
144-
PageResource.EpubReflowable(
145-
link = link,
146-
url = link.withBaseUrl(baseUrl).href,
147-
positionCount = positionsByReadingOrder.getOrNull(index)?.size ?: 0
148-
)
149-
}
142+
when (publication.metadata.presentation.layout) {
143+
EpubLayout.REFLOWABLE, null -> {
144+
resourcesSingle = publication.readingOrder.mapIndexed { index, link ->
145+
PageResource.EpubReflowable(
146+
link = link,
147+
url = link.withBaseUrl(baseUrl).href,
148+
positionCount = positionsByReadingOrder.getOrNull(index)?.size ?: 0
149+
)
150+
}
150151

151-
adapter = R2PagerAdapter(childFragmentManager, resourcesSingle)
152-
resourcePager.type = Publication.TYPE.EPUB
152+
adapter = R2PagerAdapter(childFragmentManager, resourcesSingle)
153+
resourcePager.type = Publication.TYPE.EPUB
154+
}
153155

154-
} else {
155-
val resourcesSingle = mutableListOf<PageResource>()
156-
val resourcesDouble = mutableListOf<PageResource>()
156+
EpubLayout.FIXED -> {
157+
val resourcesSingle = mutableListOf<PageResource>()
158+
val resourcesDouble = mutableListOf<PageResource>()
157159

158-
// TODO needs work, currently showing two resources for fxl, needs to understand which two resources, left & right, or only right etc.
159-
var doublePageLeft = ""
160-
var doublePageRight = ""
160+
// TODO needs work, currently showing two resources for fxl, needs to understand which two resources, left & right, or only right etc.
161+
var doublePageLeft = ""
162+
var doublePageRight = ""
161163

162-
for ((index, link) in publication.readingOrder.withIndex()) {
163-
val url = link.withBaseUrl(baseUrl).href
164-
resourcesSingle.add(PageResource.EpubFxl(url))
164+
for ((index, link) in publication.readingOrder.withIndex()) {
165+
val url = link.withBaseUrl(baseUrl).href
166+
resourcesSingle.add(PageResource.EpubFxl(url))
165167

166-
// add first page to the right,
167-
if (index == 0) {
168-
resourcesDouble.add(PageResource.EpubFxl("", url))
169-
} else {
170-
// add double pages, left & right
171-
if (doublePageLeft == "") {
172-
doublePageLeft = url
168+
// add first page to the right,
169+
if (index == 0) {
170+
resourcesDouble.add(PageResource.EpubFxl("", url))
173171
} else {
174-
doublePageRight = url
175-
resourcesDouble.add(PageResource.EpubFxl(doublePageLeft, doublePageRight))
176-
doublePageLeft = ""
172+
// add double pages, left & right
173+
if (doublePageLeft == "") {
174+
doublePageLeft = url
175+
} else {
176+
doublePageRight = url
177+
resourcesDouble.add(
178+
PageResource.EpubFxl(
179+
doublePageLeft,
180+
doublePageRight
181+
)
182+
)
183+
doublePageLeft = ""
184+
}
177185
}
178186
}
179-
}
180-
// add last page if there is only a left page remaining
181-
if (doublePageLeft != "") {
182-
resourcesDouble.add(PageResource.EpubFxl(doublePageLeft, ""))
183-
}
187+
// add last page if there is only a left page remaining
188+
if (doublePageLeft != "") {
189+
resourcesDouble.add(PageResource.EpubFxl(doublePageLeft, ""))
190+
}
184191

185-
this.resourcesSingle = resourcesSingle
186-
this.resourcesDouble = resourcesDouble
192+
this.resourcesSingle = resourcesSingle
193+
this.resourcesDouble = resourcesDouble
187194

188-
resourcePager.type = Publication.TYPE.FXL
189-
adapter = when (preferences.getInt(COLUMN_COUNT_REF, 0)) {
190-
1 -> {
191-
R2PagerAdapter(childFragmentManager, resourcesSingle)
192-
}
193-
2 -> {
194-
R2PagerAdapter(childFragmentManager, resourcesDouble)
195-
}
196-
else -> {
197-
// TODO based on device
198-
// TODO decide if 1 page or 2 page
199-
R2PagerAdapter(childFragmentManager, resourcesSingle)
195+
resourcePager.type = Publication.TYPE.FXL
196+
adapter = when (preferences.getInt(COLUMN_COUNT_REF, 0)) {
197+
1 -> {
198+
R2PagerAdapter(childFragmentManager, resourcesSingle)
199+
}
200+
2 -> {
201+
R2PagerAdapter(childFragmentManager, resourcesDouble)
202+
}
203+
else -> {
204+
// TODO based on device
205+
// TODO decide if 1 page or 2 page
206+
R2PagerAdapter(childFragmentManager, resourcesSingle)
207+
}
200208
}
201209
}
202210
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import androidx.fragment.app.FragmentResultListener
1818
import androidx.fragment.app.commit
1919
import androidx.fragment.app.commitNow
2020
import androidx.lifecycle.ViewModelProvider
21-
import org.readium.r2.shared.publication.Locator
22-
import org.readium.r2.shared.publication.Publication
23-
import org.readium.r2.shared.publication.allAreAudio
24-
import org.readium.r2.shared.publication.allAreBitmap
21+
import org.readium.r2.shared.publication.*
2522
import org.readium.r2.shared.util.mediatype.MediaType
2623
import org.readium.r2.testapp.R
2724
import org.readium.r2.testapp.databinding.ActivityReaderBinding
@@ -59,7 +56,7 @@ open class ReaderActivity : AppCompatActivity() {
5956

6057
if (savedInstanceState == null) {
6158

62-
if (publication.type == Publication.TYPE.EPUB) {
59+
if (publication.type == Publication.TYPE.EPUB || publication.readingOrder.allAreHtml) {
6360
val baseUrl = requireNotNull(inputData.baseUrl)
6461
readerFragment = EpubReaderFragment.newInstance(baseUrl)
6562

0 commit comments

Comments
 (0)