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

Long press a link to copy it #320

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

pufferss
Copy link

What is it?

  • Bugfix
  • Feature
  • Codebase improvement

Description of the changes in your PR

  • Added long press on a link to copy it feature

Fixes the following issue(s)

Relies on the following changes

  • Subclassed LinkMovementMethod to handle long click on link

Acknowledgement

I subclassed LinkMovementMethod as asked.

@naveensingh naveensingh self-assigned this Feb 13, 2025

private var isLongPressDetected = false
private var startClickTime: Long = 0
private val longPressTime = 180L
Copy link
Member

Choose a reason for hiding this comment

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

This should rely on ViewConfiguration.getLongPressTimeout()

@naveensingh
Copy link
Member

I found two issues:

  • Long pressing a link also activates message selection mode but it should not.
  • The link highlight color should be restored to the original color after the copy action.

@pufferss
Copy link
Author

The message selection mode activation when long clicking on a link thing is because it was written in the issue so i thought that this was the expected behavior. I'll fix it

holder.viewLongClicked()
true
}
threadMessageBody.movementMethod = CustomLinkMovementMethod(activity, holder)
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't pass the holder object here. Just use a kotlin lambda e.g. onLinkLongClicked

Copy link
Author

@pufferss pufferss Feb 13, 2025

Choose a reason for hiding this comment

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

Yeah i passed it here because i thought i had to activate message selection mode when a link is long pressed

Copy link
Member

Choose a reason for hiding this comment

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

Yes but even then, callbacks are the proper way to do it.

@pufferss
Copy link
Author

I found two issues:

* Long pressing a link also activates message selection mode but it should not.

* The link highlight color should be restored to the original color after the copy action.

What don't understand what do you mean about the link highlight color, do you want no highlight color while copying a link ?

@naveensingh
Copy link
Member

  • On touch down => highlight link
  • Once we have a confirmed long press => copy the link and remove the highlight (until the next touch down).

The part in bold is what I mean.

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.

long press a link to copy it
2 participants