1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
package eu.siacs.conversations.ui.adapter;
import java.util.List;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ConversationActivity;
import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.utils.UIHelper;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class ConversationAdapter extends ArrayAdapter<Conversation> {
private XmppActivity activity;
public ConversationAdapter(XmppActivity activity,
List<Conversation> conversations) {
super(activity, 0, conversations);
this.activity = activity;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (View) inflater.inflate(R.layout.conversation_list_row,
parent, false);
}
Conversation conv = getItem(position);
if (this.activity instanceof ConversationActivity) {
ConversationActivity activity = (ConversationActivity) this.activity;
if (!activity.getSlidingPaneLayout().isSlideable()) {
if (conv == activity.getSelectedConversation()) {
view.setBackgroundColor(0xffdddddd);
} else {
view.setBackgroundColor(Color.TRANSPARENT);
}
} else {
view.setBackgroundColor(Color.TRANSPARENT);
}
}
TextView convName = (TextView) view
.findViewById(R.id.conversation_name);
convName.setText(conv.getName());
TextView convLastMsg = (TextView) view
.findViewById(R.id.conversation_lastmsg);
ImageView imagePreview = (ImageView) view
.findViewById(R.id.conversation_lastimage);
Message latestMessage = conv.getLatestMessage();
if (latestMessage.getType() == Message.TYPE_TEXT
|| latestMessage.getType() == Message.TYPE_PRIVATE) {
if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP)
&& (latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
convLastMsg.setText(UIHelper.transformAsciiEmoticons(conv.getLatestMessage().getBody()));
} else {
convLastMsg.setText(activity
.getText(R.string.encrypted_message_received));
}
convLastMsg.setVisibility(View.VISIBLE);
imagePreview.setVisibility(View.GONE);
} else if (latestMessage.getType() == Message.TYPE_IMAGE) {
if (latestMessage.getStatus() >= Message.STATUS_RECEIVED) {
convLastMsg.setVisibility(View.GONE);
imagePreview.setVisibility(View.VISIBLE);
activity.loadBitmap(latestMessage, imagePreview);
} else {
convLastMsg.setVisibility(View.VISIBLE);
imagePreview.setVisibility(View.GONE);
if (latestMessage.getStatus() == Message.STATUS_RECEIVED_OFFER) {
convLastMsg.setText(activity
.getText(R.string.image_offered_for_download));
} else if (latestMessage.getStatus() == Message.STATUS_RECEIVING) {
convLastMsg.setText(activity
.getText(R.string.receiving_image));
} else {
convLastMsg.setText("");
}
}
}
if (!conv.isRead()) {
convName.setTypeface(null, Typeface.BOLD);
convLastMsg.setTypeface(null, Typeface.BOLD);
} else {
convName.setTypeface(null, Typeface.NORMAL);
convLastMsg.setTypeface(null, Typeface.NORMAL);
}
((TextView) view.findViewById(R.id.conversation_lastupdate))
.setText(UIHelper.readableTimeDifference(getContext(), conv
.getLatestMessage().getTimeSent()));
ImageView profilePicture = (ImageView) view
.findViewById(R.id.conversation_image);
profilePicture.setImageBitmap(conv.getImage(activity, 56));
return view;
}
}
|