Fix mention coloring

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-04-09 10:40:30 +02:00
parent 3c184f7d52
commit 48fdee2a65
4 changed files with 8 additions and 6 deletions

View file

@ -155,7 +155,8 @@ public class MagicIncomingTextMessageViewHolder
.nc_incoming_text_mention_others);
}
messageString = DisplayUtils.searchAndColor(message.getText(), "@" + individualHashMap.get("name"), color);
messageString = DisplayUtils.searchAndColor(messageString,
"@" + individualHashMap.get("name"), color);
} else if (individualHashMap.get("type").equals("file")) {
itemView.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap.get("link")));

View file

@ -92,7 +92,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
if (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest") || individualHashMap.get("type").equals("call")) {
if (!individualHashMap.get("id").equals(message.getActiveUserId())) {
messageString =
DisplayUtils.searchAndColor(message.getText(),
DisplayUtils.searchAndColor(messageString,
"@" + individualHashMap.get("name"), NextcloudTalkApplication
.getSharedApplication().getResources().getColor(R.color.nc_outcoming_text_default));
}

View file

@ -68,7 +68,8 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes
}
messageString =
DisplayUtils.searchAndColor(message.getText(), "@" + individualHashMap.get("name"), color);
DisplayUtils.searchAndColor(messageString,
"@" + individualHashMap.get("name"), color);
}
}
}

View file

@ -209,10 +209,10 @@ public class DisplayUtils {
}
public static Spannable searchAndColor(String text, String searchText, @ColorInt int color) {
public static Spannable searchAndColor(Spannable text, String searchText, @ColorInt int color) {
Spannable spannableString = new SpannableString(text);
String stringText = text.toString();
if (TextUtils.isEmpty(text) || TextUtils.isEmpty(searchText)) {
return spannableString;
}
@ -227,7 +227,7 @@ public class DisplayUtils {
int lastStartIndex = -1;
while (m.find()) {
int start = text.indexOf(m.group(), lastStartIndex);
int start = stringText.indexOf(m.group(), lastStartIndex);
int end = start + m.group().length();
lastStartIndex = end;
spannableString.setSpan(new ForegroundColorSpan(color), start, end,