element-x-android icon indicating copy to clipboard operation
element-x-android copied to clipboard

Tapping user mxid or room alias copies it to the clipboard

Open frebib opened this issue 1 year ago • 7 comments

Content

Make user id and room alias text in room/user view pages clickable and copy the text to the clipboard on click.

One small issue with this implementation is the snackbars don't appear until the view is closed.. not sure why, because I copy-pasted some other code that does the same thing and it works fine. Coroutines in Kotlin are ~shit~ weird. Suggestions welcome 🙏🏻

Motivation and context

Fixes https://github.com/element-hq/element-x-android/issues/3496

(Do note that I have no idea what I'm doing.. I merely mimic what I see until it works)

Screenshots / GIFs

https://github.com/user-attachments/assets/50915a67-b92f-467d-8c1f-ec93fa00a83a

Tests

Finger touchy screeny

  • Step 1
  • Step 2
  • Step ...

Tested devices

  • [x] Physical
  • [ ] Emulator
  • OS version(s): Android 14

Checklist

  • [ ] Changes have been tested on an Android device or Android emulator with API 23
  • [ ] 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
  • [x] Pull request is based on the develop branch
  • [x] Pull request title will be used in the release note, it clearly define what will change for the user
  • [x] Pull request includes screenshots or videos if containing UI changes
  • [x] Pull request includes a sign off
  • [x] You've made a self review of your PR

frebib avatar Sep 19 '24 22:09 frebib

Thank you for your contribution! Here are a few things to check in the PR to ensure it's reviewed as quickly as possible:

  • Your branch should be based on origin/develop, at least when it was created.
  • The title of the PR will be used for release notes, so it needs to describe the change visible to the user.
  • The test pass locally running ./gradlew test.
  • The code quality check suite pass locally running ./gradlew runQualityChecks.
  • If you modified anything related to the UI, including previews, you'll have to run the Record screenshots GH action in your forked repo: that will generate compatible new screenshots. However, given Github Actions limitations, it will prevent the CI from running temporarily, until you upload a new commit after that one. To do so, just pull the latest changes and push an empty commit.

github-actions[bot] avatar Sep 19 '24 22:09 github-actions[bot]

Codecov Report

Attention: Patch coverage is 75.00000% with 13 lines in your changes missing coverage. Please review.

Project coverage is 82.66%. Comparing base (249104b) to head (c88465c). Report is 1875 commits behind head on develop.

Files with missing lines Patch % Lines
.../features/roomdetails/impl/RoomDetailsPresenter.kt 66.66% 1 Missing and 1 partial :warning:
...droid/features/roomdetails/impl/RoomDetailsView.kt 84.61% 2 Missing :warning:
...impl/members/details/RoomMemberDetailsPresenter.kt 75.00% 2 Missing :warning:
...ures/userprofile/impl/root/UserProfilePresenter.kt 75.00% 2 Missing :warning:
...roid/features/roomdetails/impl/RoomDetailsEvent.kt 0.00% 1 Missing :warning:
...d/features/roomdetails/impl/di/RoomMemberModule.kt 0.00% 1 Missing :warning:
.../features/userprofile/impl/di/UserProfileModule.kt 0.00% 1 Missing :warning:
...d/features/userprofile/shared/UserProfileEvents.kt 0.00% 1 Missing :warning:
...oid/features/userprofile/shared/UserProfileView.kt 66.66% 1 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3502      +/-   ##
===========================================
- Coverage    82.68%   82.66%   -0.03%     
===========================================
  Files         1732     1732              
  Lines        40982    41022      +40     
  Branches      4966     4972       +6     
===========================================
+ Hits         33886    33910      +24     
- Misses        5341     5354      +13     
- Partials      1755     1758       +3     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Sep 24 '24 01:09 codecov[bot]

One small issue with this implementation is the snackbars don't appear until the view is closed.. not sure why, because I copy-pasted some other code that does the same thing and it works fine. Coroutines in Kotlin are ~shit~ weird. Suggestions welcome 🙏🏻

You need the View where SnackBar may be rendered to have a SnackBarHost.

You can look for val snackbarHostState = rememberSnackbarHostState(snackbarMessage = state.snackbarMessage) in the code base and add the code to all the View which may have to render a Snackar. I know this is painful :).

bmarty avatar Sep 24 '24 13:09 bmarty

Perfect, thanks Benoit. I'll give that a go in a few days and see how I get on

frebib avatar Sep 24 '24 14:09 frebib

Snackbars are fixed, thanks! As per the contributing guidelines, I'll still need to add translations to localazy for the snackbar message. I appreciate that this doesn't have a design, but perhaps we could agree on wording for that message? I've currently just copied what Element Android used, which is simply Copied to clipboard. Once we're agreed, I'll go ahead and work out how to submit that. I should probably take a stab at trying to add some presenter tests for this new functionality at some point too

frebib avatar Sep 30 '24 22:09 frebib

Thanks for the update. I am wondering if the Snackbar interferes too much with the System clipboard alert (but I did not test the code yet):

image

bmarty avatar Oct 01 '24 07:10 bmarty

I am wondering if the Snackbar interferes too much with the System clipboard alert

Yeah I thought about this too. I'm not sure which subset of Android this little pop-up applies to. My guess would be either Pixel, or some modern Android version. There are likely some devices that don't have this and on those the snackbar would be useful?

There are other places in the app that also use this snackbar popup when copying to the clipboard. I've added it here for consistency, but I'd be happy to remove it (It'll greatly simplify the patch) if the decision is taken to remove them from other places in the app too. I'm not sure what iOS does

frebib avatar Oct 01 '24 21:10 frebib

My guess would be either Pixel, or some modern Android version

I'm pretty sure this started on Android 13.

jmartinesp avatar Nov 07 '24 12:11 jmartinesp

@frebib thanks for the update. I believe that this PR can be merged, but it needs to be updated first, to fix the conflict. We apologize for the delay on this and the extra needed work. Let me know if you need any help on this.

bmarty avatar Feb 20 '25 08:02 bmarty

Replaced by #4549

bmarty avatar Apr 07 '25 16:04 bmarty