2014-08-15 11:18:15 +00:00
|
|
|
package eu.siacs.conversations.ui.adapter;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2014-10-15 17:32:12 +00:00
|
|
|
import eu.siacs.conversations.entities.Downloadable;
|
2014-11-14 16:39:03 +00:00
|
|
|
import eu.siacs.conversations.entities.DownloadableFile;
|
2014-08-15 11:18:15 +00:00
|
|
|
import eu.siacs.conversations.entities.Message;
|
|
|
|
import eu.siacs.conversations.ui.ConversationActivity;
|
2014-09-02 13:51:20 +00:00
|
|
|
import eu.siacs.conversations.ui.XmppActivity;
|
2014-08-15 11:18:15 +00:00
|
|
|
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> {
|
|
|
|
|
2014-09-02 13:51:20 +00:00
|
|
|
private XmppActivity activity;
|
2014-08-15 11:18:15 +00:00
|
|
|
|
2014-09-02 13:51:20 +00:00
|
|
|
public ConversationAdapter(XmppActivity activity,
|
2014-08-15 11:18:15 +00:00
|
|
|
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);
|
2014-10-26 17:54:10 +00:00
|
|
|
view = inflater.inflate(R.layout.conversation_list_row,
|
2014-08-15 11:18:15 +00:00
|
|
|
parent, false);
|
|
|
|
}
|
2014-10-15 17:32:12 +00:00
|
|
|
Conversation conversation = getItem(position);
|
2014-09-02 13:51:20 +00:00
|
|
|
if (this.activity instanceof ConversationActivity) {
|
|
|
|
ConversationActivity activity = (ConversationActivity) this.activity;
|
2014-10-03 13:00:29 +00:00
|
|
|
if (!activity.isConversationsOverviewHideable()) {
|
2014-10-15 17:32:12 +00:00
|
|
|
if (conversation == activity.getSelectedConversation()) {
|
2014-10-05 22:33:52 +00:00
|
|
|
view.setBackgroundColor(activity
|
|
|
|
.getSecondaryBackgroundColor());
|
2014-09-02 13:51:20 +00:00
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(Color.TRANSPARENT);
|
|
|
|
}
|
2014-08-15 11:18:15 +00:00
|
|
|
} else {
|
|
|
|
view.setBackgroundColor(Color.TRANSPARENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TextView convName = (TextView) view
|
|
|
|
.findViewById(R.id.conversation_name);
|
2014-10-15 17:32:12 +00:00
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE
|
2014-09-28 13:21:56 +00:00
|
|
|
|| activity.useSubjectToIdentifyConference()) {
|
2014-10-15 17:32:12 +00:00
|
|
|
convName.setText(conversation.getName());
|
2014-09-22 11:23:35 +00:00
|
|
|
} else {
|
2014-11-06 19:45:38 +00:00
|
|
|
convName.setText(conversation.getContactJid().toBareJid().toString());
|
2014-09-22 11:23:35 +00:00
|
|
|
}
|
2014-10-15 17:32:12 +00:00
|
|
|
TextView mLastMessage = (TextView) view
|
2014-08-15 11:18:15 +00:00
|
|
|
.findViewById(R.id.conversation_lastmsg);
|
2014-10-15 17:32:12 +00:00
|
|
|
TextView mTimestamp = (TextView) view
|
|
|
|
.findViewById(R.id.conversation_lastupdate);
|
2014-08-15 11:18:15 +00:00
|
|
|
ImageView imagePreview = (ImageView) view
|
|
|
|
.findViewById(R.id.conversation_lastimage);
|
|
|
|
|
2014-10-15 17:32:12 +00:00
|
|
|
Message message = conversation.getLatestMessage();
|
2014-08-15 11:18:15 +00:00
|
|
|
|
2014-10-15 17:32:12 +00:00
|
|
|
if (!conversation.isRead()) {
|
|
|
|
convName.setTypeface(null, Typeface.BOLD);
|
|
|
|
} else {
|
|
|
|
convName.setTypeface(null, Typeface.NORMAL);
|
|
|
|
}
|
|
|
|
|
2014-11-14 16:39:03 +00:00
|
|
|
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE
|
2014-10-15 17:32:12 +00:00
|
|
|
|| message.getDownloadable() != null) {
|
|
|
|
Downloadable d = message.getDownloadable();
|
2014-10-24 11:29:18 +00:00
|
|
|
if (conversation.isRead()) {
|
|
|
|
mLastMessage.setTypeface(null, Typeface.ITALIC);
|
|
|
|
} else {
|
|
|
|
mLastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
|
|
|
|
}
|
2014-10-15 17:32:12 +00:00
|
|
|
if (d != null) {
|
|
|
|
mLastMessage.setVisibility(View.VISIBLE);
|
2014-08-15 11:18:15 +00:00
|
|
|
imagePreview.setVisibility(View.GONE);
|
2014-10-15 17:32:12 +00:00
|
|
|
if (d.getStatus() == Downloadable.STATUS_CHECKING) {
|
|
|
|
mLastMessage.setText(R.string.checking_image);
|
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
|
2014-11-14 16:39:03 +00:00
|
|
|
if (message.getType() == Message.TYPE_FILE) {
|
|
|
|
mLastMessage.setText(getContext().getString(R.string.receiving_file,d.getMimeType(), d.getProgress()));
|
|
|
|
} else {
|
|
|
|
mLastMessage.setText(getContext().getString(R.string.receiving_image, d.getProgress()));
|
|
|
|
}
|
2014-10-15 17:32:12 +00:00
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_OFFER) {
|
2014-11-14 16:39:03 +00:00
|
|
|
if (message.getType() == Message.TYPE_FILE) {
|
|
|
|
mLastMessage.setText(R.string.file_offered_for_download);
|
|
|
|
} else {
|
|
|
|
mLastMessage.setText(R.string.image_offered_for_download);
|
|
|
|
}
|
2014-10-19 21:42:53 +00:00
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) {
|
|
|
|
mLastMessage.setText(R.string.image_offered_for_download);
|
2014-10-15 20:08:13 +00:00
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_DELETED) {
|
2014-11-15 13:40:43 +00:00
|
|
|
if (message.getType() == Message.TYPE_FILE) {
|
|
|
|
mLastMessage.setText(R.string.file_deleted);
|
|
|
|
} else {
|
|
|
|
mLastMessage.setText(R.string.image_file_deleted);
|
|
|
|
}
|
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_FAILED) {
|
|
|
|
if (message.getType() == Message.TYPE_FILE) {
|
|
|
|
mLastMessage.setText(R.string.file_transmission_failed);
|
|
|
|
} else {
|
|
|
|
mLastMessage.setText(R.string.image_transmission_failed);
|
|
|
|
}
|
2014-11-14 16:39:03 +00:00
|
|
|
} else if (message.getImageParams().width > 0) {
|
|
|
|
mLastMessage.setVisibility(View.GONE);
|
|
|
|
imagePreview.setVisibility(View.VISIBLE);
|
|
|
|
activity.loadBitmap(message, imagePreview);
|
2014-08-15 11:18:15 +00:00
|
|
|
} else {
|
2014-10-15 17:32:12 +00:00
|
|
|
mLastMessage.setText("");
|
2014-08-15 11:18:15 +00:00
|
|
|
}
|
2014-10-24 11:29:18 +00:00
|
|
|
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
2014-10-24 12:34:46 +00:00
|
|
|
imagePreview.setVisibility(View.GONE);
|
|
|
|
mLastMessage.setVisibility(View.VISIBLE);
|
2014-10-24 11:29:18 +00:00
|
|
|
mLastMessage.setText(R.string.encrypted_message_received);
|
2014-11-14 16:39:03 +00:00
|
|
|
} else if (message.getType() == Message.TYPE_FILE && message.getImageParams().width <= 0) {
|
|
|
|
DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
|
|
|
|
mLastMessage.setVisibility(View.VISIBLE);
|
|
|
|
imagePreview.setVisibility(View.GONE);
|
|
|
|
mLastMessage.setText(getContext().getString(R.string.file,file.getMimeType()));
|
2014-10-15 17:32:12 +00:00
|
|
|
} else {
|
|
|
|
mLastMessage.setVisibility(View.GONE);
|
|
|
|
imagePreview.setVisibility(View.VISIBLE);
|
|
|
|
activity.loadBitmap(message, imagePreview);
|
2014-08-15 11:18:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-10-15 17:32:12 +00:00
|
|
|
if ((message.getEncryption() != Message.ENCRYPTION_PGP)
|
|
|
|
&& (message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
|
2014-12-09 13:21:35 +00:00
|
|
|
mLastMessage.setText(message.getBody());
|
2014-10-15 17:32:12 +00:00
|
|
|
} else {
|
|
|
|
mLastMessage.setText(R.string.encrypted_message_received);
|
|
|
|
}
|
|
|
|
if (!conversation.isRead()) {
|
|
|
|
mLastMessage.setTypeface(null, Typeface.BOLD);
|
|
|
|
} else {
|
|
|
|
mLastMessage.setTypeface(null, Typeface.NORMAL);
|
|
|
|
}
|
|
|
|
mLastMessage.setVisibility(View.VISIBLE);
|
|
|
|
imagePreview.setVisibility(View.GONE);
|
2014-08-15 11:18:15 +00:00
|
|
|
}
|
2014-10-15 17:32:12 +00:00
|
|
|
mTimestamp.setText(UIHelper.readableTimeDifference(getContext(),
|
|
|
|
conversation.getLatestMessage().getTimeSent()));
|
2014-08-15 11:18:15 +00:00
|
|
|
|
|
|
|
ImageView profilePicture = (ImageView) view
|
|
|
|
.findViewById(R.id.conversation_image);
|
2014-10-21 12:57:16 +00:00
|
|
|
profilePicture.setImageBitmap(activity.avatarService().get(
|
|
|
|
conversation, activity.getPixel(56)));
|
2014-08-15 11:18:15 +00:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|