diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-01-03 22:54:31 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-01-03 22:54:31 +0100 |
commit | 173ade9d7bd6fb757b4234acfaadeb127af93cac (patch) | |
tree | d92e6ee6abf78c015a53c6cc540776e44225554f /src/main/java/de/pixart/messenger/services | |
parent | 76c8a67ade32affffef1da61dd2f9454f730984e (diff) |
use person in message style notification
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/NotificationService.java | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index c4fa85322..83441cce1 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -23,8 +23,10 @@ import android.support.v4.app.NotificationCompat.BigPictureStyle; import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationCompat.CarExtender.UnreadConversation; import android.support.v4.app.NotificationManagerCompat; +import android.support.v4.app.Person; import android.support.v4.app.RemoteInput; import android.support.v4.content.ContextCompat; +import android.support.v4.graphics.drawable.IconCompat; import android.text.SpannableString; import android.text.style.StyleSpan; import android.util.DisplayMetrics; @@ -62,6 +64,7 @@ import de.pixart.messenger.utils.Compatibility; import de.pixart.messenger.utils.GeoHelper; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xmpp.XmppConnection; +import rocks.xmpp.addr.Jid; public class NotificationService { @@ -636,15 +639,54 @@ public class NotificationService { } } + private Person getPerson(Message message) { + final Contact contact = message.getContact(); + final Person.Builder builder = new Person.Builder(); + if (contact != null) { + builder.setName(contact.getDisplayName()); + final Uri uri = contact.getSystemAccount(); + if (uri != null) { + builder.setUri(uri.toString()); + } + } else { + builder.setName(UIHelper.getMessageDisplayName(message)); + } + IconCompat icon = getIcon(message); + if (icon != null) { + builder.setIcon(icon); + } + return builder.build(); + } + + private IconCompat getIcon(Message message) { + final Contact contact; + if (message.getConversation().getMode() == Conversation.MODE_SINGLE) { + contact = message.getContact(); + } else { + Jid jid = message.getTrueCounterpart(); + contact = jid == null ? null : message.getConversation().getAccount().getRoster().getContact(jid); + } + if (contact != null) { + if (contact.getProfilePhoto() != null && QuickConversationsService.isConversations()) { + return IconCompat.createWithContentUri(contact.getProfilePhoto()); + } + if (contact.getAvatarFilename() != null) { + return IconCompat.createWithContentUri(mXmppConnectionService.getFileBackend().getAvatarUri(contact.getAvatarFilename())); + } + } + return null; + } + private void modifyForTextOnly(final Builder builder, final UnreadConversation.Builder uBuilder, final ArrayList<Message> messages) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(mXmppConnectionService.getString(R.string.me)); + final Person me = new Person.Builder().setName(mXmppConnectionService.getString(R.string.me)).build(); + NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(me); final Conversation conversation = (Conversation) messages.get(0).getConversation(); if (conversation.getMode() == Conversation.MODE_MULTI) { messagingStyle.setConversationTitle(conversation.getName()); } for (Message message : messages) { - String sender = message.getStatus() == Message.STATUS_RECEIVED ? UIHelper.getMessageDisplayName(message) : null; + final Person sender = message.getStatus() == Message.STATUS_RECEIVED ? getPerson(message) : null; messagingStyle.addMessage(UIHelper.getMessagePreview(mXmppConnectionService, message).first, message.getTimeSent(), sender); } builder.setStyle(messagingStyle); |