aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-07-29 14:42:17 +0200
committeriNPUTmice <daniel@gultsch.de>2014-07-29 14:42:17 +0200
commit1521b91b27f13e5da4d4f9545fa2e99c28be42b8 (patch)
treeb4172e3209202eaa67fec2c81bccdc009a6780d8 /src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
parent861af75576385b030e4fe64e0410a2b36bcb0ed2 (diff)
fixed #239 - show contact names and pictures in muc if real jid is known
Diffstat (limited to 'src/eu/siacs/conversations/ui/adapter/MessageAdapter.java')
-rw-r--r--src/eu/siacs/conversations/ui/adapter/MessageAdapter.java67
1 files changed, 38 insertions, 29 deletions
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;
}
}