summaryrefslogtreecommitdiff
path: root/app/src/main/java/org/terst/feedreader/ui/ReaderWebView.kt
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-10-21 19:07:17 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-10-21 19:07:17 +0000
commit9210bf463a8818595f7ca42486a787d4f1941d55 (patch)
tree3a38cf5d71a20393a33eef5a19b1a97554055e75 /app/src/main/java/org/terst/feedreader/ui/ReaderWebView.kt
parente50f4fbbca21b85648f6c4045cbd50f672d315cd (diff)
Fix stray promo headers, site-URL subscribing, and YouTube playback
Three reported bugs. **"West Hawaii today articles get a bunch of stray Trending headers."** The publisher's widget platform injects promo blocks between the real paragraphs, inside the article's own container, so every structural signal tells Readability they belong. What survives is a heading labelling nothing, because the links under it are filled in by a script that never runs in the reader. Confirmed on 9 of the 12 articles in that feed, two each. Blocks marked `data-mrf-recirculation` are now removed -- the attribute says what the block is for in the widget platform's own words, which is a better signal than the word "Trending", since an article may legitimately discuss what is trending. Nothing longer than a label and a few headlines is ever removed. Also applied to already-cached articles, in place rather than by discarding them: the article was fine, only the litter has to go. **"Can't subscribe to heathercoxrichardson.substack.com."** Adding a feed handed whatever URL it was given straight to the XML parser, so a site's home page -- the only URL a reader can actually see and copy -- failed on the root element. That page advertises its feed the way sites have since 2002, in a <link rel="alternate"> in the head. It is now read, resolved against the page, and fetched. Only what the page declares: guessing /feed and /rss would add a burst of 404s to every failed add and eventually subscribe somebody to the wrong thing. **"YouTube play is misconfigured."** It was, and YouTube said so: the player dialog loaded the embed as its own top-level document, which answers with "Video player configuration error -- Error 153". An embed has to be embedded. It now sits in an iframe on a minimal host page. Measured in the app's own WebView: top-level, no requests for the video stream and the error on screen; framed, the stream loads and there is no error. **"Long click on YouTube placeholder should open the URL directly."** It does now. Worth recording why this is not simply the link's href: for an image inside a link, WebView's hit test reports the image's URL, so a long-press on the thumbnail arrives as the i.ytimg.com JPEG. The video id is resolved out of that. Verified on a device for all four: the Substack site URL adds "Letters from an American" and fetches 20 articles; a West Hawaii Today article extracts with no Trending headers and its body intact; the video plays; and a long-press reaches the YouTube app. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018AwnALZL6bD4VBtATDVv3B
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() }