-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Scope Reader photo viewer swiping to gallery images #22762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
98 commits
Select commit
Hold shift + click to select a range
8772fc4
Start reader improvements feature branch
nbradbury 0fe604f
Remove content-scanning fallbacks for Reader featured image
nbradbury ff77238
Move featured image above title and excerpt in Reader post cards
nbradbury 5265ae1
Fix grammar in code comments
nbradbury 89c4227
Merge remote-tracking branch 'origin/trunk' into issue/reader-feature…
nbradbury 1269c94
Fit portrait featured images in Reader instead of cropping
nbradbury e15f7a2
Fix import ordering in ReaderPostNewViewHolder
nbradbury 8bcb7ba
Merge remote-tracking branch 'origin/trunk' into issue/reader-portrai…
nbradbury 63fc925
Fix import ordering and remove unnecessary @JvmOverloads in ImageManager
nbradbury 22cedba
Merge remote-tracking branch 'origin/trunk' into issue/reader-portrai…
nbradbury bdd5c62
Redesign Reader post detail header for adaptive layout
nbradbury e709ea7
Simplify Reader post detail header and image transformation code
nbradbury db6cd2c
Fix crash in Reader post detail caused by unresolvable Material3 attr…
nbradbury a1eeb7f
Simplify Reader post detail: remove dead code and redundant scroll li…
nbradbury 17a6afc
Use fastStripHtml for reading time and fix code quality issues
nbradbury 7914ed7
Fix blog section spacing between avatar and text
nbradbury ebc1c46
Merge remote-tracking branch 'origin/trunk' into feature/CMM-2002-ada…
nbradbury 80c7aa0
Hide author name when blank or same as blog name
nbradbury b334c3c
Show blog description instead of post excerpt in detail header
nbradbury 4a2692a
Reorder Reader post detail header layout
nbradbury 6892a72
Fix blog section layout spacing and alignment
nbradbury 07aa8f8
Make subscribe button smaller and place it after blog name
nbradbury 4691444
Fix featured image duplication after returning from comments
nbradbury 94841fc
Simplify Reader post detail header code
nbradbury bcc4958
Fix detekt LongMethod violation in mapPostToUiState
nbradbury 6cd6f18
Fix review issues: cache date formatter, move DB query off main threa…
nbradbury 8a92cc8
Remove unused bg_rectangle_black_translucent_40 drawable
nbradbury c4b421c
Simplify Reader post detail header code
nbradbury 19c9a5c
Fix detekt ReturnCount violation in buildReadingTime
nbradbury c3ad66f
Minor vm tweaks
nbradbury cc70a3e
Fix review issues: threading, thread safety, and data class cleanup
nbradbury af962f1
Fix detekt ReturnCount violation in buildReadingTime
nbradbury 5e98ed9
Add "View original" button to Reader post detail header
nbradbury a3aee37
Move tags from post detail header to below post content
nbradbury 4f5298a
Move likes/comments counts from header to below tags
nbradbury 5df00c6
Remove comment count from interaction section below post content
nbradbury 0178074
Fix featured image flickering in Reader post detail
nbradbury 787a0fa
Remove time from publication date in Reader post detail
nbradbury 013e033
Change "Visit site" to "View site" and open site in Reader
nbradbury 0b170de
Show liker avatars inline before like count in Reader post detail
nbradbury 87c62ef
Fetch liker data on initial post load for inline avatars
nbradbury 61fa8e5
Remove inline avatar ImageViews, keep existing faces train
nbradbury 1b88841
Remove duplicate like count text, use faces train only
nbradbury 20a22fd
Restyle Subscribe button as unfilled pill in post detail header
nbradbury 00a98b0
Remove unused ReaderImageScanner.getLargestImage()
nbradbury 7cbc42b
Fix Subscribe pill clipping and soften border color
nbradbury 5a6551e
Remove redundant tagItemsVisibility and showViewOriginal fields
nbradbury 95b090d
Fix detekt and lint issues: unused imports, long method, unused drawable
nbradbury 2739cf0
Show post excerpt instead of blog description in post detail header
nbradbury 50a0d3d
Add thin divider below the post excerpt in detail header
nbradbury a31d8ed
Remove dead code and simplify Reader post detail branch
nbradbury d9ab107
Remove dead LikesClicked/CommentsClicked header actions and redundant…
nbradbury b0f8e7e
Fix detekt and lint issues: ReturnCount, TrimLambda, missing null ann…
nbradbury 8696081
Always show header divider and darken excerpt text and divider color
nbradbury 1792af8
Simplify title builder and move divider visibility to XML
nbradbury f17f4cf
Improve auto-generated excerpt detection with suffix check and whites…
nbradbury fdf27a8
Add KDoc comments to mapPostToUiState and buildExcerpt
nbradbury 4a2a4e0
Fix detekt ReturnCount in isAutoGeneratedExcerpt
nbradbury c0a7f28
Fix flaky likers test by skipping onShowPost during init
nbradbury 6d8c367
Address PR review feedback for post detail header
nbradbury c0e7831
Fix review feedback: tighter title, softer divider, simpler author card
nbradbury 42c66c5
Fix divider color to match iOS and restore title lineHeight
nbradbury 2eb76c8
Reduce post title line spacing and fix icon vertical alignment
nbradbury e68db5d
Fix detekt ReturnCount in buildAuthorClicked
nbradbury 4bd5814
Removed lineSpacingMultiplier
nbradbury e4ec8fd
Extract author profile bottom sheet to Fragment with XML layout
nbradbury b994bce
Merge trunk into feature/CMM-2002-adaptive-post-details
nbradbury 9755c64
Cancel pending excerpt truncation check before posting new one
nbradbury bb0e2ac
Fix Visit/View site string resources for correct scoping
nbradbury bb6263e
Fix review issues: Paint thread safety, data class lambdas, View Binding
nbradbury ec5c674
Simplify bottom sheet R import and ViewModel null handling
nbradbury 62b9e05
Fix tiny text in author profile bottom sheet
nbradbury c85a766
Migrate ReaderAuthorProfileBottomSheet to Compose
nbradbury ca6dd8c
Revert Compose migration for author profile bottom sheet
nbradbury 4b91df6
Fix review issues: consistent feature gating, divider, crash safety
nbradbury 828bf2c
Fix "(Untitled)" blog name in post list and post detail
nbradbury a96476c
Fix "(Untitled)" blog name in post list and post detail, p2
nbradbury 16cafc1
Simplify author row linking and fix View original alignment
nbradbury 2839b84
Changed "View site" to "View original"
nbradbury 62b2a06
Make sure author profile shows a url when blog name is missing
nbradbury d625742
Use filled Subscribe button
nbradbury ad65b53
Fixed image resize
nbradbury 931e177
Fall back to "featured_image" for FP posts
nbradbury 3ce01cd
Reverted adjustViewBounds change
nbradbury 6be1f42
Align Reader post list horizontal margins with post detail
nbradbury cf5618a
Merge branch 'feature/CMM-2002-adaptive-post-details' into issue/CMM-…
nbradbury 4ac8b9b
Merge remote-tracking branch 'origin/trunk' into issue/CMM-1997-reade…
nbradbury edf8982
Scope Reader photo viewer swiping to gallery images
nbradbury 5c953ce
Fix gallery detection for WordPress-resized image URLs
nbradbury 3aefd40
Fix duplicate gallery image and anchor-wrapped image handling
nbradbury 28ce716
Fix image detection for non-standard formats like .bmp
nbradbury 60b43bd
Merge remote-tracking branch 'origin/trunk' into issue/CMM-1994-reade…
nbradbury 8efe641
Consolidate showReaderPhotoViewer overloads and remove unused suppress
nbradbury 8dbcdd4
Fix import ordering and add clarifying comments
nbradbury 691e57d
Fix detekt and checkstyle issues in gallery code
nbradbury be0cf43
Simplify gallery detection JS using Element.closest()
nbradbury 81542a6
Extract gallery detection logic into ReaderGalleryDetector
nbradbury 1dd9698
Add KDoc to buildDetectionJs and parseResult
nbradbury File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
110 changes: 110 additions & 0 deletions
110
WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderGalleryDetector.kt
This file contains hidden or 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,110 @@ | ||
| package org.wordpress.android.ui.reader | ||
|
|
||
| import android.webkit.WebView | ||
| import org.json.JSONArray | ||
| import org.json.JSONException | ||
| import org.wordpress.android.util.AppLog | ||
| import org.wordpress.android.util.AppLog.T | ||
|
|
||
| /** | ||
| * Detects whether a tapped image belongs to a gallery in a Reader | ||
| * post WebView, and returns the gallery's image URLs if so. | ||
| */ | ||
| class ReaderGalleryDetector { | ||
| /** | ||
| * Evaluates JS in [webView] to determine whether the image at | ||
| * [imageUrl] is inside a gallery. Calls [callback] with the | ||
| * gallery's image URLs, or null if the image is not in a gallery. | ||
| */ | ||
| fun detectGallery( | ||
| webView: WebView, | ||
| imageUrl: String, | ||
| callback: (ArrayList<String>?) -> Unit | ||
| ) { | ||
| val js = buildDetectionJs(imageUrl) | ||
| webView.evaluateJavascript(js) { result -> | ||
| callback(parseResult(result)) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Builds a JavaScript snippet that finds the tapped image in the | ||
| * DOM by matching its URL pathname, walks up to the nearest | ||
| * gallery container, and returns a JSON array of all image URLs | ||
| * in that gallery. The [imageUrl] is escaped to prevent | ||
| * injection before being interpolated into the script. | ||
| */ | ||
| private fun buildDetectionJs(imageUrl: String): String { | ||
| val safeUrl = imageUrl | ||
| .replace("\\", "\\\\") | ||
| .replace("'", "\\'") | ||
| .replace("\n", "") | ||
| .replace("\r", "") | ||
| return """ | ||
| (function() { | ||
| try { | ||
| var tp = new URL('$safeUrl').pathname; | ||
| var strip = function(p) { | ||
| return p.replace(/-\d+x\d+(\.[^.]+)${'$'}/, '${'$'}1'); | ||
| }; | ||
| var sel = '.wp-block-gallery,.tiled-gallery,' | ||
| + '.gallery,.blocks-gallery-grid'; | ||
| var imgs = document.querySelectorAll('img'); | ||
| for (var i = 0; i < imgs.length; i++) { | ||
| try { | ||
| var p = new URL(imgs[i].src).pathname; | ||
| if (p === tp || strip(p) === strip(tp)) { | ||
| var g = imgs[i].closest(sel); | ||
| if (!g) return null; | ||
| var urls = []; | ||
| var gi = g.querySelectorAll('img'); | ||
| for (var j = 0; j < gi.length; j++) { | ||
| if (gi[j].src | ||
| && gi[j].src.startsWith('http')) | ||
| urls.push(gi[j].src); | ||
| } | ||
| return JSON.stringify(urls); | ||
| } | ||
| } catch(e) {} | ||
| } | ||
| return null; | ||
| } catch(e) { return null; } | ||
| })() | ||
| """.trimIndent() | ||
| } | ||
|
|
||
| /** | ||
| * Parses the JSON string [result] returned by the gallery | ||
| * detection JavaScript. Returns the list of image URLs when | ||
| * the gallery contains more than one image, or null if the | ||
| * result is empty, not valid JSON, or a single-image gallery. | ||
| */ | ||
| private fun parseResult(result: String?): ArrayList<String>? { | ||
| if (result.isNullOrEmpty() || result == "null") return null | ||
| return try { | ||
| val json = if (result.startsWith("\"") && result.endsWith("\"")) { | ||
| result | ||
| .substring(1, result.length - 1) | ||
| .replace("\\\"", "\"") | ||
| .replace("\\\\", "\\") | ||
| } else { | ||
| result | ||
| } | ||
| val array = JSONArray(json) | ||
| // Single-image galleries fall back to all-images behavior | ||
| // so the viewer shows more context rather than a lone image. | ||
| if (array.length() <= 1) { | ||
| null | ||
| } else { | ||
| val urls = ArrayList<String>(array.length()) | ||
| for (i in 0 until array.length()) { | ||
| urls.add(array.getString(i)) | ||
| } | ||
| urls | ||
| } | ||
| } catch (e: JSONException) { | ||
| AppLog.e(T.READER, "Failed to parse gallery URLs: $e") | ||
| null | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / Android Lint
Nullable/NonNull annotation missing on field Note