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); .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")) { } else if (individualHashMap.get("type").equals("file")) {
itemView.setOnClickListener(v -> { itemView.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap.get("link"))); 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("type").equals("user") || individualHashMap.get("type").equals("guest") || individualHashMap.get("type").equals("call")) {
if (!individualHashMap.get("id").equals(message.getActiveUserId())) { if (!individualHashMap.get("id").equals(message.getActiveUserId())) {
messageString = messageString =
DisplayUtils.searchAndColor(message.getText(), DisplayUtils.searchAndColor(messageString,
"@" + individualHashMap.get("name"), NextcloudTalkApplication "@" + individualHashMap.get("name"), NextcloudTalkApplication
.getSharedApplication().getResources().getColor(R.color.nc_outcoming_text_default)); .getSharedApplication().getResources().getColor(R.color.nc_outcoming_text_default));
} }

View File

@ -68,7 +68,8 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes
} }
messageString = 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); Spannable spannableString = new SpannableString(text);
String stringText = text.toString();
if (TextUtils.isEmpty(text) || TextUtils.isEmpty(searchText)) { if (TextUtils.isEmpty(text) || TextUtils.isEmpty(searchText)) {
return spannableString; return spannableString;
} }
@ -227,7 +227,7 @@ public class DisplayUtils {
int lastStartIndex = -1; int lastStartIndex = -1;
while (m.find()) { while (m.find()) {
int start = text.indexOf(m.group(), lastStartIndex); int start = stringText.indexOf(m.group(), lastStartIndex);
int end = start + m.group().length(); int end = start + m.group().length();
lastStartIndex = end; lastStartIndex = end;
spannableString.setSpan(new ForegroundColorSpan(color), start, end, spannableString.setSpan(new ForegroundColorSpan(color), start, end,