diff options
author | andy <andy@strb.org> | 2014-04-12 01:36:44 +0200 |
---|---|---|
committer | andy <andy@strb.org> | 2014-04-12 03:46:54 +0200 |
commit | c2307337368e37fc3c7fec7d4b2e5cdf3be47212 (patch) | |
tree | adc61cb40591a84ee0228f8b5167afbd4d7f73da /src/eu/siacs/conversations/utils | |
parent | 3d6f03e859cfc4727c68bfda424b58228f4ffa61 (diff) |
More Contact Picture refactors
Use polymorphism to avoid dynamic dispatch based on nulled parameters.
Next up: Prettier MUC icons
Diffstat (limited to 'src/eu/siacs/conversations/utils')
-rw-r--r-- | src/eu/siacs/conversations/utils/UIHelper.java | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index 0d0e7b91..7654b33f 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -91,23 +91,39 @@ public class UIHelper { return bitmap; } - - public static Bitmap getContactPicture(Contact contact, String fallback, int size, Context context) { - if (contact==null) { - return getUnknownContactPicture(fallback, size); + + public static Bitmap getContactPicture(Conversation conversation, int size, Context context) { + if(conversation.getMode() == Conversation.MODE_SINGLE) { + if (conversation.getContact() != null){ + return getContactPicture(conversation.getContact(), size, context); + } else { + return getContactPicture(conversation.getName(false), size); + } + } else{ + return getContactPicture(conversation.getName(false), size); } + } + + public static Bitmap getContactPicture(Contact contact, int size, Context context) { String uri = contact.getProfilePhoto(); if (uri==null) { - return getUnknownContactPicture(contact.getDisplayName(), size); + return getContactPicture(contact.getDisplayName(), size); } try { Bitmap bm = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(Uri.parse(uri))); return Bitmap.createScaledBitmap(bm, size, size, false); } catch (FileNotFoundException e) { - return getUnknownContactPicture(contact.getDisplayName(), size); + return getContactPicture(contact.getDisplayName(), size); } } + public static Bitmap getContactPicture(String name, int size, Context context) { + return getContactPicture(name, size); + } + + public static Bitmap getContactPicture(String name, int size) { + return getUnknownContactPicture(name, size); + } public static Bitmap getErrorPicture(int size) { Bitmap bitmap = Bitmap .createBitmap(size, size, Bitmap.Config.ARGB_8888); @@ -212,7 +228,7 @@ public class UIHelper { } else if (unread.size() == 1) { Conversation conversation = unread.get(0); targetUuid = conversation.getUuid(); - mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation.getContact(), conversation.getName(useSubject), (int) res + mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation, (int) res .getDimension(android.R.dimen.notification_large_icon_width), context)); mBuilder.setContentTitle(conversation.getName(useSubject)); if (notify) { @@ -313,7 +329,7 @@ public class UIHelper { long id = Long.parseLong(systemAccount[0]); badge.assignContactUri(Contacts.getLookupUri(id, systemAccount[1])); } - badge.setImageBitmap(UIHelper.getContactPicture(contact, "", 400, context)); + badge.setImageBitmap(UIHelper.getContactPicture(contact, 400, context)); } public static AlertDialog getVerifyFingerprintDialog( @@ -357,12 +373,12 @@ public class UIHelper { return BitmapFactory.decodeStream(activity .getContentResolver().openInputStream(selfiUri)); } catch (FileNotFoundException e) { - return getUnknownContactPicture(account.getJid(), size); + return getContactPicture(account.getJid(), size); } } - return getUnknownContactPicture(account.getJid(), size); + return getContactPicture(account.getJid(), size); } else { - return getUnknownContactPicture(account.getJid(), size); + return getContactPicture(account.getJid(), size); } } } |