Merge branch 'trz/rename' into trz/rebase

This commit is contained in:
lookshe 2016-03-08 22:24:47 +01:00
commit a6442dd3ac
3 changed files with 20 additions and 21 deletions

View file

@ -332,32 +332,22 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} }
int patternMatchCount = 0; int patternMatchCount = 0;
int oldAutoLinkMask = viewHolder.messageBody.getAutoLinkMask(); 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 // 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); patternMatchCount += countMatches(XMPP_PATTERN, body);
if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0 && matcher.find()) { if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0 && patternMatchCount > 0) {
oldAutoLinkMask -= Linkify.EMAIL_ADDRESSES; oldAutoLinkMask -= Linkify.EMAIL_ADDRESSES;
} }
// count matches for all patterns // count matches for all patterns
if ((Linkify.WEB_URLS & oldAutoLinkMask) != 0) { if ((Linkify.WEB_URLS & oldAutoLinkMask) != 0) {
matcher = Patterns.WEB_URL.matcher(body); patternMatchCount += countMatches(Patterns.WEB_URL, body);
while (matcher.find()) {
patternMatchCount++;
}
} }
if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0) { if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0) {
matcher = Patterns.EMAIL_ADDRESS.matcher(body); patternMatchCount += countMatches(Patterns.EMAIL_ADDRESS, body);
while (matcher.find()) {
patternMatchCount++;
}
} }
if ((Linkify.PHONE_NUMBERS & oldAutoLinkMask) != 0) { if ((Linkify.PHONE_NUMBERS & oldAutoLinkMask) != 0) {
matcher = Patterns.PHONE.matcher(body); patternMatchCount += countMatches(Patterns.PHONE, body);
while (matcher.find()) {
patternMatchCount++;
}
} }
viewHolder.messageBody.setTextIsSelectable(patternMatchCount <= 1); viewHolder.messageBody.setTextIsSelectable(patternMatchCount <= 1);
@ -369,12 +359,25 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setTextIsSelectable(false); viewHolder.messageBody.setTextIsSelectable(false);
} }
viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true)); 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.setTypeface(null, Typeface.NORMAL);
viewHolder.messageBody.setOnLongClickListener(openContextMenu); 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, private void displayDownloadableMessage(ViewHolder viewHolder,
final Message message, String text) { final Message message, String text) {
viewHolder.image.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE);

View file

@ -54,9 +54,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:autoLink="web|phone|email" android:autoLink="web|phone|email"
android:textColorLink="@color/primaryText"
android:textColor="@color/primaryText" android:textColor="@color/primaryText"
android:textColorHighlight="@color/grey500"
android:textSize="?attr/TextSizeBody" android:textSize="?attr/TextSizeBody"
app:emojiconSize="28sp" /> app:emojiconSize="28sp" />

View file

@ -54,9 +54,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:autoLink="web|phone|email" android:autoLink="web|phone|email"
android:textColorLink="@color/primaryText"
android:textColor="@color/primaryText" android:textColor="@color/primaryText"
android:textColorHighlight="@color/grey500"
android:textSize="?attr/TextSizeBody" android:textSize="?attr/TextSizeBody"
app:emojiconSize="28sp"/> app:emojiconSize="28sp"/>