summaryrefslogtreecommitdiff
path: root/app/src/main/java/org/terst/feedreader/ui/ReaderWebView.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/terst/feedreader/ui/ReaderWebView.kt')
-rw-r--r--app/src/main/java/org/terst/feedreader/ui/ReaderWebView.kt32
1 files changed, 30 insertions, 2 deletions
diff --git a/app/src/main/java/org/terst/feedreader/ui/ReaderWebView.kt b/app/src/main/java/org/terst/feedreader/ui/ReaderWebView.kt
index f1400d3..78020a9 100644
--- a/app/src/main/java/org/terst/feedreader/ui/ReaderWebView.kt
+++ b/app/src/main/java/org/terst/feedreader/ui/ReaderWebView.kt
@@ -74,6 +74,11 @@ private fun extractYouTubeVideoId(uri: Uri): String? {
* WebView's own default long-press behavior (a native "open/copy link" popup) --
* callers show their own save/share/open action menu instead.
*
+ * onOpenYouTubeExternally fires for a LONG-press on a YouTube link, with the watch URL, instead
+ * of the ordinary onLongPressLink actions menu -- callers hand it to the system, which is the
+ * YouTube app on a phone that has one. A tap plays the video in the reader; a long-press is how
+ * you say you wanted it somewhere else.
+ *
* onYouTubeVideo fires for a tap on a YouTube watch link (what ReaderExtractor turns
* an embedded video into a thumbnail link to) with just the video ID, instead of the
* old behavior of handing off to the YouTube app/browser -- callers show an in-app
@@ -124,6 +129,7 @@ private fun extractYouTubeVideoId(uri: Uri): String? {
data class ReaderWebViewCallbacks(
val onOpenLink: (String) -> Unit,
val onLongPressLink: (String) -> Unit = {},
+ val onOpenYouTubeExternally: (String) -> Unit = {},
val onYouTubeVideo: (String) -> Unit = {},
val onImageTap: (String) -> Unit = {},
val onScrollChanged: (Int) -> Unit = {},
@@ -245,7 +251,19 @@ fun newReaderWebView(context: Context, callbacks: ReaderWebViewCallbacks): Reade
// Every article image now sits inside a zoom link, so a long-press on one
// reports that link's internal scheme -- strip it back to the image's own URL
// so the actions menu shows, and acts on, something real.
- callbacks.onLongPressLink(withoutImageZoomScheme(url))
+ val target = withoutImageZoomScheme(url)
+ // A long-press on a video reports the thumbnail's URL rather than the link's --
+ // see youTubeTargetForLongPress, which resolves it back to the video. Straight
+ // out to whatever handles YouTube on the phone, usually the app: a tap already
+ // plays the video in the reader, so the only thing a long-press can usefully
+ // mean is "not in here, out there", and picking that off a menu would be a menu
+ // with one useful item.
+ val video = youTubeTargetForLongPress(target)
+ if (video != null) {
+ callbacks.onOpenYouTubeExternally(video)
+ } else {
+ callbacks.onLongPressLink(target)
+ }
true
} else {
false
@@ -380,7 +398,17 @@ fun YouTubePlayerDialog(videoId: String, onDismiss: () -> Unit) {
}
}
webChromeClient = WebChromeClient()
- loadUrl("https://www.youtube-nocookie.com/embed/$videoId?autoplay=1&playsinline=1")
+ // A host page with the embed in an iframe, not the embed itself as the
+ // top-level document. YouTube answers a top-level embed with "Video player
+ // configuration error -- Error 153", which is the reported "YouTube play is
+ // misconfigured"; framed, the same URL plays. See YouTubeLinks.
+ loadDataWithBaseURL(
+ YOUTUBE_EMBED_BASE_URL,
+ youTubeEmbedPageHtml(videoId),
+ "text/html",
+ "utf-8",
+ null
+ )
}
},
onRelease = { it.destroy() }