From 6b50aad97951561dca537ef5e3094b59a8c76ed1 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 24 Jan 2019 20:46:02 +0100 Subject: use bitmap instead of URI for avatars in notification --- .../messenger/services/NotificationService.java | 35 +++++----------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'src/main/java/de/pixart/messenger/services/NotificationService.java') diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index 83441cce1..5e165567f 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -523,14 +523,14 @@ public class NotificationService { if (messages.size() >= 1) { final Conversation conversation = (Conversation) messages.get(0).getConversation(); final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName().toString()); - mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService() - .get(conversation, getPixel(64))); + mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService().get(conversation, AvatarService.getSystemUiAvatarSize(mXmppConnectionService))); mBuilder.setContentTitle(conversation.getName()); if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) { int count = messages.size(); mBuilder.setContentText(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count)); } else { Message message; + //TODO starting with Android 9 we might want to put images in MessageStyle if ((message = getImage(messages)) != null) { modifyForImage(mBuilder, mUnreadBuilder, message, messages); } else { @@ -615,8 +615,7 @@ public class NotificationService { private void modifyForImage(final Builder builder, final UnreadConversation.Builder uBuilder, final Message message, final ArrayList messages) { try { - final Bitmap bitmap = mXmppConnectionService.getFileBackend() - .getThumbnail(message, getPixel(288), false); + final Bitmap bitmap = mXmppConnectionService.getFileBackend().getThumbnail(message, getPixel(288), false); final ArrayList tmp = new ArrayList<>(); for (final Message msg : messages) { if (msg.getType() == Message.TYPE_TEXT @@ -651,44 +650,26 @@ public class NotificationService { } else { builder.setName(UIHelper.getMessageDisplayName(message)); } - IconCompat icon = getIcon(message); - if (icon != null) { - builder.setIcon(icon); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + builder.setIcon(IconCompat.createWithBitmap(mXmppConnectionService.getAvatarService().get(message, AvatarService.getSystemUiAvatarSize(mXmppConnectionService), false))); } 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 messages) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 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) { + final boolean multiple = conversation.getMode() == Conversation.MODE_MULTI; + if (multiple) { messagingStyle.setConversationTitle(conversation.getName()); } for (Message message : messages) { final Person sender = message.getStatus() == Message.STATUS_RECEIVED ? getPerson(message) : null; messagingStyle.addMessage(UIHelper.getMessagePreview(mXmppConnectionService, message).first, message.getTimeSent(), sender); } + messagingStyle.setGroupConversation(multiple); builder.setStyle(messagingStyle); } else { if (messages.get(0).getConversation().getMode() == Conversation.MODE_SINGLE) { -- cgit v1.2.3