From 5e1cbf8514892d557c8927abad3911dc38f2871c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 3 May 2018 13:57:13 +0200 Subject: [PATCH] only highlight alphanumeric chars --- .../ui/adapter/MessageAdapter.java | 4 ++-- .../conversations/utils/StylingHelper.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 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 6a2c83d9c..f77427cdc 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -1007,8 +1007,8 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie } } - public void setHighlightedTerm(List term) { - this.highlightedTerm = term; + public void setHighlightedTerm(List terms) { + this.highlightedTerm = terms == null ? null : StylingHelper.filterHighlightedWords(terms); } public interface OnQuoteListener { diff --git a/src/main/java/eu/siacs/conversations/utils/StylingHelper.java b/src/main/java/eu/siacs/conversations/utils/StylingHelper.java index 23e6709f7..1303d086e 100644 --- a/src/main/java/eu/siacs/conversations/utils/StylingHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/StylingHelper.java @@ -47,6 +47,7 @@ import android.text.style.TypefaceSpan; import android.widget.EditText; import android.widget.TextView; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -99,6 +100,25 @@ public class StylingHelper { } } + public static List filterHighlightedWords(List terms) { + List words = new ArrayList<>(); + for(String term : terms) { + if (!FtsUtils.isKeyword(term)) { + StringBuilder builder = new StringBuilder(); + for (int codepoint, i = 0; i < term.length(); i += Character.charCount(codepoint)) { + codepoint = term.codePointAt(i); + if (Character.isLetterOrDigit(codepoint)) { + builder.append(Character.toChars(codepoint)); + } + } + if (builder.length() > 0) { + words.add(builder.toString()); + } + } + } + return words; + } + private static void highlight(final Context context, final Editable editable, String needle, boolean dark) { final int length = needle.length(); String string = editable.toString();