diff --git a/readium/navigator/src/main/java/org/readium/r2/navigator/Experimental.kt b/readium/navigator/src/main/java/org/readium/r2/navigator/OptIn.kt similarity index 62% rename from readium/navigator/src/main/java/org/readium/r2/navigator/Experimental.kt rename to readium/navigator/src/main/java/org/readium/r2/navigator/OptIn.kt index 904dc6f4b7..cc639ab824 100644 --- a/readium/navigator/src/main/java/org/readium/r2/navigator/Experimental.kt +++ b/readium/navigator/src/main/java/org/readium/r2/navigator/OptIn.kt @@ -6,12 +6,18 @@ package org.readium.r2.navigator -@RequiresOptIn(message = "Support for the Decorator API is still experimental. The API may be changed in the future without notice.") +@RequiresOptIn( + level = RequiresOptIn.Level.WARNING, + message = "Support for the Decorator API is still experimental. The API may be changed in the future without notice." +) @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.PROPERTY) annotation class ExperimentalDecorator -@RequiresOptIn(message = "The new Audiobook navigator is still experimental. The API may be changed in the future without notice.") +@RequiresOptIn( + level = RequiresOptIn.Level.WARNING, + message = "The new Audiobook navigator is still experimental. The API may be changed in the future without notice." +) @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.PROPERTY) annotation class ExperimentalAudiobook diff --git a/readium/navigator/src/main/java/org/readium/r2/navigator/R2BasicWebView.kt b/readium/navigator/src/main/java/org/readium/r2/navigator/R2BasicWebView.kt index 80b8886eb3..d9632aa364 100644 --- a/readium/navigator/src/main/java/org/readium/r2/navigator/R2BasicWebView.kt +++ b/readium/navigator/src/main/java/org/readium/r2/navigator/R2BasicWebView.kt @@ -26,7 +26,6 @@ import android.widget.ListPopupWindow import android.widget.PopupWindow import android.widget.TextView import androidx.annotation.RequiresApi -import androidx.browser.customtabs.CustomTabsIntent import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableStateFlow import org.json.JSONObject 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 3419787cc5..3909911a04 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 @@ -18,7 +18,6 @@ import android.view.View import android.view.ViewGroup import android.webkit.WebResourceRequest import android.webkit.WebView -import androidx.browser.customtabs.CustomTabsIntent import androidx.collection.forEach import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity @@ -43,6 +42,7 @@ import org.readium.r2.navigator.pager.R2PagerAdapter.PageResource import org.readium.r2.navigator.pager.R2ViewPager import org.readium.r2.navigator.util.createFragmentFactory import org.readium.r2.shared.COLUMN_COUNT_REF +import org.readium.r2.shared.InternalReadiumApi import org.readium.r2.shared.SCROLL_REF import org.readium.r2.shared.extensions.addPrefix import org.readium.r2.shared.extensions.tryOrLog @@ -51,6 +51,7 @@ import org.readium.r2.shared.publication.epub.EpubLayout import org.readium.r2.shared.publication.presentation.presentation import org.readium.r2.shared.publication.services.isRestricted import org.readium.r2.shared.publication.services.positionsByReadingOrder +import org.readium.r2.shared.util.launchWebBrowser import kotlin.math.ceil import kotlin.reflect.KClass @@ -494,13 +495,10 @@ class EpubNavigatorFragment private constructor( return true } + @OptIn(InternalReadiumApi::class) private fun openExternalLink(url: Uri) { val context = context ?: return - tryOrLog { - CustomTabsIntent.Builder() - .build() - .launchUrl(context, url) - } + launchWebBrowser(context, url) } } diff --git a/readium/shared/build.gradle b/readium/shared/build.gradle index ffc86b4bec..d166be8696 100644 --- a/readium/shared/build.gradle +++ b/readium/shared/build.gradle @@ -57,6 +57,7 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'androidx.browser:browser:1.3.0' implementation "com.github.kittinunf.fuel:fuel-android:2.2.2" implementation "com.github.kittinunf.fuel:fuel:2.2.2" implementation "com.jakewharton.timber:timber:4.7.1" diff --git a/readium/shared/src/main/java/org/readium/r2/shared/Experimental.kt b/readium/shared/src/main/java/org/readium/r2/shared/Experimental.kt deleted file mode 100644 index d5a8560177..0000000000 --- a/readium/shared/src/main/java/org/readium/r2/shared/Experimental.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Module: r2-shared-kotlin - * Developers: Mickaël Menu - * - * Copyright (c) 2020. Readium Foundation. All rights reserved. - * Use of this source code is governed by a BSD-style license which is detailed in the - * LICENSE file present in the project repository where this source code is maintained. - */ - -package org.readium.r2.shared - -@RequiresOptIn(message = "Support for PDF is still experimental. The API may be changed in the future without notice.") -@Retention(AnnotationRetention.BINARY) -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.PROPERTY) -annotation class PdfSupport - -@RequiresOptIn(message = "Support for SearchService is still experimental. The API may be changed in the future without notice.") -@Retention(AnnotationRetention.BINARY) -@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.PROPERTY) -annotation class Search diff --git a/readium/shared/src/main/java/org/readium/r2/shared/OptIn.kt b/readium/shared/src/main/java/org/readium/r2/shared/OptIn.kt new file mode 100644 index 0000000000..5f71d18437 --- /dev/null +++ b/readium/shared/src/main/java/org/readium/r2/shared/OptIn.kt @@ -0,0 +1,34 @@ +/* + * Module: r2-shared-kotlin + * Developers: Mickaël Menu + * + * Copyright (c) 2020. Readium Foundation. All rights reserved. + * Use of this source code is governed by a BSD-style license which is detailed in the + * LICENSE file present in the project repository where this source code is maintained. + */ + +package org.readium.r2.shared + +@RequiresOptIn( + level = RequiresOptIn.Level.ERROR, + message = "This is an internal API that should not be used outside of Readium modules. No compatibility guarantees are provided." +) +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.PROPERTY) +annotation class InternalReadiumApi + +@RequiresOptIn( + level = RequiresOptIn.Level.WARNING, + message = "Support for PDF is still experimental. The API may be changed in the future without notice." +) +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.PROPERTY) +annotation class PdfSupport + +@RequiresOptIn( + level = RequiresOptIn.Level.WARNING, + message = "Support for SearchService is still experimental. The API may be changed in the future without notice." +) +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.PROPERTY) +annotation class Search diff --git a/readium/shared/src/main/java/org/readium/r2/shared/util/WebLauncher.kt b/readium/shared/src/main/java/org/readium/r2/shared/util/WebLauncher.kt new file mode 100644 index 0000000000..2e761478dd --- /dev/null +++ b/readium/shared/src/main/java/org/readium/r2/shared/util/WebLauncher.kt @@ -0,0 +1,35 @@ +package org.readium.r2.shared.util + +import android.content.ActivityNotFoundException +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.webkit.URLUtil +import androidx.browser.customtabs.CustomTabsIntent +import org.readium.r2.shared.InternalReadiumApi +import org.readium.r2.shared.extensions.tryOrLog + +/** + * Opens the given [uri] with a Chrome Custom Tab or the system browser as a fallback. + */ +@InternalReadiumApi +fun launchWebBrowser(context: Context, uri: Uri) { + var url = uri + if (url.scheme == null) { + url = url.buildUpon().scheme("http").build() + } + + if (!URLUtil.isNetworkUrl(url.toString())) { + return + } + + tryOrLog { + try { + CustomTabsIntent.Builder() + .build() + .launchUrl(context, url) + } catch (e: ActivityNotFoundException) { + context.startActivity(Intent(Intent.ACTION_VIEW, url)) + } + } +} \ No newline at end of file diff --git a/test-app/README.md b/test-app/README.md deleted file mode 100644 index fcc6571303..0000000000 --- a/test-app/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Readium Mobile Test App (Kotlin/Android) - -A test app for the Kotlin implementation of Readium-2. Stable builds are [available on Google Play](https://play.google.com/apps/testing/org.readium.r2reader). - -[![BSD-3](https://img.shields.io/badge/License-BSD--3-brightgreen.svg)](https://opensource.org/licenses/BSD-3-Clause) - -All migration steps necessary in reading apps to upgrade to major versions of the Readium toolkit will be documented in the [Migration Guide](https://readium.org/mobile/kotlin/migration-guide). - -## Features - -- [x] EPUB 2.x and 3.x support -- [x] Readium LCP support -- [x] CBZ support -- [x] Custom styles -- [x] Night & sepia modes -- [x] Pagination and scrolling -- [x] Table of contents -- [x] OPDS 1.x and 2.0 support -- [x] FXL support -- [ ] RTL support - - -## Dependencies - -- [Shared Models](https://github.com/readium/r2-shared-kotlin) (Model, shared for both streamer and navigator) [![Release](https://jitpack.io/v/readium/r2-shared-kotlin.svg)](https://jitpack.io/#readium/r2-shared-kotlin) -- [Streamer](https://github.com/readium/r2-streamer-kotlin) (The parser/server) [![Release](https://jitpack.io/v/readium/r2-streamer-kotlin.svg)](https://jitpack.io/#readium/r2-streamer-kotlin) -- [Navigator](https://github.com/readium/r2-navigator-kotlin) (The bare ViewControllers for displaying parsed resources) [![Release](https://jitpack.io/v/readium/r2-navigator-kotlin.svg)](https://jitpack.io/#readium/r2-navigator-kotlin) -- [Readium CSS](https://github.com/readium/readium-css) (Handles styles, layout and user settings) - -## Install and run the testapp -[Get started with the testapp](https://github.com/readium/r2-workspace-kotlin/blob/master/README.md) - -