aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 53611d37..36790041 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -330,15 +330,40 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
viewHolder.messageBody.setText(span);
}
- int urlCount = 0;
- Matcher matcher = Patterns.WEB_URL.matcher(body);
- while (matcher.find()) {
- urlCount++;
+ int patternMatchCount = 0;
+ int oldAutoLinkMask = viewHolder.messageBody.getAutoLinkMask();
+ Matcher matcher = null;
+
+ // first check if we have a match on XMPP_PATTERN so we do not have to check for EMAIL_ADDRESSES
+ matcher = XMPP_PATTERN.matcher(body);
+ if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0 && matcher.find()) {
+ oldAutoLinkMask -= Linkify.EMAIL_ADDRESSES;
}
- viewHolder.messageBody.setTextIsSelectable(urlCount <= 1);
+
+ // count matches for all patterns
+ if ((Linkify.WEB_URLS & oldAutoLinkMask) != 0) {
+ matcher = Patterns.WEB_URL.matcher(body);
+ while (matcher.find()) {
+ patternMatchCount++;
+ }
+ }
+ if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0) {
+ matcher = Patterns.EMAIL_ADDRESS.matcher(body);
+ while (matcher.find()) {
+ patternMatchCount++;
+ }
+ }
+ if ((Linkify.PHONE_NUMBERS & oldAutoLinkMask) != 0) {
+ matcher = Patterns.PHONE.matcher(body);
+ while (matcher.find()) {
+ patternMatchCount++;
+ }
+ }
+
+ viewHolder.messageBody.setTextIsSelectable(patternMatchCount <= 1);
viewHolder.messageBody.setAutoLinkMask(0);
- Linkify.addLinks(viewHolder.messageBody, Linkify.WEB_URLS);
Linkify.addLinks(viewHolder.messageBody, XMPP_PATTERN, "xmpp");
+ viewHolder.messageBody.setAutoLinkMask(oldAutoLinkMask);
} else {
viewHolder.messageBody.setText("");
viewHolder.messageBody.setTextIsSelectable(false);