Skip to content

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

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

SeniorZhai wants to merge 10 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 93db2ac in 27m 55s · 6 comments

Quality: The latest changes handle some initial page shifts, but the viewer still has selection, playback, and dismissal defects. Verification covered the current code, the DAO queries, and Android 15 window behavior in AOSP source.

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.

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

Labels

testing Now testing, but you can review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants