use colored usernames in group chats/channels

This commit is contained in:
Christian Schneppe 2020-02-10 20:10:04 +01:00
parent caaaa05e81
commit e2d89da5d3
No known key found for this signature in database
GPG key ID: F30B8D686B44D87E
5 changed files with 31 additions and 8 deletions

View file

@ -657,7 +657,7 @@ public class NotificationService {
builder.setUri(uri.toString());
}
} else {
builder.setName(UIHelper.getMessageDisplayName(message));
builder.setName(UIHelper.getColoredUsername(message));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
builder.setIcon(IconCompat.createWithBitmap(mXmppConnectionService.getAvatarService().get(message, AvatarService.getSystemUiAvatarSize(mXmppConnectionService), false)));
@ -704,17 +704,15 @@ 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(message);
styledString = new SpannableString(name + ": " + message.getBody());
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
style.addLine(styledString);
}
builder.setStyle(style);
int count = messages.size();
if (count == 1) {
final String name = UIHelper.getMessageDisplayName(messages.get(0));
final SpannableString name = UIHelper.getColoredUsername(messages.get(0));
styledString = new SpannableString(name + ": " + messages.get(0).getBody());
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
builder.setContentText(styledString);
builder.setTicker(styledString);
} else {

View file

@ -3,6 +3,7 @@ package de.pixart.messenger.ui.adapter;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.preference.PreferenceManager;
import android.text.SpannableStringBuilder;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
@ -182,7 +183,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationAdapte
if (message.getStatus() == Message.STATUS_RECEIVED) {
if (conversation.getMode() == Conversation.MODE_MULTI) {
viewHolder.binding.senderName.setVisibility(View.VISIBLE);
viewHolder.binding.senderName.setText(UIHelper.getMessageDisplayName(message).split("\\s+")[0] + ':');
viewHolder.binding.senderName.setText(UIHelper.getColoredUsername(message));
} else {
viewHolder.binding.senderName.setVisibility(View.GONE);
}

View file

@ -303,7 +303,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
break;
default:
if (multiReceived) {
info = UIHelper.getMessageDisplayName(message);
viewHolder.username.setText(UIHelper.getColoredUsername(message));
}
break;
}
@ -578,7 +578,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.messageBody.setHighlightColor(darkBackground ? type == SENT ? StyledAttributes.getColor(activity, R.attr.colorAccent) : StyledAttributes.getColor(activity, R.attr.colorAccent) : StyledAttributes.getColor(activity, R.attr.colorAccent));
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
if (message.getBody() != null) {
final String nick = UIHelper.getMessageDisplayName(message);
final SpannableString nick = UIHelper.getColoredUsername(message);
SpannableStringBuilder body = new SpannableStringBuilder(replaceYoutube(activity.getApplicationContext(), message.getMergedBody().toString()));
if (message.getBody().equals(DELETED_MESSAGE_BODY)) {
body = body.replace(0, DELETED_MESSAGE_BODY.length(), activity.getString(R.string.message_deleted));
@ -1103,6 +1103,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
view = activity.getLayoutInflater().inflate(R.layout.message_received, parent, false);
viewHolder.message_box = view.findViewById(R.id.message_box);
viewHolder.contact_picture = view.findViewById(R.id.message_photo);
viewHolder.username = view.findViewById(R.id.username);
viewHolder.audioPlayer = view.findViewById(R.id.audio_player);
viewHolder.download_button = view.findViewById(R.id.download_button);
viewHolder.answer_button = view.findViewById(R.id.answer);
@ -1463,6 +1464,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
protected TextView time;
protected CopyTextView messageBody;
protected TextView user;
protected TextView username;
protected ImageView contact_picture;
protected TextView status_message;
protected TextView encryption;

View file

@ -1,9 +1,14 @@
package de.pixart.messenger.utils;
import android.content.Context;
import android.graphics.Typeface;
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 androidx.annotation.ColorInt;
@ -499,6 +504,14 @@ public class UIHelper {
}
}
public static SpannableString getColoredUsername(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);
user.setSpan(new ForegroundColorSpan(message.getAvatarBackgroundColor()), 0, user.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return user;
}
public static String getMessageDisplayName(final Message message) {
final Conversational conversation = message.getConversation();
if (message.getStatus() == Message.STATUS_RECEIVED) {

View file

@ -43,6 +43,15 @@
android:orientation="vertical"
android:padding="2dp">
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="@string/sending"
android:textAppearance="@style/TextAppearance.Conversations.Caption" />
<include layout="@layout/message_content" />
<LinearLayout