Skip to content
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

Media navigation with swipe gesture #4161

Merged
merged 38 commits into from
Jan 23, 2025
Merged

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Jan 17, 2025

Content

Add ability to swipe between media (images and videos) and files (files, audio and voice message) when navigating from the gallery.

Note: for now, when opening a media from the room, swipe is not supported. This support will come later.

Motivation and context

Closes #4174
Related to #1484

Screenshots / GIFs

SwipeMedia.mp4

Tests

  • Open a room and navigate to settings/Media and files
  • Open an image
  • Swipe left and right
  • press back
  • open the files tab
  • open a file
  • Swipe left and right

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

Copy link
Contributor

github-actions bot commented Jan 17, 2025

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/9Xh75M

@bmarty bmarty added PR-Feature For a new feature Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. labels Jan 20, 2025
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jan 22, 2025
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to myself: why the caption has vanished here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 4f4c994

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 91.27273% with 48 lines in your changes missing coverage. Please review.

Project coverage is 83.35%. Comparing base (e4768a8) to head (da22758).
Report is 44 commits behind head on develop.

Files with missing lines Patch % Lines
...braries/mediaviewer/impl/viewer/MediaViewerView.kt 91.33% 7 Missing and 4 partials ⚠️
...l/timeline/model/event/TimelineItemEventContent.kt 0.00% 5 Missing ⚠️
...aries/mediaviewer/impl/gallery/MediaGalleryView.kt 75.00% 3 Missing and 2 partials ⚠️
...diaviewer/impl/viewer/MediaViewerFlickToDismiss.kt 88.09% 2 Missing and 3 partials ⚠️
...aries/mediaviewer/impl/gallery/EventItemFactory.kt 50.00% 0 Missing and 4 partials ⚠️
...s/mediaviewer/impl/viewer/MediaViewerDataSource.kt 96.29% 2 Missing and 1 partial ⚠️
...s/mediaviewer/impl/DefaultMediaViewerEntryPoint.kt 0.00% 2 Missing ⚠️
...aries/mediaviewer/impl/gallery/ui/VoiceItemView.kt 0.00% 0 Missing and 2 partials ⚠️
...ies/mediaviewer/impl/local/audio/MediaAudioView.kt 60.00% 2 Missing ⚠️
...ies/mediaviewer/impl/local/video/MediaVideoView.kt 50.00% 2 Missing ⚠️
... and 6 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4161      +/-   ##
===========================================
+ Coverage    83.31%   83.35%   +0.03%     
===========================================
  Files         1881     1886       +5     
  Lines        49101    49403     +302     
  Branches      5769     5804      +35     
===========================================
+ Hits         40910    41180     +270     
- Misses        6116     6134      +18     
- Partials      2075     2089      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bmarty bmarty added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jan 22, 2025
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jan 22, 2025
@bmarty bmarty added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jan 22, 2025
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jan 22, 2025
@bmarty bmarty force-pushed the feature/bma/mediaNavigation branch from 1d87a2b to 74be5a5 Compare January 22, 2025 15:25
@bmarty bmarty changed the title WIP media navigation with swipe Media navigation with swipe gesture Jan 23, 2025
@bmarty bmarty marked this pull request as ready for review January 23, 2025 09:54
@bmarty bmarty requested a review from a team as a code owner January 23, 2025 09:54
@bmarty bmarty requested review from ganfra and removed request for a team January 23, 2025 09:54
Copy link
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

There are a few nits that you can decide to change or not and some more docs in the new classes/methods would be nice, but mainly I think we need to fix backpagination with either the fix discussed privately or something similar, otherwise the gallery seems to get stuck.

}
HorizontalPager(
state = pagerState,
modifier = Modifier,
Copy link
Member

Choose a reason for hiding this comment

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

This is probably not needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, removed.

Comment on lines 44 to 48
fun start() {
if (!isStarted.compareAndSet(false, true)) {
return
}
flow {
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a way to stop this flow, i.e. when the user leaves the gallery screen? Or is it ok if the gallery keeps loading in bg while the user is checking the room?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no way so far, but the flow will complete when the room will be destroyed.
The idea is to share the flow between the gallery and the media viewer with swipe. This will have to be reworked a bit when we will open the viewer from the timeline.

Comment on lines 293 to 294
.takeIf { it != -1 }
?: 0
Copy link
Member

Choose a reason for hiding this comment

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

I think this could be .coerceAtLeast(0).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, done

Comment on lines 128 to 130
onDismiss = {
onBackClick()
},
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this can probably be just onDismiss = onBackClick,. Same below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, done

Comment on lines 72 to 73
.takeIf { it != -1 }
?: 0
Copy link
Member

Choose a reason for hiding this comment

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

coerceAtLeast(0) here too?

@@ -115,7 +115,7 @@ private fun VoiceInfoRow(
}
Spacer(Modifier.width(8.dp))
Text(
text = if (state.progress > 0f) state.time else voice.duration ?: state.time,
text = if (state.progress > 0f) state.time else voice.mediaInfo.duration ?: state.time,
Copy link
Member

Choose a reason for hiding this comment

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

voice.mediaInfo.duration?.takeIf { state.progress > 0f } ?: state.time maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

The correct alternative would be
voice.mediaInfo.duration?.takeIf { state.progress == 0f } ?: state.time
and I prefer not compare float using equality.

Comment on lines 210 to 211
.takeIf { it != -1 }
?: 0
Copy link
Member

Choose a reason for hiding this comment

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

I keep writing the coerceAtLeast(0) suggestion and the function keeps moving 😅 .

Comment on lines 130 to 132
onDismiss = {
onBackClick()
},
Copy link
Member

Choose a reason for hiding this comment

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

This can probably be inlined as some other previous cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

👌

Comment on lines 203 to 205
loadingItem?.let { item ->
LaunchedEffect(item.timestamp) {
state.eventSink(MediaGalleryEvents.LoadMore(item.direction))
Copy link
Member

Choose a reason for hiding this comment

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

Nit: if (loadingItem != null) and use loadingItem inside maybe? It's easier to step the debugger this way.

@bmarty bmarty added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jan 23, 2025
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jan 23, 2025
@bmarty
Copy link
Member Author

bmarty commented Jan 23, 2025

Thanks for the review @jmartinesp . I (think I) have fixed all the remarks except the main one. I am working on it while the CI is recording the screenshots. I want to add unit test on this part.

@bmarty
Copy link
Member Author

bmarty commented Jan 23, 2025

@jmartinesp I have fixed the pagination issue and covered it by a unit test in da22758

Let me know if it's OK for you!

Copy link
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the previous nits, with the back pagination issue fixed it should be good to merge!

@bmarty bmarty merged commit 3668e86 into develop Jan 23, 2025
28 checks passed
@bmarty bmarty deleted the feature/bma/mediaNavigation branch January 23, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Feature For a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] Attachment viewer: navigation by swiping left and right
4 participants