Skip to content

feat(media): add overlay viewer for media and avatars - #6882

Open
SeniorZhai wants to merge 13 commits into
masterfrom
feat/media-viewer-overlay
Open

SeniorZhai wants to merge 13 commits into
masterfrom
feat/media-viewer-overlay

Conversation

@SeniorZhai

Copy link
Copy Markdown
Member

No description provided.

@SeniorZhai SeniorZhai added the testing Now testing, but you can review label Nov 20, 2026
@gaotic

gaotic Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

AI review done for efaaf7f in 20m 26s · 3 comments

Quality: The follow-up improves direct opening of escaped cover URLs, but gallery eligibility and app-card action sheet cleanup still need fixes. The review used source tracing, Android framework verification, and a focused SQL reproduction.

Role Model Status
Reviewer GPT codex/gpt-6.2-sol · effort high ok
Reviewer Grok grok/grok-4.7@500k · effort medium ok
Summary codex/gpt-6.2-sol · effort medium ok

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review · Codex (Grok failed) · 7c53b48

Request changes. git diff --check and XML validation passed, and the SQLite check reproduced the paging mismatch. Kotlin compilation, Android lint, and unit tests could not start because Gradle 9.9.1 was unavailable locally and the wrapper could not resolve its download host.

conversationRepository.getMediaMessagesPagingSource(mode.conversationId, excludeLive)
},
).flow.collectLatest { pagingData ->
adapter.submitData(dialog.lifecycle, pagingData)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tapping an app card with a nested cover.url can open another message’s photo. The paging query only includes cards with cover_url, and this submission replaces the tapped item even when its ID is absent. Use the same cover rules for tapping, rendering, and paging, or keep the tapped cover in a standalone viewer when it is excluded from paging.

private val CHROME_INTERPOLATOR = PathInterpolator(0.2f, 0.88f, 0.3f, 1f)

@Volatile
private var currentOverlay: AvatarViewerOverlay? = null

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Destroying the host while an avatar is open leaves the destroyed activity and its views reachable through currentOverlay. MediaOverlayDialog dismisses itself on host destruction without calling finishDismiss(). Clear the reference and restore source visibility through a shared cleanup path that also runs on host destruction.


when (mode) {
is Mode.Conversation -> {
if (downloadMedia(position)) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Swiping from a video to an image that needs downloading leaves the image toolbar hidden. The early return skips updateTopBarForConversation, so currentIsVideo stays true and image taps cannot show the controls. Update the selected page’s toolbar state before returning to wait for the download.

onOutsideTap: () -> Unit,
): PhotoView =
PhotoView(parent.context).apply {
setOnOutsidePhotoTapListener { onOutsideTap() }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A single tap in the space around a fitted image toggles the controls twice. PhotoViewAttacher calls both the click listener and the outside-photo listener for that tap, and both toggle the toolbar and system bars. Use one tap handler for both areas and make the same change in AvatarViewerOverlay.

if (hostActivity.isFinishing || hostActivity.isDestroyed) return
hostActivity.hideKeyboard()
configureOverlayWindow()
hideFloatingIfNeeded()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Floating controls can reappear over the open viewer when the app resumes. This hides them when the dialog opens, but MixinApplication.onActivityResumed can show them again because it sees the host activity. Make the floating-window refresh honor the visible media overlay.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review · Codex (Grok failed) · 3f786d5

Request changes. Both Git diff checks and XML validation passed, and SQLite reproduced the paging mismatch. Kotlin compilation, Android lint, and unit tests could not start because the required Gradle distribution was unavailable and the installed fallback hit a sandbox socket restriction.

conversationRepository.getMediaMessagesPagingSource(mode.conversationId, excludeLive)
},
).flow.collectLatest { pagingData ->
adapter.submitData(dialog.lifecycle, pagingData)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tapping an app card with only cover.url can replace the tapped cover with another message’s photo. The overlay accepts the tapped item, but the paging query requires cover_url. In a SQLite fixture, the computed index resolved to the next photo. Use the same cover rules for rendering and paging, or keep excluded covers in a standalone viewer.

isClosing = true
binding.transitionView.clearAndHide()
initialThumb?.setSourceVisible?.invoke(true)
currentOverlay = null

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Destroying the host while the avatar viewer is open retains the activity through currentOverlay. The dialog’s lifecycle observer calls super.dismiss() and bypasses finishDismiss(), which clears the reference and restores the thumbnail. Run the same cleanup on host destruction.


when (mode) {
is Mode.Conversation -> {
if (downloadMedia(position)) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Swiping from a video to an image that needs downloading leaves the image toolbar hidden. The early return skips the toolbar update, so currentIsVideo stays true and image taps cannot reveal the controls. Update the selected page’s toolbar state before returning for the download.

onOutsideTap: () -> Unit,
): PhotoView =
PhotoView(parent.context).apply {
setOnOutsidePhotoTapListener { onOutsideTap() }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A tap in the margin around a fitted photo toggles the controls twice. PhotoViewAttacher invokes both the holder’s click listener and this outside-photo listener for the same tap. Use one handler for the whole photo view and apply the same fix in the avatar viewer.

if (hostActivity.isFinishing || hostActivity.isDestroyed) return
hostActivity.hideKeyboard()
configureOverlayWindow()
hideFloatingIfNeeded()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The floating web clip or music player can reappear over the viewer when the app resumes. This call hides them on open, but MixinApplication.onActivityResumed() refreshes them for the host activity while the dialog is still showing. Make that refresh check for a visible media overlay.

binding.lockTv.post(hideLockRunnable)

val currentId = getCurrentMessageId(position)
if (currentId != null && currentId != hiddenMessageId) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Opening a transcript photo at a nonzero index can hide its thumbnail before the transition draws. If the initial selection arrives before the opening transition’s posted callback, onPageSelected() hides the source immediately. Defer that initial visibility change until the transition takes over the thumbnail.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review · Codex (Grok failed) · f5d5145

Request changes. The incremental diff matches the incoming base changes, and the six prior findings still apply. Both Git diff checks, XML validation, and JavaScript syntax validation passed, and SQLite reproduced the paging mismatch. The pinned Gradle distribution was unavailable locally, and a sandbox socket restriction stopped the fallback before compilation, lint, or unit tests could run.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review · Grok + Codex · 1798a82

Request changes. Both Git diff checks and XML validation passed. Gradle startup was blocked by filesystem and socket restrictions, so Kotlin compilation, Android lint, unit tests, and on-device behavior remain unverified.

}
}

if (messageItem.isAppCard() && (mode.mediaSource == MediaSource.SharedMedia || !messageItem.isAppCardWithMediaCover())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tapping an app card with a space after "cover_url": can replace its cover with another message’s photo. The parsed URL passes this guard, but the DAO’s raw string filter excludes the card. In SQLite, an oldest card with spaced JSON gave index 0 and the next photo occupied that slot. Use the same eligibility rule for both the overlay and the paging query.

if (messageItem.isAppCard() && (mode.mediaSource == MediaSource.SharedMedia || !messageItem.isAppCardWithMediaCover())) {
checkOrientation()
firstLoad = false
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The standalone viewer keeps a recalled card’s cover visible and available to save or share. This return leaves the original MessageItem in the adapter, so clearing the message in the database never updates the viewer. Observe the backing message and dismiss the overlay when it is recalled or removed.


when (mode) {
is Mode.Conversation -> {
val messageItem = getConversationItem(position) ?: return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Swiping from a video onto an unloaded photo leaves the video playing outside PiP and the photo toolbar hidden. peek() returns null for the placeholder, so this return skips both updates. When paging fills the same position, the initial-page listener has already stopped handling updates and photo taps still see currentIsVideo. Stop the previous video when leaving its page and refresh the toolbar when the selected item loads.

recreate: Boolean,
) {
if (activity is MediaPagerActivity || activity is CallActivity || activity is MusicActivity || activity is WebActivity || activity is AppAuthActivity) {
if (activity is MediaPagerActivity || MediaViewerOverlay.isShowing() || activity is CallActivity || activity is MusicActivity || activity is WebActivity || activity is AppAuthActivity) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Scanning a supported trade QR code from the photo viewer opens SwapActivity while the host overlay stays open. The global isShowing() check then hides floating web clips and the music player on the trading screen too. Scope suppression to the activity that owns the overlay.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review · Codex (Grok failed) · a4d9bcb

Request changes. Both Git diff checks and XML validation passed, and an in-memory SQLite check reproduced the paging mismatch. The Gradle wrapper could not download Gradle 9.9.2, leaving Kotlin compilation, Android lint, and unit tests unverified.

}
}

if (messageItem.isAppCard() && (mode.mediaSource == MediaSource.SharedMedia || !messageItem.isAppCardWithMediaCover())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Opening the oldest app card can show the next message’s photo if the card JSON has a space after "cover_url":. The parsed cover passes this guard, but the DAO’s LIKE filter excludes the card. SQLite returned index 0 with the photo as the only paged item. Use the same cover eligibility rule in the viewer and DAO.

if (pendingPos != null && binding.viewPager.currentItem == pendingPos) {
val loaded = getConversationItem(pendingPos)
if (loaded != null) {
pendingConversationPosition = null

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A downloaded video that fills the selected placeholder can have no working playback controls until the user swipes away and back. This callback clears the pending selection before RecyclerView binds the video holder, so the player lookup can miss its view. Later binds only attach the player automatically at the initial position. Attach the player when the selected video holder binds, after checking that it is still selected.

if (item.type == MessageCategory.MESSAGE_RECALL.name || !item.isAppCard()) {
cleanupAndDismissImmediate()
}
} else if (sawMessage) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If the card is deleted between the tap and Room’s first query, the viewer keeps the cover from the chat’s in-memory item and still offers Save and Share. The first query emits null while sawMessage is false. Dismiss on the first missing-row result too.

val view = View.inflate(ContextThemeWrapper(activity, R.style.Custom), R.layout.view_drag_image_bottom, null)
val sheetBinding = ViewDragImageBottomBinding.bind(view)
builder.setCustomView(view)
val bottomSheet = builder.create()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Recalling a standalone card while its actions sheet is open leaves the sheet over the chat. Cleanup dismisses the viewer and cancels its coroutine scope, but this separate dialog remains open with Save and Share that no longer work. Keep a reference to the sheet and dismiss it during overlay cleanup.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review · GPT + Grok · 93db2ac

Request changes. Both Git diff checks and XML validation passed, and in-memory SQLite checks reproduced the paging mismatches. The Gradle wrapper could not download Gradle 9.9.2, so Kotlin compilation, Android lint, and the bottom-sheet unit test remain unverified.

snapshot.indexOfFirst { it?.messageId == mode.messageId }
}
if (targetIndex < 0) {
if (itemAtIndex == null) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Opening the newest app card can show an older photo, and opening it as the only media item can leave the viewer blank. Gson accepts a space after "cover_url":, but the DAO filter excludes that card. SQLite returned an initial index of 1 for a one-photo gallery and an empty page for a card-only gallery, so both cases skip recovery. Use the same cover eligibility rule for the viewer and DAO.

}
firstLoad = false
mode.initialItem?.let { initialItem ->
dataJob?.cancel()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Deleting an earlier media message during startup can turn the gallery into a single-item viewer. In SQLite, the tapped item moved from index 3 to 2 while Room's refresh still started at 3. The fallback then cancels paging and submits the cached item alone. It can also restore the cached item after the item itself is recalled. Recheck the tapped ID, retry paging at its current index if it still exists, and dismiss if it was recalled or deleted.

if (pendingPos != null && binding.viewPager.currentItem == pendingPos) {
val loaded = getConversationItem(pendingPos)
if (loaded != null) {
pendingConversationPosition = null

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Swiping to a placeholder that resolves to an already-downloaded video can leave its playback controls inactive until the user swipes away and back. This clears the pending selection before RecyclerView has to bind the video holder, so the player lookup can miss it. Later binds only attach the player at initialPos. Attach the player when the selected video holder binds and verify it is still selected.

if (item.type == MessageCategory.MESSAGE_RECALL.name || !item.isAppCard()) {
cleanupAndDismissImmediate()
}
} else if (sawMessage) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If a standalone card is deleted before Room's first query, the viewer keeps the in-memory cover and still offers Save and Share. The observer receives null while sawMessage is false, so it skips dismissal. Dismiss on the first missing-row result too.

bottomSheet.dismiss()
}
sheetBinding.cancel.setOnClickListener { bottomSheet.dismiss() }
bottomSheet.show()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Recalling a standalone card while its actions sheet is open leaves the sheet over the chat. The sheet is a separate dialog stored only in a local variable, and overlay cleanup cancels the scope used by Save and Share before dismissing the viewer. Keep a reference to the actions sheet and dismiss it during overlay cleanup.

val bottomNavInset =
if (lastInsets != null) {
val compatInsets = WindowInsetsCompat.toWindowInsetsCompat(lastInsets, container)
val navBottom = compatInsets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On Android 15 with gesture navigation, the portrait floating dialog can be fitted above the navigation bar. In that case the container gets a zero bottom navigation inset and the new fill never draws behind the gesture handle. The test injects full-window bounds and positive insets directly into the container, bypassing the window layout. Configure the portrait dialog window to extend into the navigation area so the sheet can draw there.

…verlay

# Conflicts:
#	app/src/main/java/one/mixin/android/ui/common/GroupBottomSheetDialogFragment.kt

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review · GPT + Grok · c8b74ec

Request changes. The post-review merge fixes compact-window handling in the existing pagers but leaves equivalent defects in the new overlay, along with the previously identified paging, deletion, player-binding, action-sheet, and bottom-inset issues. git diff --check passed and the relevant SQL and lifecycle paths were inspected, while Gradle verification remained blocked by the unavailable wrapper download.


app/src/main/java/one/mixin/android/ui/media/pager/overlay/MediaViewerOverlay.kt:1103

The overlay still requests an activity orientation in multi-window and on non-compact large-screen windows. MediaPagerActivity and TranscriptMediaPagerActivity now return from this path when isInMultiWindowMode or !isCompactWindow(), but this overlay does not, so opening it can force a split/foldable host orientation and later restore that request. Apply the same window guards before setting orientationModified or requestedOrientation.


app/src/main/java/one/mixin/android/ui/media/pager/overlay/MediaViewerOverlay.kt:1677

This overlay still clamps the PiP target against activity.realSize().y. In landscape, the regular pagers now use windowHeight() because the display size can exceed a short split/freeform window, while this path can animate to a target wider than the host window. Use the current window height for the landscape clamp.


app/src/main/java/one/mixin/android/db/MessageDao.kt:64

The DAO only recognizes an app-card cover when the JSON has no whitespace before the URL value. Gson-backed isAppCardWithMediaCover() accepts content such as {"cover_url": "https://..."}, so the overlay takes the paged-media path while every DAO query omits that card. This makes the initial index point at the wrong item or produces an empty page for a card-only gallery. Use the same whitespace-tolerant cover eligibility rule in all media queries.


app/src/main/java/one/mixin/android/ui/media/pager/overlay/MediaViewerOverlay.kt:514

When the tapped row moves or disappears between indexMediaMessages() and the first Paging snapshot, this branch returns for a null itemAtIndex and otherwise falls back to submitting only the cached initialItem. A deleted earlier row can therefore collapse the gallery to one item, and a recalled tapped row can be restored from stale memory with Save/Share still available. Re-query the tapped ID, retry using its current index when it still exists, and dismiss when it has been recalled or deleted.


app/src/main/java/one/mixin/android/ui/media/pager/overlay/MediaViewerOverlay.kt:1261

If a swipe lands on a placeholder that resolves to an already-downloaded video, loadConversationVideoMessage() can run before RecyclerView binds the holder and returns because the tagged container is absent. The later bind only assigns the player when position == initialPos, which is the originally opened item, so the selected video has inactive controls until it is rebound. Attach the player from the selected-video bind path, checking that the holder is still the current selection.


app/src/main/java/one/mixin/android/ui/media/pager/overlay/MediaViewerOverlay.kt:723

A standalone app card deleted before the first Room emission leaves the overlay open because the initial null result is ignored while sawMessage is false. The in-memory cover remains available for Save and Share. Dismiss on the first missing-row result, while still dismissing when a previously observed row disappears.


app/src/main/java/one/mixin/android/ui/media/pager/overlay/MediaViewerOverlay.kt:1332

The actions sheet is a separate dialog held only in this local variable, and cleanupAndDismissImmediate() never dismisses it. If the card is recalled while its image or video actions sheet is visible, cleanup dismisses the overlay but leaves the sheet over the conversation. Keep the active sheet reference on the overlay and dismiss it during cleanup.


app/src/main/java/one/mixin/android/widget/BottomSheet.kt:330

The new fill height is still zero for the portrait floating dialog on gesture-navigation devices because TransparentDialog uses windowIsFloating=true and only the phone-landscape path opts into LAYOUT_HIDE_NAVIGATION. The window is laid out above the navigation area, so navBottom is zero and setBottomBarFill() cannot draw behind the gesture handle. Configure the portrait dialog window to extend into the navigation area before relying on this inset fill.

- Increase unit test worker maxHeapSize to 2g to prevent Robolectric OOM
- Guard overlay orientation changes in multi-window/non-compact mode and use windowHeight() for landscape PiP
- Normalize JSON whitespace in MessageDao app-card cover queries
- Re-query moved/deleted items on initial paging mismatch, bind video player when selected holder binds, dismiss on initial null standalone row, and track/dismiss active action BottomSheet
- Make portrait TransparentDialog BottomSheet non-floating and edge-to-edge behind the navigation bar
@SeniorZhai SeniorZhai removed the testing Now testing, but you can review label Nov 25, 2026

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review · GPT (Grok failed) · ef7fb5b

Request changes. Both diff whitespace checks passed, and a focused SQLite/Gson check reproduced the cover eligibility mismatch. The targeted Android unit tests could not run because the Gradle wrapper download failed and the offline fallback could not resolve the Foojay plugin.

}
bottomSheet.dismiss()
}
sheetBinding.shareImage.setOnClickListener {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Recalling a gallery app card while its action sheet is open still leaves Save and Share usable. Paging removes the recalled row, but the recall observer only covers standalone cards, and these handlers retain the original cover URL. Observe the sheet’s message ID and dismiss the sheet when the row is recalled or deleted. Revalidate the row before resolving the cover for Save or Share.

private const val NORMALIZED_CONTENT = "REPLACE(REPLACE(REPLACE(REPLACE(content, ' ', ''), char(9), ''), char(10), ''), char(13), '')"
private const val NORMALIZED_CONTENT_ALIAS = "REPLACE(REPLACE(REPLACE(REPLACE(m.content, ' ', ''), char(9), ''), char(10), ''), char(13), '')"
private const val APP_CARD_COVER_MEDIA = "category = 'APP_CARD' AND $NORMALIZED_CONTENT LIKE '%\"cover_url\":\"%' AND $NORMALIZED_CONTENT NOT LIKE '%\"cover_url\":\"\"%'"
private const val APP_CARD_COVER_MEDIA_ALIAS = "m.category = 'APP_CARD' AND $NORMALIZED_CONTENT_ALIAS LIKE '%\"cover_url\":\"%' AND $NORMALIZED_CONTENT_ALIAS NOT LIKE '%\"cover_url\":\"\"%'"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The SQL still disagrees with Gson on cover eligibility. Both predicates admit {"cover_url": "\t\n"} as a gallery page even though Gson decodes the value as blank. They also skip "cover\u005furl", which Gson decodes as cover_url, so opening that valid cover now dismisses the viewer on the retry lookup. Use the same parsed, nonblank top-level cover rule for paging, indexing, and lookup.


@Synchronized
private fun changeOrientation(orientation: Int) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O || activity.isInMultiWindowMode || !activity.isCompactWindow()) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The fullscreen button now does nothing in split-screen and non-compact windows. Both conversation and transcript video holders leave it visible and route clicks here, where the guard returns before doing anything. Hide the control under the same conditions or make it expand the video within the current window.

…ingle image

Dismiss the gallery image action sheet when its app card is recalled or deleted, and fall back to the standalone viewer when SQL cover matching misses a cover that Gson decodes.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI review · GPT + Grok · efaaf7f

Request changes. Both diff whitespace checks passed, and a focused SQLite/Gson check reproduced the cover eligibility mismatch. The targeted Android unit tests were blocked by the Gradle distribution download and the offline Foojay plugin resolution.

sheetBinding.showInChat.setOnClickListener {
showInChat(bottomSheet, item.messageId)
}
sheetBinding.save.setOnClickListener {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Save and Share can still export a recalled or deleted app-card cover. The observer starts an exit animation that leaves the buttons active, and both handlers use the captured item. Save can also resume with that item after a storage permission prompt. Disable the actions when the row becomes invalid and fetch the current row before resolving the cover, including after permission is granted.

bottomSheet.dismiss()
}
}
source.observeForever(observer)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The observeForever subscription can outlive the host activity. Host teardown starts an animated dismiss, but Android can detach the sheet window before the animation posts the actual dismiss to its view. That post can stay queued, so OnDismissListener never removes the observer. Bind the observer to the overlay lifecycle and remove it on ordinary sheet dismissal as well.

private const val NORMALIZED_CONTENT = "REPLACE(REPLACE(REPLACE(REPLACE(content, ' ', ''), char(9), ''), char(10), ''), char(13), '')"
private const val NORMALIZED_CONTENT_ALIAS = "REPLACE(REPLACE(REPLACE(REPLACE(m.content, ' ', ''), char(9), ''), char(10), ''), char(13), '')"
private const val APP_CARD_COVER_MEDIA = "category = 'APP_CARD' AND $NORMALIZED_CONTENT LIKE '%\"cover_url\":\"%' AND $NORMALIZED_CONTENT NOT LIKE '%\"cover_url\":\"\"%'"
private const val APP_CARD_COVER_MEDIA_ALIAS = "m.category = 'APP_CARD' AND $NORMALIZED_CONTENT_ALIAS LIKE '%\"cover_url\":\"%' AND $NORMALIZED_CONTENT_ALIAS NOT LIKE '%\"cover_url\":\"\"%'"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The normalized predicate now includes cards with a value like {"cover_url" : "\t\n"} in the gallery and its counts. Both SQL predicates accepted that row in SQLite, while Gson decoded the cover as blank. Use the same parsed, nonblank top-level cover_url rule for paging, indexing, and lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants