Better-Link-Movement-Method icon indicating copy to clipboard operation
Better-Link-Movement-Method copied to clipboard

Link not working if the description of the link (the part between the tags) itself is not a link.

Open mparyani445 opened this issue 4 years ago • 5 comments

The library is working fine only if we have link between tags for example: Some text http://www.google.com Some text http://www.google.com In this way it will highlight the link and clickable also, but in case 2

Some text Go to Google Some text Go to Google

Link is not generating neither it is clickable, can you provide any solution for this I have tried using 1.BetterLinkMovementMethod.linkify(Linkify.ALL, textview) and 2.BetterLinkMovementMethod.linkifyHtml(textview) both

mparyani445 avatar Jan 15 '20 12:01 mparyani445

Don't think this issue is specific to this library, sorry.

saket avatar Jan 16 '20 04:01 saket

Same. this works when using normal LinkMovementMethod but when using BetterLinkMovementMethod, it does not make it a link.

travismmorgan avatar Jun 10 '20 20:06 travismmorgan

Huh, I wonder if my implementations of linkify*() functions are wrong. I'd advise to avoid using them in that case.

saket avatar Jun 11 '20 05:06 saket

Ok I have a solution for this, We have text with HTML, but also want the Linkify to work as well. I will open a PR soon for you. The issue is that when you call Linkify on a text view where you did Html.fromHtml, they clear the previous spans. So the solution is to first record the current spans, then apply linkify which will remove your HTML spans, then apply them back.

cfsbhawkins avatar Apr 02 '21 19:04 cfsbhawkins

Basically update addLinks to this ` private static void addLinks(int linkifyMask, BetterLinkMovementMethod movementMethod, TextView textView) { textView.setMovementMethod(movementMethod); URLSpan[] htmlUrlSpans = null; if(textView.getText() instanceof SpannableString){ htmlUrlSpans = ((SpannableString)textView.getText()).getSpans(0, textView.getText().length(), URLSpan.class); }

SpannableString buffer = new SpannableString(textView.getText());

if (linkifyMask != LINKIFY_NONE) {
  Linkify.addLinks(buffer, linkifyMask);
}

if(htmlUrlSpans != null && textView.getText() instanceof SpannableString){
  for (URLSpan span : htmlUrlSpans) {
    int end = ((SpannableString)textView.getText()).getSpanEnd(span);
    int start = ((SpannableString)textView.getText()).getSpanStart(span);
    buffer.setSpan(span, start,end,0);
  }
}

textView.setText(buffer);

}`

cfsbhawkins avatar Apr 02 '21 20:04 cfsbhawkins