aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian.schneppe@pix-art.de>2020-02-10 20:10:04 +0100
committerChristian Schneppe <christian.schneppe@pix-art.de>2020-02-10 20:10:04 +0100
commite2d89da5d3fe0169f1b3a53147cdc8cdb6efaf6c (patch)
tree817cb4a12071bbce84a1eb423f488f5200aa4d10 /src/main/java
parentcaaaa05e81c8b67302b24ce08cfa94c074b5f549 (diff)
use colored usernames in group chats/channels
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/services/NotificationService.java8
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java3
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java6
-rw-r--r--src/main/java/de/pixart/messenger/utils/UIHelper.java13
4 files changed, 22 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java
index dcbff4f17..0848d0c2c 100644
--- a/src/main/java/de/pixart/messenger/services/NotificationService.java
+++ b/src/main/java/de/pixart/messenger/services/NotificationService.java
@@ -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 {
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java
index 7f52293e8..cf4a72bee 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java
@@ -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);
}
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index 38016229d..5992a9a8a 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -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;
diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java
index fe933f8ac..5c3db105a 100644
--- a/src/main/java/de/pixart/messenger/utils/UIHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java
@@ -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) {