forked from mirror/monocles_chat
Option for colored usernames in group chats
This commit is contained in:
parent
2b2deb3f4f
commit
815970cde9
9 changed files with 41 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -375,7 +375,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||
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<Message> {
|
|||
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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
5
src/main/res/drawable/rounded_format_color_text_24.xml
Normal file
5
src/main/res/drawable/rounded_format_color_text_24.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?colorControlNormal" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M120,960Q103,960 91.5,948.5Q80,937 80,920L80,840Q80,823 91.5,811.5Q103,800 120,800L840,800Q857,800 868.5,811.5Q880,823 880,840L880,920Q880,937 868.5,948.5Q857,960 840,960L120,960ZM285,680Q262,680 248.5,660.5Q235,641 243,619L419,150Q424,136 436,128Q448,120 462,120L498,120Q513,120 524.5,128Q536,136 541,150L718,620Q726,642 712.5,661Q699,680 676,680Q662,680 650,672Q638,664 633,650L594,536L368,536L327,651Q322,665 310.5,672.5Q299,680 285,680ZM396,456L564,456L482,224L478,224L396,456Z"/>
|
||||
|
||||
</vector>
|
|
@ -13,4 +13,5 @@
|
|||
<bool name="app_lock_enabled">false</bool>
|
||||
<bool name="secure_tls">false</bool>
|
||||
<bool name="prefer_ipv6">false</bool>
|
||||
<bool name="use_colored_muc_names">false</bool>
|
||||
</resources>
|
||||
|
|
|
@ -1406,4 +1406,6 @@
|
|||
<string name="pref_secure_tls">Use secure TLS Ciphers only</string>
|
||||
<string name="pref_prefer_ipv6_summary">Prefers IPv6 when connecting</string>
|
||||
<string name="pref_prefer_ipv6">Prefer IPv6</string>
|
||||
<string name="pref_use_colored_muc_names">Use colored user names</string>
|
||||
<string name="pref_use_colored_muc_names_summary">Use colored user names in group chats</string>
|
||||
</resources>
|
|
@ -103,6 +103,12 @@
|
|||
android:key="show_own_accounts"
|
||||
android:summary="@string/pref_show_own_accounts_summary"
|
||||
android:title="@string/pref_show_own_accounts" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="@bool/use_colored_muc_names"
|
||||
android:icon="@drawable/rounded_format_color_text_24"
|
||||
android:key="colored_muc_names"
|
||||
android:summary="@string/pref_use_colored_muc_names_summary"
|
||||
android:title="@string/pref_use_colored_muc_names" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="@bool/show_nav_bar"
|
||||
android:key="show_nav_bar"
|
||||
|
|
Loading…
Reference in a new issue