diff options
Diffstat (limited to 'src/eu/siacs/conversations/ui')
-rw-r--r-- | src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java | 86 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/adapter/MessageAdapter.java | 67 |
2 files changed, 90 insertions, 63 deletions
diff --git a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 56903da8..c22dd26f 100644 --- a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -7,6 +7,8 @@ import org.openintents.openpgp.util.OpenPgpUtils; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions.OnRenameListener; @@ -54,7 +56,7 @@ public class ConferenceDetailsActivity extends XmppActivity { private List<User> users = new ArrayList<MucOptions.User>(); private OnConversationUpdate onConvChanged = new OnConversationUpdate() { - + @Override public void onConversationUpdate() { runOnUiThread(new Runnable() { @@ -150,13 +152,14 @@ public class ConferenceDetailsActivity extends XmppActivity { this.uuid = getIntent().getExtras().getString("uuid"); } if (uuid != null) { - this.conversation = xmppConnectionService.findConversationByUuid(uuid); + this.conversation = xmppConnectionService + .findConversationByUuid(uuid); if (this.conversation != null) { populateView(); } } } - + @Override protected void onStop() { if (xmppConnectionServiceBound) { @@ -164,33 +167,34 @@ public class ConferenceDetailsActivity extends XmppActivity { } super.onStop(); } - + protected void registerListener() { if (xmppConnectionServiceBound) { xmppConnectionService .setOnConversationListChangedListener(this.onConvChanged); - xmppConnectionService.setOnRenameListener(new OnRenameListener() { + xmppConnectionService.setOnRenameListener(new OnRenameListener() { - @Override - public void onRename(final boolean success) { - runOnUiThread(new Runnable() { + @Override + public void onRename(final boolean success) { + runOnUiThread(new Runnable() { - @Override - public void run() { - populateView(); - if (success) { - Toast.makeText(ConferenceDetailsActivity.this, - getString(R.string.your_nick_has_been_changed), - Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(ConferenceDetailsActivity.this, - getString(R.string.nick_in_use), - Toast.LENGTH_SHORT).show(); + @Override + public void run() { + populateView(); + if (success) { + Toast.makeText( + ConferenceDetailsActivity.this, + getString(R.string.your_nick_has_been_changed), + Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(ConferenceDetailsActivity.this, + getString(R.string.nick_in_use), + Toast.LENGTH_SHORT).show(); + } } - } - }); - } - }); + }); + } + }); } } @@ -222,28 +226,42 @@ public class ConferenceDetailsActivity extends XmppActivity { this.users.addAll(conversation.getMucOptions().getUsers()); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); membersView.removeAllViews(); - for (final User contact : conversation.getMucOptions().getUsers()) { - View view = (View) inflater.inflate(R.layout.contact, null); - TextView displayName = (TextView) view + Account account = conversation.getAccount(); + for (final User user : conversation.getMucOptions().getUsers()) { + View view = (View) inflater.inflate(R.layout.contact, membersView, + false); + TextView name = (TextView) view .findViewById(R.id.contact_display_name); TextView key = (TextView) view.findViewById(R.id.key); - displayName.setText(contact.getName()); TextView role = (TextView) view.findViewById(R.id.contact_jid); - role.setText(getReadableRole(contact.getRole())); - if (contact.getPgpKeyId() != 0) { + role.setText(getReadableRole(user.getRole())); + if (user.getPgpKeyId() != 0) { key.setVisibility(View.VISIBLE); key.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - viewPgpKey(contact); + viewPgpKey(user); } }); - key.setText(OpenPgpUtils.convertKeyIdToHex(contact - .getPgpKeyId())); + key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId())); + } + Bitmap bm; + if (user.getJid() != null) { + Contact contact = account.getRoster().getContact(user.getJid()); + if (contact.showInRoster()) { + bm = contact.getImage(48, this); + name.setText(contact.getDisplayName()); + } else { + bm = UIHelper.getContactPicture(user.getName(), 48, this, + false); + name.setText(user.getName()); + } + } else { + bm = UIHelper + .getContactPicture(user.getName(), 48, this, false); + name.setText(user.getName()); } - Bitmap bm = UIHelper.getContactPicture(contact.getName(), 48, this, - false); ImageView iv = (ImageView) view.findViewById(R.id.contact_photo); iv.setImageBitmap(bm); membersView.addView(view); diff --git a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 0a2857d2..8489de2e 100644 --- a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -42,17 +42,12 @@ public class MessageAdapter extends ArrayAdapter<Message> { private BitmapCache mBitmapCache = new BitmapCache(); private DisplayMetrics metrics; - private boolean useSubject = true; - private OnContactPictureClicked mOnContactPictureClickedListener; public MessageAdapter(ConversationActivity activity, List<Message> messages) { super(activity, 0, messages); this.activity = activity; metrics = getContext().getResources().getDisplayMetrics(); - SharedPreferences preferences = PreferenceManager - .getDefaultSharedPreferences(getContext()); - useSubject = preferences.getBoolean("use_subject_in_muc", true); } private Bitmap getSelfBitmap() { @@ -130,7 +125,12 @@ public class MessageAdapter extends ArrayAdapter<Message> { error = true; default: if (multiReceived) { - info = message.getCounterpart(); + Contact contact = message.getContact(); + if (contact != null) { + info = contact.getDisplayName(); + } else { + info = message.getCounterpart(); + } } break; } @@ -277,7 +277,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { switch (type) { case SENT: view = (View) activity.getLayoutInflater().inflate( - R.layout.message_sent, null); + R.layout.message_sent, parent,false); viewHolder.message_box = (LinearLayout) view .findViewById(R.id.message_box); viewHolder.contact_picture = (ImageView) view @@ -295,7 +295,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { break; case RECIEVED: view = (View) activity.getLayoutInflater().inflate( - R.layout.message_recieved, null); + R.layout.message_recieved, parent,false); viewHolder.message_box = (LinearLayout) view .findViewById(R.id.message_box); viewHolder.contact_picture = (ImageView) view @@ -307,9 +307,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { viewHolder.contact_picture.setImageBitmap(mBitmapCache.get( - item.getConversation().getName(useSubject), item - .getConversation().getContact(), - getContext())); + item.getConversation().getContact(), getContext())); } viewHolder.indicator = (ImageView) view @@ -324,15 +322,13 @@ public class MessageAdapter extends ArrayAdapter<Message> { break; case STATUS: view = (View) activity.getLayoutInflater().inflate( - R.layout.message_status, null); + R.layout.message_status, parent,false); viewHolder.contact_picture = (ImageView) view .findViewById(R.id.message_photo); if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { viewHolder.contact_picture.setImageBitmap(mBitmapCache.get( - item.getConversation().getName(useSubject), item - .getConversation().getContact(), - getContext())); + item.getConversation().getContact(), getContext())); viewHolder.contact_picture.setAlpha(128); viewHolder.contact_picture .setOnClickListener(new OnClickListener() { @@ -366,8 +362,14 @@ public class MessageAdapter extends ArrayAdapter<Message> { if (type == RECIEVED) { if (item.getConversation().getMode() == Conversation.MODE_MULTI) { - viewHolder.contact_picture.setImageBitmap(mBitmapCache.get( - item.getCounterpart(), null, getContext())); + Contact contact = item.getContact(); + if (contact != null) { + viewHolder.contact_picture.setImageBitmap(mBitmapCache.get( + contact, getContext())); + } else { + viewHolder.contact_picture.setImageBitmap(mBitmapCache.get( + item.getCounterpart(), getContext())); + } viewHolder.contact_picture .setOnClickListener(new OnClickListener() { @@ -453,20 +455,27 @@ public class MessageAdapter extends ArrayAdapter<Message> { } private class BitmapCache { - private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>(); + private HashMap<String, Bitmap> contactBitmaps = new HashMap<String, Bitmap>(); + private HashMap<String, Bitmap> unknownBitmaps = new HashMap<String, Bitmap>(); - public Bitmap get(String name, Contact contact, Context context) { - if (bitmaps.containsKey(name)) { - return bitmaps.get(name); + public Bitmap get(Contact contact, Context context) { + if (contactBitmaps.containsKey(contact.getJid())) { + return contactBitmaps.get(contact.getJid()); } else { - Bitmap bm; - if (contact != null) { - bm = UIHelper - .getContactPicture(contact, 48, context, false); - } else { - bm = UIHelper.getContactPicture(name, 48, context, false); - } - bitmaps.put(name, bm); + Bitmap bm = UIHelper.getContactPicture(contact, 48, context, + false); + contactBitmaps.put(contact.getJid(), bm); + return bm; + } + } + + public Bitmap get(String name, Context context) { + if (unknownBitmaps.containsKey(name)) { + return unknownBitmaps.get(name); + } else { + Bitmap bm = UIHelper + .getContactPicture(name, 48, context, false); + unknownBitmaps.put(name, bm); return bm; } } |