klinker24 / Android-TextView-LinkBuilder

Insanely easy way to define clickable links within a TextView.
MIT License
1.59k stars 199 forks source link

Link for second word with similar content not working #43

Closed madhurtewani closed 7 years ago

madhurtewani commented 7 years ago

Hi @klinker24,

In a TextView if I add a LinkBuilder that links hashtags or @mentions then second word sometimes doesn't link properly. The use case is when the second word starts with the first word.

Example: Consider following text as contents of TextView. #hello #helloBuddy #hello_buddy

#hello is highlighted and linked in all 3 words.

Below is the screenshot for same. screenshot_1500276421

Please reply ASAP.

klinker24 commented 7 years ago

There did seem to be some issues with this. I have fixed them here and here. I will release a new version shortly.

With these changes, the library has support for regular expressions, using a regex, you can accomplish this.

For example, this regular expression would match any #hello... hashtags: #hello([$A-Za-z0-9_-]*)

While this regex would match any hashtags: #([$A-Za-z0-9_-]+)

To apply these within the link builder, you could use:

Link helloHashtag = new Link(Pattern.compile("#hello([$A-Za-z0-9_-]*)"));

screenshot_20170717-075706

madhurtewani commented 7 years ago

Thank you @klinker24.

I will not be able to the following because the text is completely dynamic and won't get to know if the text is having similar use case or not.

Link helloHashtag = new Link(Pattern.compile("#hello([$A-Za-z0-9_-]*)"));

Can you please tell me when would you be releasing the updated version of library with the fix?

klinker24 commented 7 years ago

I was giving an example of a regular expression usage. There is a matcher for any hashtag in my comment too.

The update will be available whenever maven central releases it. Within the hour usually, sometimes longer, hard to give an exact time

madhurtewani commented 7 years ago

OK, thank you.

madhurtewani commented 7 years ago

Hi @klinker24,

I got the updated library and highlight is working fine but link is not.

Link is still applied on the partial text (hello as per my example) and only that part is clickable. In click listener the clickedText returned is only the partial text instead of full text.

klinker24 commented 7 years ago

Here are some changes: https://github.com/klinker24/Android-TextView-LinkBuilder/commit/c4fa9c7aacf375e85fad8cb0a0004a8a2d62962c

If you could try them out and confirm it works, I will make a build.

madhurtewani commented 7 years ago

Yes, it works completely fine. Thank you.

klinker24 commented 7 years ago

Ok, I will release it as 1.6.1, it will be available shortly.