2014-07-22 13:31:54 +00:00
|
|
|
package eu.siacs.conversations.ui.adapter;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
2014-11-15 14:16:40 +00:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ResolveInfo;
|
2014-07-22 13:31:54 +00:00
|
|
|
import android.graphics.Typeface;
|
2014-11-13 20:04:05 +00:00
|
|
|
import android.net.Uri;
|
2014-08-22 11:22:07 +00:00
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.style.ForegroundColorSpan;
|
|
|
|
import android.text.style.StyleSpan;
|
2014-07-22 13:31:54 +00:00
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnLongClickListener;
|
2014-11-07 14:38:20 +00:00
|
|
|
import android.view.ViewGroup;
|
2014-07-22 13:31:54 +00:00
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2014-11-07 14:38:20 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.Config;
|
|
|
|
import eu.siacs.conversations.R;
|
2014-12-03 09:35:30 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2014-11-07 14:38:20 +00:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
|
|
|
import eu.siacs.conversations.entities.Downloadable;
|
2014-11-13 20:04:05 +00:00
|
|
|
import eu.siacs.conversations.entities.DownloadableFile;
|
2014-11-07 14:38:20 +00:00
|
|
|
import eu.siacs.conversations.entities.Message;
|
|
|
|
import eu.siacs.conversations.entities.Message.ImageParams;
|
|
|
|
import eu.siacs.conversations.ui.ConversationActivity;
|
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2014-11-07 14:32:22 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
2014-11-07 14:38:20 +00:00
|
|
|
|
2014-07-22 13:31:54 +00:00
|
|
|
public class MessageAdapter extends ArrayAdapter<Message> {
|
|
|
|
|
|
|
|
private static final int SENT = 0;
|
2014-08-28 14:49:52 +00:00
|
|
|
private static final int RECEIVED = 1;
|
2014-07-22 13:31:54 +00:00
|
|
|
private static final int STATUS = 2;
|
2014-08-31 12:29:12 +00:00
|
|
|
private static final int NULL = 3;
|
2014-07-22 13:31:54 +00:00
|
|
|
|
|
|
|
private ConversationActivity activity;
|
|
|
|
|
|
|
|
private DisplayMetrics metrics;
|
|
|
|
|
|
|
|
private OnContactPictureClicked mOnContactPictureClickedListener;
|
2014-08-10 13:27:44 +00:00
|
|
|
private OnContactPictureLongClicked mOnContactPictureLongClickedListener;
|
2014-07-22 13:31:54 +00:00
|
|
|
|
2014-10-23 19:27:41 +00:00
|
|
|
private OnLongClickListener openContextMenu = new OnLongClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
v.showContextMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-22 13:31:54 +00:00
|
|
|
public MessageAdapter(ConversationActivity activity, List<Message> messages) {
|
|
|
|
super(activity, 0, messages);
|
|
|
|
this.activity = activity;
|
|
|
|
metrics = getContext().getResources().getDisplayMetrics();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnContactPictureClicked(OnContactPictureClicked listener) {
|
|
|
|
this.mOnContactPictureClickedListener = listener;
|
|
|
|
}
|
2014-08-31 14:28:21 +00:00
|
|
|
|
|
|
|
public void setOnContactPictureLongClicked(
|
|
|
|
OnContactPictureLongClicked listener) {
|
2014-08-10 13:27:44 +00:00
|
|
|
this.mOnContactPictureLongClickedListener = listener;
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
2014-08-31 12:29:12 +00:00
|
|
|
return 4;
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
2014-08-31 12:29:12 +00:00
|
|
|
if (getItem(position).wasMergedIntoPrevious()) {
|
|
|
|
return NULL;
|
|
|
|
} else if (getItem(position).getType() == Message.TYPE_STATUS) {
|
2014-07-22 13:31:54 +00:00
|
|
|
return STATUS;
|
2014-08-28 09:01:24 +00:00
|
|
|
} else if (getItem(position).getStatus() <= Message.STATUS_RECEIVED) {
|
2014-08-28 14:49:52 +00:00
|
|
|
return RECEIVED;
|
2014-07-22 13:31:54 +00:00
|
|
|
} else {
|
|
|
|
return SENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void displayStatus(ViewHolder viewHolder, Message message) {
|
|
|
|
String filesize = null;
|
|
|
|
String info = null;
|
|
|
|
boolean error = false;
|
2014-09-20 13:49:25 +00:00
|
|
|
if (viewHolder.indicatorReceived != null) {
|
|
|
|
viewHolder.indicatorReceived.setVisibility(View.GONE);
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI
|
2014-08-31 16:55:15 +00:00
|
|
|
&& message.getMergedStatus() <= Message.STATUS_RECEIVED;
|
2014-11-13 21:59:00 +00:00
|
|
|
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getDownloadable() != null) {
|
2014-10-14 17:33:35 +00:00
|
|
|
ImageParams params = message.getImageParams();
|
2014-11-13 21:59:00 +00:00
|
|
|
if (params.size > (1.5 * 1024 * 1024)) {
|
|
|
|
filesize = params.size / (1024 * 1024)+ " MB";
|
|
|
|
} else if (params.size > 0) {
|
2014-10-14 17:33:35 +00:00
|
|
|
filesize = params.size / 1024 + " KB";
|
|
|
|
}
|
2014-10-29 10:31:03 +00:00
|
|
|
if (message.getDownloadable() != null && message.getDownloadable().getStatus() == Downloadable.STATUS_FAILED) {
|
|
|
|
error = true;
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2014-08-31 16:55:15 +00:00
|
|
|
switch (message.getMergedStatus()) {
|
2014-07-22 13:31:54 +00:00
|
|
|
case Message.STATUS_WAITING:
|
|
|
|
info = getContext().getString(R.string.waiting);
|
|
|
|
break;
|
|
|
|
case Message.STATUS_UNSEND:
|
2014-11-14 00:29:56 +00:00
|
|
|
Downloadable d = message.getDownloadable();
|
|
|
|
if (d!=null) {
|
|
|
|
info = getContext().getString(R.string.sending_file,d.getProgress());
|
|
|
|
} else {
|
|
|
|
info = getContext().getString(R.string.sending);
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
break;
|
|
|
|
case Message.STATUS_OFFERED:
|
|
|
|
info = getContext().getString(R.string.offering);
|
|
|
|
break;
|
2014-09-20 13:49:25 +00:00
|
|
|
case Message.STATUS_SEND_RECEIVED:
|
|
|
|
if (activity.indicateReceived()) {
|
|
|
|
viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Message.STATUS_SEND_DISPLAYED:
|
|
|
|
if (activity.indicateReceived()) {
|
|
|
|
viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
break;
|
2014-07-22 13:31:54 +00:00
|
|
|
case Message.STATUS_SEND_FAILED:
|
|
|
|
info = getContext().getString(R.string.send_failed);
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (multiReceived) {
|
2014-07-29 12:42:17 +00:00
|
|
|
Contact contact = message.getContact();
|
|
|
|
if (contact != null) {
|
|
|
|
info = contact.getDisplayName();
|
|
|
|
} else {
|
2014-11-09 17:24:01 +00:00
|
|
|
info = getDisplayedMucCounterpart(message.getCounterpart());
|
2014-07-29 12:42:17 +00:00
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error) {
|
2014-09-11 12:24:10 +00:00
|
|
|
viewHolder.time.setTextColor(activity.getWarningTextColor());
|
2014-07-22 13:31:54 +00:00
|
|
|
} else {
|
|
|
|
viewHolder.time.setTextColor(activity.getSecondaryTextColor());
|
|
|
|
}
|
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
|
|
|
|
viewHolder.indicator.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
viewHolder.indicator.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2014-09-21 21:16:23 +00:00
|
|
|
String formatedTime = UIHelper.readableTimeDifferenceFull(getContext(),
|
2014-08-31 16:55:15 +00:00
|
|
|
message.getMergedTimeSent());
|
2014-08-28 09:01:24 +00:00
|
|
|
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
2014-07-22 13:31:54 +00:00
|
|
|
if ((filesize != null) && (info != null)) {
|
|
|
|
viewHolder.time.setText(filesize + " \u00B7 " + info);
|
|
|
|
} else if ((filesize == null) && (info != null)) {
|
|
|
|
viewHolder.time.setText(formatedTime + " \u00B7 " + info);
|
|
|
|
} else if ((filesize != null) && (info == null)) {
|
|
|
|
viewHolder.time.setText(formatedTime + " \u00B7 " + filesize);
|
|
|
|
} else {
|
|
|
|
viewHolder.time.setText(formatedTime);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((filesize != null) && (info != null)) {
|
|
|
|
viewHolder.time.setText(filesize + " \u00B7 " + info);
|
|
|
|
} else if ((filesize == null) && (info != null)) {
|
|
|
|
if (error) {
|
|
|
|
viewHolder.time.setText(info + " \u00B7 " + formatedTime);
|
|
|
|
} else {
|
|
|
|
viewHolder.time.setText(info);
|
|
|
|
}
|
|
|
|
} else if ((filesize != null) && (info == null)) {
|
|
|
|
viewHolder.time.setText(filesize + " \u00B7 " + formatedTime);
|
|
|
|
} else {
|
|
|
|
viewHolder.time.setText(formatedTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:04:05 +00:00
|
|
|
private void displayInfoMessage(ViewHolder viewHolder, String text) {
|
2014-07-22 13:31:54 +00:00
|
|
|
if (viewHolder.download_button != null) {
|
|
|
|
viewHolder.download_button.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
2014-11-13 20:04:05 +00:00
|
|
|
viewHolder.messageBody.setText(text);
|
2014-09-11 12:24:10 +00:00
|
|
|
viewHolder.messageBody.setTextColor(activity.getSecondaryTextColor());
|
2014-07-22 13:31:54 +00:00
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.ITALIC);
|
|
|
|
viewHolder.messageBody.setTextIsSelectable(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void displayDecryptionFailed(ViewHolder viewHolder) {
|
|
|
|
if (viewHolder.download_button != null) {
|
|
|
|
viewHolder.download_button.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
|
|
|
viewHolder.messageBody.setText(getContext().getString(
|
|
|
|
R.string.decryption_failed));
|
2014-09-11 12:24:10 +00:00
|
|
|
viewHolder.messageBody.setTextColor(activity.getWarningTextColor());
|
2014-07-22 13:31:54 +00:00
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
|
|
|
|
viewHolder.messageBody.setTextIsSelectable(false);
|
|
|
|
}
|
|
|
|
|
2014-08-10 13:27:44 +00:00
|
|
|
private void displayTextMessage(ViewHolder viewHolder, Message message) {
|
2014-07-22 13:31:54 +00:00
|
|
|
if (viewHolder.download_button != null) {
|
|
|
|
viewHolder.download_button.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
2014-08-10 13:27:44 +00:00
|
|
|
if (message.getBody() != null) {
|
|
|
|
if (message.getType() != Message.TYPE_PRIVATE) {
|
2014-10-15 17:32:12 +00:00
|
|
|
String body = Config.PARSE_EMOTICONS ? UIHelper
|
|
|
|
.transformAsciiEmoticons(message.getMergedBody())
|
|
|
|
: message.getMergedBody();
|
|
|
|
viewHolder.messageBody.setText(body);
|
2014-08-10 13:27:44 +00:00
|
|
|
} else {
|
2014-08-22 11:22:07 +00:00
|
|
|
String privateMarker;
|
2014-08-28 09:01:24 +00:00
|
|
|
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
2014-08-31 14:28:21 +00:00
|
|
|
privateMarker = activity
|
|
|
|
.getString(R.string.private_message);
|
2014-08-10 13:27:44 +00:00
|
|
|
} else {
|
2014-11-09 15:21:13 +00:00
|
|
|
final String to;
|
|
|
|
if (message.getCounterpart() != null) {
|
|
|
|
to = message.getCounterpart().getResourcepart();
|
2014-08-10 13:27:44 +00:00
|
|
|
} else {
|
2014-11-09 15:21:13 +00:00
|
|
|
to = "";
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2014-11-07 14:09:28 +00:00
|
|
|
privateMarker = activity.getString(R.string.private_message_to, to);
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2014-08-31 14:28:21 +00:00
|
|
|
SpannableString span = new SpannableString(privateMarker + " "
|
|
|
|
+ message.getBody());
|
|
|
|
span.setSpan(
|
|
|
|
new ForegroundColorSpan(activity
|
|
|
|
.getSecondaryTextColor()), 0, privateMarker
|
|
|
|
.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
|
|
|
|
privateMarker.length(),
|
|
|
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2014-08-22 11:22:07 +00:00
|
|
|
viewHolder.messageBody.setText(span);
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
} else {
|
|
|
|
viewHolder.messageBody.setText("");
|
|
|
|
}
|
|
|
|
viewHolder.messageBody.setTextColor(activity.getPrimaryTextColor());
|
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
|
|
|
|
viewHolder.messageBody.setTextIsSelectable(true);
|
|
|
|
}
|
|
|
|
|
2014-10-17 11:09:02 +00:00
|
|
|
private void displayDownloadableMessage(ViewHolder viewHolder,
|
2014-11-13 20:04:05 +00:00
|
|
|
final Message message, String text) {
|
2014-10-17 11:09:02 +00:00
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.GONE);
|
|
|
|
viewHolder.download_button.setVisibility(View.VISIBLE);
|
2014-11-13 20:04:05 +00:00
|
|
|
viewHolder.download_button.setText(text);
|
2014-10-17 11:09:02 +00:00
|
|
|
viewHolder.download_button.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
startDonwloadable(message);
|
|
|
|
}
|
|
|
|
});
|
2014-10-23 19:27:41 +00:00
|
|
|
viewHolder.download_button.setOnLongClickListener(openContextMenu);
|
2014-10-17 11:09:02 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 20:04:05 +00:00
|
|
|
private void displayOpenableMessage(ViewHolder viewHolder,final Message message) {
|
2014-11-14 11:31:57 +00:00
|
|
|
final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
|
2014-11-13 20:04:05 +00:00
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.GONE);
|
|
|
|
viewHolder.download_button.setVisibility(View.VISIBLE);
|
2014-11-14 11:31:57 +00:00
|
|
|
viewHolder.download_button.setText(activity.getString(R.string.open_file,file.getMimeType()));
|
2014-11-13 20:04:05 +00:00
|
|
|
viewHolder.download_button.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-11-14 11:31:57 +00:00
|
|
|
openDonwloadable(file);
|
2014-11-13 20:04:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
viewHolder.download_button.setOnLongClickListener(openContextMenu);
|
|
|
|
}
|
|
|
|
|
2014-07-22 13:31:54 +00:00
|
|
|
private void displayImageMessage(ViewHolder viewHolder,
|
|
|
|
final Message message) {
|
|
|
|
if (viewHolder.download_button != null) {
|
|
|
|
viewHolder.download_button.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
viewHolder.messageBody.setVisibility(View.GONE);
|
|
|
|
viewHolder.image.setVisibility(View.VISIBLE);
|
2014-10-14 16:16:03 +00:00
|
|
|
ImageParams params = message.getImageParams();
|
|
|
|
double target = metrics.density * 288;
|
|
|
|
int scalledW;
|
|
|
|
int scalledH;
|
|
|
|
if (params.width <= params.height) {
|
|
|
|
scalledW = (int) (params.width / ((double) params.height / target));
|
|
|
|
scalledH = (int) target;
|
|
|
|
} else {
|
|
|
|
scalledW = (int) target;
|
|
|
|
scalledH = (int) (params.height / ((double) params.width / target));
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2014-10-14 16:16:03 +00:00
|
|
|
viewHolder.image.setLayoutParams(new LinearLayout.LayoutParams(
|
|
|
|
scalledW, scalledH));
|
2014-07-22 13:31:54 +00:00
|
|
|
activity.loadBitmap(message, viewHolder.image);
|
|
|
|
viewHolder.image.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
2014-08-08 09:49:23 +00:00
|
|
|
intent.setDataAndType(activity.xmppConnectionService
|
|
|
|
.getFileBackend().getJingleFileUri(message), "image/*");
|
2014-07-22 13:31:54 +00:00
|
|
|
getContext().startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
2014-10-23 19:27:41 +00:00
|
|
|
viewHolder.image.setOnLongClickListener(openContextMenu);
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 17:24:01 +00:00
|
|
|
private String getDisplayedMucCounterpart(final Jid counterpart) {
|
|
|
|
if (counterpart==null) {
|
|
|
|
return "";
|
2014-11-09 18:06:43 +00:00
|
|
|
} else if (!counterpart.isBareJid()) {
|
2014-11-09 17:24:01 +00:00
|
|
|
return counterpart.getResourcepart();
|
|
|
|
} else {
|
|
|
|
return counterpart.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 13:31:54 +00:00
|
|
|
@Override
|
|
|
|
public View getView(int position, View view, ViewGroup parent) {
|
2014-12-03 09:35:30 +00:00
|
|
|
final Message message = getItem(position);
|
|
|
|
final Conversation conversation = message.getConversation();
|
|
|
|
final Account account = conversation.getAccount();
|
2014-12-07 20:14:13 +00:00
|
|
|
final int type = getItemViewType(position);
|
2014-07-22 13:31:54 +00:00
|
|
|
ViewHolder viewHolder;
|
|
|
|
if (view == null) {
|
|
|
|
viewHolder = new ViewHolder();
|
|
|
|
switch (type) {
|
2014-08-31 12:29:12 +00:00
|
|
|
case NULL:
|
2014-10-26 17:54:10 +00:00
|
|
|
view = activity.getLayoutInflater().inflate(
|
2014-08-31 12:29:12 +00:00
|
|
|
R.layout.message_null, parent, false);
|
|
|
|
break;
|
2014-07-22 13:31:54 +00:00
|
|
|
case SENT:
|
2014-10-26 17:54:10 +00:00
|
|
|
view = activity.getLayoutInflater().inflate(
|
2014-08-08 09:49:23 +00:00
|
|
|
R.layout.message_sent, parent, false);
|
2014-07-22 13:31:54 +00:00
|
|
|
viewHolder.message_box = (LinearLayout) view
|
|
|
|
.findViewById(R.id.message_box);
|
|
|
|
viewHolder.contact_picture = (ImageView) view
|
|
|
|
.findViewById(R.id.message_photo);
|
2014-10-15 17:32:12 +00:00
|
|
|
viewHolder.download_button = (Button) view
|
|
|
|
.findViewById(R.id.download_button);
|
2014-07-22 13:31:54 +00:00
|
|
|
viewHolder.indicator = (ImageView) view
|
|
|
|
.findViewById(R.id.security_indicator);
|
|
|
|
viewHolder.image = (ImageView) view
|
|
|
|
.findViewById(R.id.message_image);
|
|
|
|
viewHolder.messageBody = (TextView) view
|
|
|
|
.findViewById(R.id.message_body);
|
|
|
|
viewHolder.time = (TextView) view
|
|
|
|
.findViewById(R.id.message_time);
|
2014-09-20 13:49:25 +00:00
|
|
|
viewHolder.indicatorReceived = (ImageView) view
|
|
|
|
.findViewById(R.id.indicator_received);
|
2014-07-22 13:31:54 +00:00
|
|
|
break;
|
2014-08-28 14:49:52 +00:00
|
|
|
case RECEIVED:
|
2014-10-26 17:54:10 +00:00
|
|
|
view = activity.getLayoutInflater().inflate(
|
2014-08-28 09:01:24 +00:00
|
|
|
R.layout.message_received, parent, false);
|
2014-07-22 13:31:54 +00:00
|
|
|
viewHolder.message_box = (LinearLayout) view
|
|
|
|
.findViewById(R.id.message_box);
|
|
|
|
viewHolder.contact_picture = (ImageView) view
|
|
|
|
.findViewById(R.id.message_photo);
|
|
|
|
viewHolder.download_button = (Button) view
|
|
|
|
.findViewById(R.id.download_button);
|
|
|
|
viewHolder.indicator = (ImageView) view
|
|
|
|
.findViewById(R.id.security_indicator);
|
|
|
|
viewHolder.image = (ImageView) view
|
|
|
|
.findViewById(R.id.message_image);
|
|
|
|
viewHolder.messageBody = (TextView) view
|
|
|
|
.findViewById(R.id.message_body);
|
|
|
|
viewHolder.time = (TextView) view
|
|
|
|
.findViewById(R.id.message_time);
|
2014-11-07 14:38:20 +00:00
|
|
|
viewHolder.indicatorReceived = (ImageView) view
|
|
|
|
.findViewById(R.id.indicator_received);
|
2014-07-22 13:31:54 +00:00
|
|
|
break;
|
|
|
|
case STATUS:
|
2014-10-26 17:54:10 +00:00
|
|
|
view = activity.getLayoutInflater().inflate(
|
2014-08-08 09:49:23 +00:00
|
|
|
R.layout.message_status, parent, false);
|
2014-07-22 13:31:54 +00:00
|
|
|
viewHolder.contact_picture = (ImageView) view
|
|
|
|
.findViewById(R.id.message_photo);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
viewHolder = null;
|
|
|
|
break;
|
|
|
|
}
|
2014-12-07 20:14:13 +00:00
|
|
|
view.setTag(viewHolder);
|
2014-07-22 13:31:54 +00:00
|
|
|
} else {
|
|
|
|
viewHolder = (ViewHolder) view.getTag();
|
2014-12-07 20:14:13 +00:00
|
|
|
if (viewHolder == null) {
|
|
|
|
return view;
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 09:51:16 +00:00
|
|
|
if (type == STATUS) {
|
2014-12-03 09:35:30 +00:00
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
2014-11-07 14:38:20 +00:00
|
|
|
viewHolder.contact_picture.setImageBitmap(activity
|
2014-12-03 09:35:30 +00:00
|
|
|
.avatarService().get(conversation.getContact(),
|
2014-11-07 14:38:20 +00:00
|
|
|
activity.getPixel(32)));
|
|
|
|
viewHolder.contact_picture.setAlpha(0.5f);
|
|
|
|
viewHolder.contact_picture
|
|
|
|
.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-12-03 09:35:30 +00:00
|
|
|
String name = conversation.getName();
|
2014-11-07 14:38:20 +00:00
|
|
|
String read = getContext()
|
|
|
|
.getString(
|
|
|
|
R.string.contact_has_read_up_to_this_point,
|
|
|
|
name);
|
|
|
|
Toast.makeText(getContext(), read,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2014-10-07 09:51:16 +00:00
|
|
|
return view;
|
2014-11-07 14:38:20 +00:00
|
|
|
} else if (type == NULL) {
|
2014-10-06 20:03:01 +00:00
|
|
|
if (position == getCount() - 1) {
|
|
|
|
view.getLayoutParams().height = 1;
|
|
|
|
} else {
|
|
|
|
view.getLayoutParams().height = 0;
|
2014-10-07 13:18:09 +00:00
|
|
|
|
2014-10-06 20:03:01 +00:00
|
|
|
}
|
|
|
|
view.setLayoutParams(view.getLayoutParams());
|
2014-07-22 13:31:54 +00:00
|
|
|
return view;
|
2014-11-07 14:38:20 +00:00
|
|
|
} else if (type == RECEIVED) {
|
2014-12-03 09:35:30 +00:00
|
|
|
Contact contact = message.getContact();
|
2014-11-07 14:38:20 +00:00
|
|
|
if (contact != null) {
|
|
|
|
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(contact, activity.getPixel(48)));
|
2014-12-03 09:35:30 +00:00
|
|
|
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(getDisplayedMucCounterpart(message.getCounterpart()),
|
2014-11-07 22:48:30 +00:00
|
|
|
activity.getPixel(48)));
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
2014-12-03 09:35:30 +00:00
|
|
|
} else if (type == SENT && viewHolder.contact_picture != null) {
|
|
|
|
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48)));
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 14:09:28 +00:00
|
|
|
if (viewHolder != null && viewHolder.contact_picture != null) {
|
2014-09-20 14:02:49 +00:00
|
|
|
viewHolder.contact_picture
|
|
|
|
.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
|
|
|
|
MessageAdapter.this.mOnContactPictureClickedListener
|
2014-12-03 09:35:30 +00:00
|
|
|
.onContactPictureClicked(message);
|
2014-09-20 14:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
viewHolder.contact_picture
|
|
|
|
.setOnLongClickListener(new OnLongClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
|
|
|
|
MessageAdapter.this.mOnContactPictureLongClickedListener
|
2014-12-03 09:35:30 +00:00
|
|
|
.onContactPictureLongClicked(message);
|
2014-09-20 14:02:49 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-12-03 09:35:30 +00:00
|
|
|
if (message.getDownloadable() != null && message.getDownloadable().getStatus() != Downloadable.STATUS_UPLOADING) {
|
|
|
|
Downloadable d = message.getDownloadable();
|
2014-11-13 20:04:05 +00:00
|
|
|
if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
|
2014-12-03 09:35:30 +00:00
|
|
|
if (message.getType() == Message.TYPE_FILE) {
|
2014-11-13 20:04:05 +00:00
|
|
|
displayInfoMessage(viewHolder,activity.getString(R.string.receiving_file,d.getMimeType(),d.getProgress()));
|
|
|
|
} else {
|
|
|
|
displayInfoMessage(viewHolder,activity.getString(R.string.receiving_image,d.getProgress()));
|
|
|
|
}
|
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_CHECKING) {
|
|
|
|
displayInfoMessage(viewHolder,activity.getString(R.string.checking_image));
|
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_DELETED) {
|
2014-12-03 09:35:30 +00:00
|
|
|
if (message.getType() == Message.TYPE_FILE) {
|
2014-11-15 14:16:40 +00:00
|
|
|
displayInfoMessage(viewHolder, activity.getString(R.string.file_deleted));
|
|
|
|
} else {
|
|
|
|
displayInfoMessage(viewHolder, activity.getString(R.string.image_file_deleted));
|
|
|
|
}
|
2014-11-13 20:04:05 +00:00
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_OFFER) {
|
2014-12-03 09:35:30 +00:00
|
|
|
if (message.getType() == Message.TYPE_FILE) {
|
|
|
|
displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_file,d.getMimeType()));
|
2014-11-13 20:04:05 +00:00
|
|
|
} else {
|
2014-12-03 09:35:30 +00:00
|
|
|
displayDownloadableMessage(viewHolder, message,activity.getString(R.string.download_image));
|
2014-11-13 20:04:05 +00:00
|
|
|
}
|
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) {
|
2014-12-03 09:35:30 +00:00
|
|
|
displayDownloadableMessage(viewHolder, message,activity.getString(R.string.check_image_filesize));
|
2014-11-13 20:04:05 +00:00
|
|
|
} else if (d.getStatus() == Downloadable.STATUS_FAILED) {
|
2014-12-03 09:35:30 +00:00
|
|
|
if (message.getType() == Message.TYPE_FILE) {
|
2014-11-15 13:40:43 +00:00
|
|
|
displayInfoMessage(viewHolder, activity.getString(R.string.file_transmission_failed));
|
|
|
|
} else {
|
|
|
|
displayInfoMessage(viewHolder, activity.getString(R.string.image_transmission_failed));
|
|
|
|
}
|
2014-11-13 20:04:05 +00:00
|
|
|
}
|
2014-12-03 09:35:30 +00:00
|
|
|
} else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
|
|
|
displayImageMessage(viewHolder, message);
|
|
|
|
} else if (message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
|
|
|
if (message.getImageParams().width > 0) {
|
|
|
|
displayImageMessage(viewHolder,message);
|
2014-11-13 21:59:00 +00:00
|
|
|
} else {
|
2014-12-03 09:35:30 +00:00
|
|
|
displayOpenableMessage(viewHolder, message);
|
2014-11-13 21:59:00 +00:00
|
|
|
}
|
2014-12-03 09:35:30 +00:00
|
|
|
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
2014-11-14 11:31:57 +00:00
|
|
|
if (activity.hasPgp()) {
|
|
|
|
displayInfoMessage(viewHolder,activity.getString(R.string.encrypted_message));
|
2014-07-22 13:31:54 +00:00
|
|
|
} else {
|
2014-11-14 11:31:57 +00:00
|
|
|
displayInfoMessage(viewHolder,
|
|
|
|
activity.getString(R.string.install_openkeychain));
|
|
|
|
if (viewHolder != null) {
|
|
|
|
viewHolder.message_box
|
|
|
|
.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
activity.showInstallPgpDialog();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2014-12-03 09:35:30 +00:00
|
|
|
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
2014-11-14 11:31:57 +00:00
|
|
|
displayDecryptionFailed(viewHolder);
|
|
|
|
} else {
|
2014-12-03 09:35:30 +00:00
|
|
|
displayTextMessage(viewHolder, message);
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 09:35:30 +00:00
|
|
|
displayStatus(viewHolder, message);
|
2014-07-22 13:31:54 +00:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2014-10-17 11:09:02 +00:00
|
|
|
public void startDonwloadable(Message message) {
|
2014-10-14 17:27:49 +00:00
|
|
|
Downloadable downloadable = message.getDownloadable();
|
|
|
|
if (downloadable != null) {
|
2014-10-17 11:09:02 +00:00
|
|
|
if (!downloadable.start()) {
|
|
|
|
Toast.makeText(activity, R.string.not_connected_try_again,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2014-10-14 17:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 11:31:57 +00:00
|
|
|
public void openDonwloadable(DownloadableFile file) {
|
2014-11-15 14:16:40 +00:00
|
|
|
if (!file.exists()) {
|
|
|
|
Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Intent openIntent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
openIntent.setDataAndType(Uri.fromFile(file), file.getMimeType());
|
|
|
|
PackageManager manager = activity.getPackageManager();
|
|
|
|
List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0);
|
|
|
|
if (infos.size() > 0) {
|
|
|
|
getContext().startActivity(openIntent);
|
|
|
|
} else {
|
|
|
|
Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2014-11-13 20:04:05 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 14:38:20 +00:00
|
|
|
public interface OnContactPictureClicked {
|
|
|
|
public void onContactPictureClicked(Message message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnContactPictureLongClicked {
|
|
|
|
public void onContactPictureLongClicked(Message message);
|
|
|
|
}
|
|
|
|
|
2014-07-22 13:31:54 +00:00
|
|
|
private static class ViewHolder {
|
|
|
|
|
|
|
|
protected LinearLayout message_box;
|
|
|
|
protected Button download_button;
|
|
|
|
protected ImageView image;
|
|
|
|
protected ImageView indicator;
|
2014-09-20 13:49:25 +00:00
|
|
|
protected ImageView indicatorReceived;
|
2014-07-22 13:31:54 +00:00
|
|
|
protected TextView time;
|
|
|
|
protected TextView messageBody;
|
|
|
|
protected ImageView contact_picture;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|