From 4b4ba6cff85c0bc80fa354a70d7b35b4cef9a672 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Tue, 8 Mar 2016 22:13:52 +0100 Subject: reset link and highlight colors to system default --- .../ui/adapter/MessageAdapter.java | 37 ++++++++++++---------- src/main/res/layout/message_received.xml | 2 -- src/main/res/layout/message_sent.xml | 2 -- 3 files changed, 20 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java index 79f3412d..cc6ea18c 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java @@ -332,32 +332,22 @@ public class MessageAdapter extends ArrayAdapter { } 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()) { + patternMatchCount += countMatches(XMPP_PATTERN, body); + if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0 && patternMatchCount > 0) { oldAutoLinkMask -= Linkify.EMAIL_ADDRESSES; } // count matches for all patterns if ((Linkify.WEB_URLS & oldAutoLinkMask) != 0) { - matcher = Patterns.WEB_URL.matcher(body); - while (matcher.find()) { - patternMatchCount++; - } + patternMatchCount += countMatches(Patterns.WEB_URL, body); } if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0) { - matcher = Patterns.EMAIL_ADDRESS.matcher(body); - while (matcher.find()) { - patternMatchCount++; - } + patternMatchCount += countMatches(Patterns.EMAIL_ADDRESS, body); } if ((Linkify.PHONE_NUMBERS & oldAutoLinkMask) != 0) { - matcher = Patterns.PHONE.matcher(body); - while (matcher.find()) { - patternMatchCount++; - } + patternMatchCount += countMatches(Patterns.PHONE, body); } viewHolder.messageBody.setTextIsSelectable(patternMatchCount <= 1); @@ -369,12 +359,25 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.messageBody.setTextIsSelectable(false); } viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true)); - viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground, true)); - viewHolder.messageBody.setHighlightColor(activity.getResources().getColor(darkBackground ? R.color.grey800 : R.color.grey500)); viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); viewHolder.messageBody.setOnLongClickListener(openContextMenu); } + /** + * Counts the number of occurrences of the pattern in body. + * @param pattern the pattern to match + * @param body the body to find the pattern + * @return the number of occurrences + */ + private int countMatches(Pattern pattern, String body) { + Matcher matcher = pattern.matcher(body); + int count = 0; + while (matcher.find()) { + count++; + } + return count; + } + private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, String text) { viewHolder.image.setVisibility(View.GONE); diff --git a/src/main/res/layout/message_received.xml b/src/main/res/layout/message_received.xml index 93ab095b..fa690872 100644 --- a/src/main/res/layout/message_received.xml +++ b/src/main/res/layout/message_received.xml @@ -54,9 +54,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="web|phone|email" - android:textColorLink="@color/primaryText" android:textColor="@color/primaryText" - android:textColorHighlight="@color/grey500" android:textSize="?attr/TextSizeBody" app:emojiconSize="28sp" /> diff --git a/src/main/res/layout/message_sent.xml b/src/main/res/layout/message_sent.xml index 909ae9c7..b74347d4 100644 --- a/src/main/res/layout/message_sent.xml +++ b/src/main/res/layout/message_sent.xml @@ -54,9 +54,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="web|phone|email" - android:textColorLink="@color/primaryText" android:textColor="@color/primaryText" - android:textColorHighlight="@color/grey500" android:textSize="?attr/TextSizeBody" app:emojiconSize="28sp"/> -- cgit v1.2.3