diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-01-24 20:46:02 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-01-24 20:46:02 +0100 |
commit | 6b50aad97951561dca537ef5e3094b59a8c76ed1 (patch) | |
tree | 836803b7328dffd7aa5f986d5af18626fa75ee4b /src/main/java | |
parent | 6d5c7fd4d625bc453e487335330282d4481c19ac (diff) |
use bitmap instead of URI for avatars in notification
Diffstat (limited to 'src/main/java')
4 files changed, 17 insertions, 28 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index ce65587b7..5ad1f873c 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -85,6 +85,7 @@ public final class Config { public static final int FILE_SIZE = 1048576; // 1 MiB public static final int AVATAR_SIZE = 480; + public static final int SYSTEM_UI_AVATAR_SIZE = 48; public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.JPEG; public static final int AVATAR_CHAR_LIMIT = 9400; diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java index 23e2da4d6..93d24a63f 100644 --- a/src/main/java/de/pixart/messenger/services/AvatarService.java +++ b/src/main/java/de/pixart/messenger/services/AvatarService.java @@ -1,5 +1,6 @@ package de.pixart.messenger.services; +import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -42,6 +43,8 @@ import de.pixart.messenger.xmpp.OnAdvancedStreamFeaturesLoaded; import de.pixart.messenger.xmpp.XmppConnection; import rocks.xmpp.addr.Jid; +import static de.pixart.messenger.Config.SYSTEM_UI_AVATAR_SIZE; + public class AvatarService implements OnAdvancedStreamFeaturesLoaded { private static final int FG_COLOR = 0xFFFAFAFA; @@ -75,6 +78,10 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { return value == null ? "" : value.toString(); } + public static int getSystemUiAvatarSize(final Context context) { + return (int) (SYSTEM_UI_AVATAR_SIZE * context.getResources().getDisplayMetrics().density); + } + private Bitmap get(final Contact contact, final int size, boolean cachedOnly) { if (contact.isSelf()) { return get(contact.getAccount(), size, cachedOnly); diff --git a/src/main/java/de/pixart/messenger/services/ContactChooserTargetService.java b/src/main/java/de/pixart/messenger/services/ContactChooserTargetService.java index 4c0aec3ca..e4a98d63a 100644 --- a/src/main/java/de/pixart/messenger/services/ContactChooserTargetService.java +++ b/src/main/java/de/pixart/messenger/services/ContactChooserTargetService.java @@ -42,7 +42,7 @@ public class ContactChooserTargetService extends ChooserTargetService implements } mXmppConnectionService.populateWithOrderedConversations(conversations, false); final ComponentName componentName = new ComponentName(this, ConversationsActivity.class); - final int pixel = (int) (48 * getResources().getDisplayMetrics().density); + final int pixel = AvatarService.getSystemUiAvatarSize(this); for (Conversation conversation : conversations) { if (conversation.sentMessagesCount() == 0) { continue; 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<Message> messages) { try { - final Bitmap bitmap = mXmppConnectionService.getFileBackend() - .getThumbnail(message, getPixel(288), false); + final Bitmap bitmap = mXmppConnectionService.getFileBackend().getThumbnail(message, getPixel(288), false); final ArrayList<Message> 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<Message> 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) { |