mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-01 04:09:21 +00:00
Improve coloring
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
dfae11f65c
commit
b35a1c0758
@ -143,8 +143,7 @@ public class MagicIncomingTextMessageViewHolder
|
||||
.nc_incoming_text_mention_others);
|
||||
}
|
||||
|
||||
messageString = DisplayUtils.searchAndColor(messageText.getText().toString(),
|
||||
messageString, "@" + individualHashMap.get("name"), color);
|
||||
messageString = DisplayUtils.searchAndColor(message.getText(), "@" + 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")));
|
||||
|
@ -90,8 +90,9 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
|
||||
Map<String, String> individualHashMap = message.getMessageParameters().get(key);
|
||||
if (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest")) {
|
||||
if (!individualHashMap.get("id").equals(message.getActiveUserId())) {
|
||||
messageString = DisplayUtils.searchAndColor(messageText.getText().toString(),
|
||||
messageString, "@" + individualHashMap.get("name"), NextcloudTalkApplication
|
||||
messageString =
|
||||
DisplayUtils.searchAndColor(message.getText(),
|
||||
"@" + individualHashMap.get("name"), NextcloudTalkApplication
|
||||
.getSharedApplication().getResources().getColor(R.color.nc_outcoming_text_default));
|
||||
}
|
||||
|
||||
|
@ -67,8 +67,8 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes
|
||||
color = context.getResources().getColor(R.color.nc_incoming_text_mention_others);
|
||||
}
|
||||
|
||||
messageString = DisplayUtils.searchAndColor(message.getText(),
|
||||
messageString, "@" + individualHashMap.get("name"), color);
|
||||
messageString =
|
||||
DisplayUtils.searchAndColor(message.getText(), "@" + individualHashMap.get("name"), color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class MentionAutocompleteCallback implements AutocompleteCallback<Mention
|
||||
String replacement = item.getLabel();
|
||||
editable.replace(start, end, replacement + " ");
|
||||
Spans.MentionSpan mentionSpan = new Spans.MentionSpan(Typeface.BOLD, item.getId(), item.getLabel());
|
||||
editable.setSpan(mentionSpan, start, start + replacement.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
editable.setSpan(mentionSpan, start, start + item.getLabel().length() , Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -374,6 +374,16 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
||||
} else {
|
||||
messageInput.setError(null);
|
||||
}
|
||||
|
||||
Editable editable = messageInput.getEditableText();
|
||||
Spans.MentionSpan[] mentionSpans = editable.getSpans(0, messageInput.length(), Spans.MentionSpan.class);
|
||||
Spans.MentionSpan mentionSpan;
|
||||
for (int i = 0; i < mentionSpans.length; i++) {
|
||||
mentionSpan = mentionSpans[i];
|
||||
if (start >= editable.getSpanStart(mentionSpan) && start < editable.getSpanEnd(mentionSpan)) {
|
||||
editable.removeSpan(mentionSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -203,27 +203,34 @@ public class DisplayUtils {
|
||||
}
|
||||
|
||||
|
||||
public static Spannable searchAndColor(String text, Spannable spannable, String searchText, @ColorInt int color) {
|
||||
public static Spannable searchAndColor(String text, String searchText, @ColorInt int color) {
|
||||
|
||||
Spannable spannableString = new SpannableString(text);
|
||||
|
||||
if (TextUtils.isEmpty(text) || TextUtils.isEmpty(searchText)) {
|
||||
return spannable;
|
||||
return spannableString;
|
||||
}
|
||||
|
||||
Matcher m = Pattern.compile(searchText, Pattern.CASE_INSENSITIVE | Pattern.LITERAL)
|
||||
.matcher(text);
|
||||
Matcher m = Pattern.compile(searchText,
|
||||
Pattern.CASE_INSENSITIVE | Pattern.LITERAL | Pattern.MULTILINE)
|
||||
.matcher(spannableString);
|
||||
|
||||
|
||||
int textSize = NextcloudTalkApplication.getSharedApplication().getResources().getDimensionPixelSize(R.dimen
|
||||
.chat_text_size);
|
||||
|
||||
int lastStartIndex = -1;
|
||||
while (m.find()) {
|
||||
int start = text.indexOf(m.group());
|
||||
int end = text.indexOf(m.group()) + m.group().length();
|
||||
spannable.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
spannable.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
spannable.setSpan(new AbsoluteSizeSpan(textSize), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
int start = text.indexOf(m.group(), lastStartIndex);
|
||||
int end = start + m.group().length();
|
||||
lastStartIndex = end;
|
||||
spannableString.setSpan(new ForegroundColorSpan(color), start, end,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
spannableString.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
spannableString.setSpan(new AbsoluteSizeSpan(textSize), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
return spannable;
|
||||
return spannableString;
|
||||
}
|
||||
|
||||
public static Drawable getMessageSelector(@ColorInt int normalColor, @ColorInt int selectedColor,
|
||||
|
Loading…
Reference in New Issue
Block a user