Skip to content

Commit 28b073e

Browse files
authored
Revisit navigator interfaces (#408)
1 parent cdfe876 commit 28b073e

File tree

31 files changed

+477
-330
lines changed

31 files changed

+477
-330
lines changed

docs/migration-guide.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,26 @@ navigator.addInputListener(object : InputListener {
166166
})
167167
```
168168

169+
### New navigator interfaces
170+
171+
An important part of `VisualNavigator` was moved to `DirectionalNavigator`. A new `HyperlinkNavigator`
172+
interface implemented by the `EpubFragmentNavigator` provides the ability to intercept clicks on
173+
links to both internal and external URLs. Opening external URLs is no longer handled by the navigator,
174+
that's something you should do by yourself in the way you like.
175+
169176
### Edge tap and keyboard navigation
170177

171178
Version 3.0.0 ships with a new `DirectionalNavigationAdapter` component replacing `EdgeTapNavigation`. This helper allows users to turn pages with arrow and space keys on their keyboard or by tapping the edge of the screen.
172179

173-
It's easy to set it up with an implementation of `VisualNavigator`, as it implements `InputListener`.
180+
It's easy to set it up with an implementation of `DirectionalNavigator`, as it implements `InputListener`.
174181

175182
```kotlin
176-
navigator.addInputListener(DirectionalNavigationAdapter(
177-
animatedTransition = true
178-
))
183+
navigator.addInputListener(
184+
DirectionalNavigationAdapter(
185+
navigator,
186+
animatedTransition = true
187+
)
188+
)
179189
```
180190

181191
`DirectionalNavigationAdapter` offers a lot of customization options. Take a look at its API.

readium/adapters/exoplayer/audio/src/main/java/org/readium/adapter/exoplayer/audio/ExoPlayerEngine.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,19 @@ public class ExoPlayerEngine private constructor(
205205
exoPlayer.pause()
206206
}
207207

208-
override fun seek(index: Int, position: Duration) {
209-
exoPlayer.seekTo(index, position.inWholeMilliseconds)
208+
override fun skipTo(index: Int, offset: Duration) {
209+
exoPlayer.seekTo(index, offset.inWholeMilliseconds)
210210
}
211211

212-
override fun seekBy(offset: Duration) {
213-
exoPlayer.seekBy(offset)
212+
override fun skip(duration: Duration) {
213+
exoPlayer.seekBy(duration)
214214
}
215215

216-
override fun seekForward() {
216+
override fun skipForward() {
217217
exoPlayer.seekForward()
218218
}
219219

220-
override fun seekBackward() {
220+
override fun skipBackward() {
221221
exoPlayer.seekBack()
222222
}
223223

readium/adapters/pdfium/navigator/src/main/java/org/readium/adapter/pdfium/navigator/PdfiumEngineProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ package org.readium.adapter.pdfium.navigator
88

99
import android.graphics.PointF
1010
import com.github.barteksc.pdfviewer.PDFView
11+
import org.readium.r2.navigator.OverflowNavigator
1112
import org.readium.r2.navigator.SimplePresentation
12-
import org.readium.r2.navigator.VisualNavigator
1313
import org.readium.r2.navigator.input.TapEvent
1414
import org.readium.r2.navigator.pdf.PdfDocumentFragmentInput
1515
import org.readium.r2.navigator.pdf.PdfEngineProvider
@@ -68,7 +68,7 @@ public class PdfiumEngineProvider(
6868
return settingsPolicy.settings(preferences)
6969
}
7070

71-
override fun computePresentation(settings: PdfiumSettings): VisualNavigator.Presentation =
71+
override fun computePresentation(settings: PdfiumSettings): OverflowNavigator.Presentation =
7272
SimplePresentation(
7373
readingProgression = settings.readingProgression,
7474
scroll = true,

readium/adapters/pspdfkit/navigator/src/main/java/org/readium/adapter/pspdfkit/navigator/PsPdfKitEngineProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ package org.readium.adapter.pspdfkit.navigator
88

99
import android.graphics.PointF
1010
import com.pspdfkit.configuration.PdfConfiguration
11+
import org.readium.r2.navigator.OverflowNavigator
1112
import org.readium.r2.navigator.SimplePresentation
12-
import org.readium.r2.navigator.VisualNavigator
1313
import org.readium.r2.navigator.input.TapEvent
1414
import org.readium.r2.navigator.pdf.PdfDocumentFragmentInput
1515
import org.readium.r2.navigator.pdf.PdfEngineProvider
@@ -68,7 +68,7 @@ public class PsPdfKitEngineProvider(
6868
return settingsPolicy.settings(preferences)
6969
}
7070

71-
override fun computePresentation(settings: PsPdfKitSettings): VisualNavigator.Presentation =
71+
override fun computePresentation(settings: PsPdfKitSettings): OverflowNavigator.Presentation =
7272
SimplePresentation(
7373
readingProgression = settings.readingProgression,
7474
scroll = settings.scroll,

readium/navigator-media2/src/main/java/org/readium/navigator/media2/MediaMetadataFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import androidx.media2.common.MediaMetadata
77
*
88
* The metadata are used for example in the media-style Android notification.
99
*/
10-
@ExperimentalMedia2
10+
@Deprecated("Use the new MediaMetadataFactory from the readium-navigator-media-common module.")
1111
public interface MediaMetadataFactory {
1212

1313
/**

readium/navigator-media2/src/main/java/org/readium/navigator/media2/MediaNavigator.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import timber.log.Timber
5555
* providing [create] with it. If you don't, ExoPlayer will be used, without cache.
5656
* You can build your own [SessionPlayer] based on [ExoPlayer] using [ExoPlayerDataSource].
5757
*/
58-
@ExperimentalMedia2
58+
@Deprecated("Use the new AudioNavigator from the readium-navigator-media-audio module.")
5959
@OptIn(ExperimentalTime::class)
6060
public class MediaNavigator private constructor(
6161
override val publication: Publication,
@@ -383,12 +383,12 @@ public class MediaNavigator private constructor(
383383
return true
384384
}
385385

386-
override fun goForward(animated: Boolean, completion: () -> Unit): Boolean {
386+
public fun goForward(animated: Boolean, completion: () -> Unit): Boolean {
387387
launchAndRun({ goForward() }, completion)
388388
return true
389389
}
390390

391-
override fun goBackward(animated: Boolean, completion: () -> Unit): Boolean {
391+
public fun goBackward(animated: Boolean, completion: () -> Unit): Boolean {
392392
launchAndRun({ goBackward() }, completion)
393393
return true
394394
}

readium/navigator/src/main/java/org/readium/r2/navigator/Deprecated.kt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,95 @@
99

1010
package org.readium.r2.navigator
1111

12+
import kotlin.time.Duration
13+
import kotlinx.coroutines.flow.Flow
14+
import org.readium.r2.navigator.media.MediaPlayback
15+
1216
@Deprecated("Use navigator fragments.", level = DeprecationLevel.ERROR)
1317
public interface IR2Activity
1418

1519
@Deprecated("Use TtsNavigator.", level = DeprecationLevel.ERROR)
1620
public interface IR2TTS
21+
22+
/**
23+
* A navigator rendering an audio or video publication.
24+
*/
25+
@Deprecated("Use the new readium-navigator-media modules.")
26+
@OptIn(ExperimentalAudiobook::class)
27+
public interface MediaNavigator : Navigator {
28+
29+
/**
30+
* Current playback information.
31+
*/
32+
public val playback: Flow<MediaPlayback>
33+
34+
/**
35+
* Indicates whether the navigator is currently playing.
36+
*/
37+
public val isPlaying: Boolean
38+
39+
/**
40+
* Sets the speed of the media playback.
41+
*
42+
* Normal speed is 1.0 and 0.0 is incorrect.
43+
*/
44+
public fun setPlaybackRate(rate: Double)
45+
46+
/**
47+
* Resumes or start the playback at the current location.
48+
*/
49+
public fun play()
50+
51+
/**
52+
* Pauses the playback.
53+
*/
54+
public fun pause()
55+
56+
/**
57+
* Toggles the playback.
58+
* Can be useful as a handler for play/pause button.
59+
*/
60+
public fun playPause()
61+
62+
/**
63+
* Stops the playback.
64+
*
65+
* Compared to [pause], the navigator may clear its state in whatever way is appropriate. For
66+
* example, recovering a player's resources.
67+
*/
68+
public fun stop()
69+
70+
/**
71+
* Seeks to the given time in the current resource.
72+
*/
73+
public fun seekTo(position: Duration)
74+
75+
/**
76+
* Seeks relatively from the current position in the current resource.
77+
*/
78+
public fun seekRelative(offset: Duration)
79+
80+
public interface Listener : Navigator.Listener
81+
}
82+
83+
/**
84+
* Moves to the left content portion (eg. page) relative to the reading progression direction.
85+
*/
86+
@Deprecated(
87+
"Use a DirectionalNavigationAdapter or goFoward and goBackward.",
88+
level = DeprecationLevel.ERROR
89+
)
90+
public fun VisualNavigator.goLeft(animated: Boolean = false, completion: () -> Unit = {}): Boolean {
91+
throw NotImplementedError()
92+
}
93+
94+
/**
95+
* Moves to the right content portion (eg. page) relative to the reading progression direction.
96+
*/
97+
@Deprecated(
98+
"Use a DirectionalNavigationAdapter or goFoward and goBackward.",
99+
level = DeprecationLevel.ERROR
100+
)
101+
public fun VisualNavigator.goRight(animated: Boolean = false, completion: () -> Unit = {}): Boolean {
102+
throw NotImplementedError()
103+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2023 Readium Foundation. All rights reserved.
3+
* Use of this source code is governed by the BSD-style license
4+
* available in the top-level LICENSE file of the project.
5+
*/
6+
7+
package org.readium.r2.navigator
8+
9+
import org.readium.r2.shared.ExperimentalReadiumApi
10+
import org.readium.r2.shared.publication.Link
11+
import org.readium.r2.shared.util.AbsoluteUrl
12+
13+
/**
14+
* A navigator supporting hyperlinks.
15+
*/
16+
@ExperimentalReadiumApi
17+
public interface HyperlinkNavigator : Navigator {
18+
19+
@ExperimentalReadiumApi
20+
public interface Listener : Navigator.Listener {
21+
22+
/**
23+
* Called when a link to an internal resource was clicked in the navigator.
24+
*
25+
* You can use this callback to perform custom navigation like opening a new window
26+
* or other operations.
27+
*
28+
* By returning false the navigator wont try to open the link itself and it is up
29+
* to the calling app to decide how to display the link.
30+
*/
31+
@ExperimentalReadiumApi
32+
public fun shouldFollowInternalLink(link: Link): Boolean { return true }
33+
34+
/**
35+
* Called when a link to an external URL was activated in the navigator.
36+
*/
37+
@ExperimentalReadiumApi
38+
public fun onExternalLinkActivated(url: AbsoluteUrl)
39+
}
40+
}

0 commit comments

Comments
 (0)