Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
}
}

Expand Down
1 change: 1 addition & 0 deletions readium/shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 0 additions & 20 deletions readium/shared/src/main/java/org/readium/r2/shared/Experimental.kt

This file was deleted.

34 changes: 34 additions & 0 deletions readium/shared/src/main/java/org/readium/r2/shared/OptIn.kt
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got inspired by InternalCoroutinesApi.


@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
Original file line number Diff line number Diff line change
@@ -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))
}
}
}
33 changes: 0 additions & 33 deletions test-app/README.md

This file was deleted.