-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new experimental EPUB FXL navigator (#567)
- Loading branch information
Showing
132 changed files
with
12,141 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,3 +94,6 @@ lcp.patch | |
|
||
# Kotlin | ||
.kotlin/ | ||
|
||
# Script outpouts | ||
readium/navigators/web/scripts/dist/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2022 Readium Foundation. All rights reserved. | ||
* Use of this source code is governed by the BSD-style license | ||
* available in the top-level LICENSE file of the project. | ||
*/ | ||
|
||
plugins { | ||
id("readium.library-conventions") | ||
alias(libs.plugins.kotlin.serialization) | ||
alias(libs.plugins.compose.compiler) | ||
} | ||
|
||
android { | ||
namespace = "org.readium.navigators.common" | ||
|
||
buildFeatures { | ||
compose = true | ||
} | ||
} | ||
|
||
dependencies { | ||
api(project(":readium:readium-shared")) | ||
api(project(":readium:readium-navigator")) | ||
|
||
implementation(libs.kotlinx.serialization.json) | ||
implementation(libs.bundles.compose) | ||
implementation(libs.timber) | ||
implementation(libs.kotlinx.coroutines.android) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pom.artifactId=readium-navigator-common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
104 changes: 104 additions & 0 deletions
104
readium/navigators/common/src/main/java/org/readium/navigator/common/HyperlinkListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2024 Readium Foundation. All rights reserved. | ||
* Use of this source code is governed by the BSD-style license | ||
* available in the top-level LICENSE file of the project. | ||
*/ | ||
|
||
package org.readium.navigator.common | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import org.readium.r2.shared.ExperimentalReadiumApi | ||
import org.readium.r2.shared.util.AbsoluteUrl | ||
import org.readium.r2.shared.util.Url | ||
|
||
/** | ||
* This listener lets you decide what to do when hyperlinks are activated, whether they point to | ||
* a readingOrder item, a non-linear resource or external content. | ||
*/ | ||
@ExperimentalReadiumApi | ||
public interface HyperlinkListener { | ||
|
||
public fun onReadingOrderLinkActivated(location: HyperlinkLocation, context: LinkContext?) | ||
|
||
public fun onNonLinearLinkActivated(location: HyperlinkLocation, context: LinkContext?) | ||
|
||
public fun onExternalLinkActivated(url: AbsoluteUrl, context: LinkContext?) | ||
} | ||
|
||
@ExperimentalReadiumApi | ||
public data class HyperlinkLocation( | ||
public val href: Url, | ||
public val fragment: String? = null | ||
) | ||
|
||
@ExperimentalReadiumApi | ||
public sealed interface LinkContext | ||
|
||
@ExperimentalReadiumApi | ||
public data class FootnoteContext( | ||
public val noteContent: String | ||
) : LinkContext | ||
|
||
@ExperimentalReadiumApi | ||
public class NullHyperlinkListener : HyperlinkListener { | ||
override fun onReadingOrderLinkActivated(location: HyperlinkLocation, context: LinkContext?) { | ||
} | ||
|
||
override fun onNonLinearLinkActivated(location: HyperlinkLocation, context: LinkContext?) { | ||
} | ||
|
||
override fun onExternalLinkActivated(url: AbsoluteUrl, context: LinkContext?) { | ||
} | ||
} | ||
|
||
/** | ||
* A [HyperlinkListener] following links to readingOrder items. | ||
* | ||
* Activations of links to external content or non-linear items are ignored by default. | ||
* To handle them, pass [onNonLinearLinkActivated] and [onExternalLinkActivated] delegates. | ||
*/ | ||
@ExperimentalReadiumApi | ||
@Composable | ||
public fun <L : Location> defaultHyperlinkListener( | ||
controller: NavigationController<L, *>, | ||
shouldFollowReadingOrderLink: (HyperlinkLocation, LinkContext?) -> Boolean = { _, _ -> true }, | ||
onNonLinearLinkActivated: (HyperlinkLocation, LinkContext?) -> Unit = { _, _ -> }, | ||
onExternalLinkActivated: (AbsoluteUrl, LinkContext?) -> Unit = { _, _ -> } | ||
): HyperlinkListener { | ||
val coroutineScope = rememberCoroutineScope() | ||
|
||
return DefaultHyperlinkListener( | ||
coroutineScope = coroutineScope, | ||
controller = controller, | ||
shouldFollowReadingOrderLink = shouldFollowReadingOrderLink, | ||
onNonLinearLinkActivatedDelegate = onNonLinearLinkActivated, | ||
onExternalLinkActivatedDelegate = onExternalLinkActivated | ||
) | ||
} | ||
|
||
@ExperimentalReadiumApi | ||
private class DefaultHyperlinkListener<L : Location>( | ||
private val coroutineScope: CoroutineScope, | ||
private val controller: NavigationController<L, *>, | ||
private val shouldFollowReadingOrderLink: (HyperlinkLocation, LinkContext?) -> Boolean, | ||
private val onNonLinearLinkActivatedDelegate: (HyperlinkLocation, LinkContext?) -> Unit, | ||
private val onExternalLinkActivatedDelegate: (AbsoluteUrl, LinkContext?) -> Unit | ||
) : HyperlinkListener { | ||
|
||
override fun onReadingOrderLinkActivated(location: HyperlinkLocation, context: LinkContext?) { | ||
if (shouldFollowReadingOrderLink(location, context)) { | ||
coroutineScope.launch { controller.goTo(location) } | ||
} | ||
} | ||
|
||
override fun onNonLinearLinkActivated(location: HyperlinkLocation, context: LinkContext?) { | ||
onNonLinearLinkActivatedDelegate(location, context) | ||
} | ||
|
||
override fun onExternalLinkActivated(url: AbsoluteUrl, context: LinkContext?) { | ||
onExternalLinkActivatedDelegate(url, context) | ||
} | ||
} |
Oops, something went wrong.