mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01: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);
|
.nc_incoming_text_mention_others);
|
||||||
}
|
}
|
||||||
|
|
||||||
messageString = DisplayUtils.searchAndColor(messageText.getText().toString(),
|
messageString = DisplayUtils.searchAndColor(message.getText(), "@" + individualHashMap.get("name"), color);
|
||||||
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")));
|
||||||
|
@ -90,8 +90,9 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
|
|||||||
Map<String, String> individualHashMap = message.getMessageParameters().get(key);
|
Map<String, String> individualHashMap = message.getMessageParameters().get(key);
|
||||||
if (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest")) {
|
if (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest")) {
|
||||||
if (!individualHashMap.get("id").equals(message.getActiveUserId())) {
|
if (!individualHashMap.get("id").equals(message.getActiveUserId())) {
|
||||||
messageString = DisplayUtils.searchAndColor(messageText.getText().toString(),
|
messageString =
|
||||||
messageString, "@" + individualHashMap.get("name"), NextcloudTalkApplication
|
DisplayUtils.searchAndColor(message.getText(),
|
||||||
|
"@" + individualHashMap.get("name"), NextcloudTalkApplication
|
||||||
.getSharedApplication().getResources().getColor(R.color.nc_outcoming_text_default));
|
.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);
|
color = context.getResources().getColor(R.color.nc_incoming_text_mention_others);
|
||||||
}
|
}
|
||||||
|
|
||||||
messageString = DisplayUtils.searchAndColor(message.getText(),
|
messageString =
|
||||||
messageString, "@" + individualHashMap.get("name"), color);
|
DisplayUtils.searchAndColor(message.getText(), "@" + individualHashMap.get("name"), color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class MentionAutocompleteCallback implements AutocompleteCallback<Mention
|
|||||||
String replacement = item.getLabel();
|
String replacement = item.getLabel();
|
||||||
editable.replace(start, end, replacement + " ");
|
editable.replace(start, end, replacement + " ");
|
||||||
Spans.MentionSpan mentionSpan = new Spans.MentionSpan(Typeface.BOLD, item.getId(), item.getLabel());
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,6 +374,16 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
} else {
|
} else {
|
||||||
messageInput.setError(null);
|
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
|
@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)) {
|
if (TextUtils.isEmpty(text) || TextUtils.isEmpty(searchText)) {
|
||||||
return spannable;
|
return spannableString;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher m = Pattern.compile(searchText, Pattern.CASE_INSENSITIVE | Pattern.LITERAL)
|
Matcher m = Pattern.compile(searchText,
|
||||||
.matcher(text);
|
Pattern.CASE_INSENSITIVE | Pattern.LITERAL | Pattern.MULTILINE)
|
||||||
|
.matcher(spannableString);
|
||||||
|
|
||||||
|
|
||||||
int textSize = NextcloudTalkApplication.getSharedApplication().getResources().getDimensionPixelSize(R.dimen
|
int textSize = NextcloudTalkApplication.getSharedApplication().getResources().getDimensionPixelSize(R.dimen
|
||||||
.chat_text_size);
|
.chat_text_size);
|
||||||
|
|
||||||
|
int lastStartIndex = -1;
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
int start = text.indexOf(m.group());
|
int start = text.indexOf(m.group(), lastStartIndex);
|
||||||
int end = text.indexOf(m.group()) + m.group().length();
|
int end = start + m.group().length();
|
||||||
spannable.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
lastStartIndex = end;
|
||||||
spannable.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
spannableString.setSpan(new ForegroundColorSpan(color), start, end,
|
||||||
spannable.setSpan(new AbsoluteSizeSpan(textSize), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
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,
|
public static Drawable getMessageSelector(@ColorInt int normalColor, @ColorInt int selectedColor,
|
||||||
|
Loading…
Reference in New Issue
Block a user