More Contact Picture refactors

Use polymorphism to avoid dynamic dispatch based on nulled parameters.
Next up: Prettier MUC icons
This commit is contained in:
andy 2014-04-12 01:36:44 +02:00
parent 3d6f03e859
commit c230733736
5 changed files with 40 additions and 17 deletions

View file

@ -164,8 +164,7 @@ public class ConversationActivity extends XmppActivity {
ImageView imageView = (ImageView) view ImageView imageView = (ImageView) view
.findViewById(R.id.conversation_image); .findViewById(R.id.conversation_image);
imageView.setImageBitmap(UIHelper.getContactPicture( imageView.setImageBitmap(UIHelper.getContactPicture(
conv.getContact(), conv.getName(useSubject), 200, conv, 200, activity.getApplicationContext()));
activity.getApplicationContext()));
return view; return view;
} }

View file

@ -614,7 +614,12 @@ public class ConversationFragment extends Fragment {
if (bitmaps.containsKey(name)) { if (bitmaps.containsKey(name)) {
return bitmaps.get(name); return bitmaps.get(name);
} else { } else {
Bitmap bm = UIHelper.getContactPicture(contact, name, 200, context); Bitmap bm;
if (contact != null){
bm = UIHelper.getContactPicture(contact, 200, context);
} else {
bm = UIHelper.getContactPicture(name, 200, context);
}
bitmaps.put(name, bm); bitmaps.put(name, bm);
return bm; return bm;
} }

View file

@ -179,7 +179,7 @@ public class MucDetailsActivity extends XmppActivity {
role.setText(getReadableRole(contact.getRole())); role.setText(getReadableRole(contact.getRole()));
ImageView imageView = (ImageView) view ImageView imageView = (ImageView) view
.findViewById(R.id.contact_photo); .findViewById(R.id.contact_photo);
imageView.setImageBitmap(UIHelper.getContactPicture(null,contact.getName(), 90,this.getApplicationContext())); imageView.setImageBitmap(UIHelper.getContactPicture(contact.getName(), 89,this.getApplicationContext()));
membersView.addView(view); membersView.addView(view);
} }
} }

View file

@ -81,7 +81,9 @@ public class ShareWithActivity extends XmppActivity {
} }
}); });
for(final Conversation conversation : convList) { for(final Conversation conversation : convList) {
View view = createContactView(conversation.getName(useSubject), conversation.getLatestMessage().getBody().trim(), UIHelper.getContactPicture(conversation.getContact(),conversation.getName(useSubject), 90,this.getApplicationContext())); View view = createContactView(conversation.getName(useSubject),
conversation.getLatestMessage().getBody().trim(),
UIHelper.getContactPicture(conversation, 90,this.getApplicationContext()));
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@Override @Override
@ -115,7 +117,8 @@ public class ShareWithActivity extends XmppActivity {
for(int i = 0; i < contactsList.size(); ++i) { for(int i = 0; i < contactsList.size(); ++i) {
final Contact con = contactsList.get(i); final Contact con = contactsList.get(i);
View view = createContactView(con.getDisplayName(), con.getJid(), UIHelper.getContactPicture(con,null, 90,this.getApplicationContext())); View view = createContactView(con.getDisplayName(), con.getJid(),
UIHelper.getContactPicture(con, 90, this.getApplicationContext()));
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@Override @Override

View file

@ -91,23 +91,39 @@ public class UIHelper {
return bitmap; return bitmap;
} }
public static Bitmap getContactPicture(Contact contact, String fallback, int size, Context context) { public static Bitmap getContactPicture(Conversation conversation, int size, Context context) {
if (contact==null) { if(conversation.getMode() == Conversation.MODE_SINGLE) {
return getUnknownContactPicture(fallback, size); 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(); String uri = contact.getProfilePhoto();
if (uri==null) { if (uri==null) {
return getUnknownContactPicture(contact.getDisplayName(), size); return getContactPicture(contact.getDisplayName(), size);
} }
try { try {
Bitmap bm = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(Uri.parse(uri))); Bitmap bm = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(Uri.parse(uri)));
return Bitmap.createScaledBitmap(bm, size, size, false); return Bitmap.createScaledBitmap(bm, size, size, false);
} catch (FileNotFoundException e) { } 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) { public static Bitmap getErrorPicture(int size) {
Bitmap bitmap = Bitmap Bitmap bitmap = Bitmap
.createBitmap(size, size, Bitmap.Config.ARGB_8888); .createBitmap(size, size, Bitmap.Config.ARGB_8888);
@ -212,7 +228,7 @@ public class UIHelper {
} else if (unread.size() == 1) { } else if (unread.size() == 1) {
Conversation conversation = unread.get(0); Conversation conversation = unread.get(0);
targetUuid = conversation.getUuid(); 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)); .getDimension(android.R.dimen.notification_large_icon_width), context));
mBuilder.setContentTitle(conversation.getName(useSubject)); mBuilder.setContentTitle(conversation.getName(useSubject));
if (notify) { if (notify) {
@ -313,7 +329,7 @@ public class UIHelper {
long id = Long.parseLong(systemAccount[0]); long id = Long.parseLong(systemAccount[0]);
badge.assignContactUri(Contacts.getLookupUri(id, systemAccount[1])); 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( public static AlertDialog getVerifyFingerprintDialog(
@ -357,12 +373,12 @@ public class UIHelper {
return BitmapFactory.decodeStream(activity return BitmapFactory.decodeStream(activity
.getContentResolver().openInputStream(selfiUri)); .getContentResolver().openInputStream(selfiUri));
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
return getUnknownContactPicture(account.getJid(), size); return getContactPicture(account.getJid(), size);
} }
} }
return getUnknownContactPicture(account.getJid(), size); return getContactPicture(account.getJid(), size);
} else { } else {
return getUnknownContactPicture(account.getJid(), size); return getContactPicture(account.getJid(), size);
} }
} }
} }