diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index ee00ea618..3b7330552 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -1736,7 +1736,7 @@ public class NotificationService { builder.setUri(uri.toString()); } } else { - builder.setName(UIHelper.getMessageDisplayName(message)); + builder.setName(UIHelper.getColoredUsername(mXmppConnectionService, message)); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { final Jid jid = contact == null ? message.getCounterpart() : contact.getJid(); @@ -1849,7 +1849,7 @@ public class NotificationService { final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); SpannableString styledString; for (Message message : messages) { - final String name = UIHelper.getMessageDisplayName(message); + final SpannableString name = UIHelper.getColoredUsername(mXmppConnectionService, message); styledString = new SpannableString(name + ": " + message.getBody()); styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0); style.addLine(styledString); @@ -1857,7 +1857,7 @@ public class NotificationService { builder.setStyle(style); int count = messages.size(); if (count == 1) { - final String name = UIHelper.getMessageDisplayName(messages.get(0)); + final SpannableString name = UIHelper.getColoredUsername(mXmppConnectionService, messages.get(0)); styledString = new SpannableString(name + ": " + messages.get(0).getBody()); styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0); builder.setContentText(styledString); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 87c729ff6..32fa12e80 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -6301,4 +6301,8 @@ public class XmppConnectionService extends Service { PUSH, PRESENCE } + + public boolean colored_muc_names() { + return getBooleanPreference("colored_muc_names", R.bool.use_colored_muc_names); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index cebb75e16..b81e429af 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -196,9 +196,12 @@ public class ConversationAdapter if (status == Message.STATUS_RECEIVED) { if (conversation.getMode() == Conversation.MODE_MULTI) { viewHolder.binding.senderName.setVisibility(View.VISIBLE); + /* final String dname = UIHelper.getMessageDisplayName(message); final String[] words = dname.split("\\s+"); viewHolder.binding.senderName.setText((words.length > 0 ? words[0] : dname) + ':'); + */ + viewHolder.binding.senderName.setText(UIHelper.getColoredUsername(activity.xmppConnectionService, message) + ":"); } else { viewHolder.binding.senderName.setVisibility(View.GONE); } 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 86c9fcbb0..a6d7e899b 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -375,7 +375,7 @@ public class MessageAdapter extends ArrayAdapter { if (displayName != null) { timeInfoBuilder.add(""); viewHolder.username().setVisibility(View.VISIBLE); - viewHolder.username().setText(displayName); + viewHolder.username().setText(UIHelper.getColoredUsername(activity.xmppConnectionService, message)); } } else { viewHolder.username().setText(null); @@ -613,7 +613,7 @@ public class MessageAdapter extends ArrayAdapter { if (message.getBody() != null && !message.getBody().equals("")) { viewHolder.messageBody().setTextIsSelectable(true); viewHolder.messageBody().setVisibility(View.VISIBLE); - final String nick = UIHelper.getMessageDisplayName(message); + final SpannableString nick = UIHelper.getColoredUsername(activity.xmppConnectionService, message); SpannableStringBuilder body = getSpannableBody(message); final var processMarkup = body.getSpans(0, body.length(), Message.PlainTextSpan.class).length > 0; if (body.length() > Config.MAX_DISPLAY_MESSAGE_CHARS) { diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 29ad53807..52676d811 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -1,11 +1,16 @@ package eu.siacs.conversations.utils; import android.content.Context; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.content.res.ColorStateList; +import android.text.Spannable; +import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.format.DateFormat; import android.text.format.DateUtils; +import android.text.style.ForegroundColorSpan; +import android.text.style.StyleSpan; import android.util.Pair; import android.widget.TextView; @@ -610,4 +615,14 @@ public class UIHelper { return size + " B"; } } + + public static SpannableString getColoredUsername(final XmppConnectionService service, final Message message) { + final SpannableString user; + user = SpannableString.valueOf(UIHelper.getMessageDisplayName(message)); + user.setSpan(new StyleSpan(Typeface.BOLD), 0, user.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + if (service.colored_muc_names()) { + user.setSpan(new ForegroundColorSpan(message.getAvatarBackgroundColor()), 0, user.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } + return user; + } } diff --git a/src/main/res/drawable/rounded_format_color_text_24.xml b/src/main/res/drawable/rounded_format_color_text_24.xml new file mode 100644 index 000000000..2a8f0858f --- /dev/null +++ b/src/main/res/drawable/rounded_format_color_text_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/res/values/bools.xml b/src/main/res/values/bools.xml index 4e0b4207d..38f2372a3 100644 --- a/src/main/res/values/bools.xml +++ b/src/main/res/values/bools.xml @@ -13,4 +13,5 @@ false false false + false diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 12f3f7662..9c6052596 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1406,4 +1406,6 @@ Use secure TLS Ciphers only Prefers IPv6 when connecting Prefer IPv6 + Use colored user names + Use colored user names in group chats \ No newline at end of file diff --git a/src/main/res/xml/preferences_interface.xml b/src/main/res/xml/preferences_interface.xml index e24881b7a..18e873ce1 100644 --- a/src/main/res/xml/preferences_interface.xml +++ b/src/main/res/xml/preferences_interface.xml @@ -103,6 +103,12 @@ android:key="show_own_accounts" android:summary="@string/pref_show_own_accounts_summary" android:title="@string/pref_show_own_accounts" /> +