2014-07-22 13:31:54 +00:00
|
|
|
package eu.siacs.conversations.ui.adapter;
|
|
|
|
|
2015-09-27 19:27:07 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2014-07-22 13:31:54 +00:00
|
|
|
import android.content.Intent;
|
2014-11-15 14:16:40 +00:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ResolveInfo;
|
2015-10-29 11:08:15 +00:00
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.graphics.Bitmap;
|
2014-07-22 13:31:54 +00:00
|
|
|
import android.graphics.Typeface;
|
2015-10-29 11:08:15 +00:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2014-11-13 20:04:05 +00:00
|
|
|
import android.net.Uri;
|
2015-10-29 11:08:15 +00:00
|
|
|
import android.os.AsyncTask;
|
2017-03-29 16:30:28 +00:00
|
|
|
import android.support.v4.content.ContextCompat;
|
2014-08-22 11:22:07 +00:00
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableString;
|
2016-09-15 23:15:07 +00:00
|
|
|
import android.text.SpannableStringBuilder;
|
2015-05-10 01:12:44 +00:00
|
|
|
import android.text.Spanned;
|
2017-07-04 09:01:20 +00:00
|
|
|
import android.text.format.DateUtils;
|
2014-08-22 11:22:07 +00:00
|
|
|
import android.text.style.ForegroundColorSpan;
|
2015-05-10 01:12:44 +00:00
|
|
|
import android.text.style.RelativeSizeSpan;
|
2014-08-22 11:22:07 +00:00
|
|
|
import android.text.style.StyleSpan;
|
2016-02-29 18:05:50 +00:00
|
|
|
import android.text.util.Linkify;
|
2014-07-22 13:31:54 +00:00
|
|
|
import android.util.DisplayMetrics;
|
2016-11-25 14:06:43 +00:00
|
|
|
import android.view.ActionMode;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2014-07-22 13:31:54 +00:00
|
|
|
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;
|
|
|
|
|
2017-07-30 20:04:58 +00:00
|
|
|
import com.vdurmont.emoji.EmojiManager;
|
|
|
|
|
2015-10-29 11:08:15 +00:00
|
|
|
import java.lang.ref.WeakReference;
|
2016-03-04 20:30:34 +00:00
|
|
|
import java.net.URL;
|
2014-11-07 14:38:20 +00:00
|
|
|
import java.util.List;
|
2017-01-09 16:58:11 +00:00
|
|
|
import java.util.Locale;
|
2015-10-29 11:08:15 +00:00
|
|
|
import java.util.concurrent.RejectedExecutionException;
|
2017-01-09 16:58:11 +00:00
|
|
|
import java.util.regex.Matcher;
|
2016-02-29 18:05:50 +00:00
|
|
|
import java.util.regex.Pattern;
|
2014-11-07 14:38:20 +00:00
|
|
|
|
2016-05-28 21:13:47 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-11-07 14:38:20 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2016-11-14 21:27:41 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
|
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.Conversation;
|
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;
|
2015-06-30 15:15:02 +00:00
|
|
|
import eu.siacs.conversations.entities.Message.FileParams;
|
2015-07-20 12:26:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Transferable;
|
2016-10-03 19:04:10 +00:00
|
|
|
import eu.siacs.conversations.persistance.FileBackend;
|
2017-01-23 16:14:30 +00:00
|
|
|
import eu.siacs.conversations.services.MessageArchiveService;
|
2017-01-20 13:54:59 +00:00
|
|
|
import eu.siacs.conversations.services.NotificationService;
|
2014-11-07 14:38:20 +00:00
|
|
|
import eu.siacs.conversations.ui.ConversationActivity;
|
2016-11-25 14:06:43 +00:00
|
|
|
import eu.siacs.conversations.ui.text.DividerSpan;
|
|
|
|
import eu.siacs.conversations.ui.text.QuoteSpan;
|
2016-09-15 23:15:07 +00:00
|
|
|
import eu.siacs.conversations.ui.widget.ClickableMovementMethod;
|
2016-10-19 17:43:30 +00:00
|
|
|
import eu.siacs.conversations.ui.widget.CopyTextView;
|
2016-09-18 13:35:14 +00:00
|
|
|
import eu.siacs.conversations.ui.widget.ListSelectionManager;
|
2015-10-28 21:40:09 +00:00
|
|
|
import eu.siacs.conversations.utils.CryptoHelper;
|
2015-03-07 13:15:38 +00:00
|
|
|
import eu.siacs.conversations.utils.GeoHelper;
|
2017-01-09 16:58:11 +00:00
|
|
|
import eu.siacs.conversations.utils.Patterns;
|
2014-11-07 14:38:20 +00:00
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2017-05-07 19:05:35 +00:00
|
|
|
import eu.siacs.conversations.xmpp.mam.MamReference;
|
2014-11-07 14:38:20 +00:00
|
|
|
|
2016-10-19 17:43:30 +00:00
|
|
|
public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler {
|
2014-07-22 13:31:54 +00:00
|
|
|
|
|
|
|
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;
|
2017-07-04 09:01:20 +00:00
|
|
|
private static final int DATE_SEPARATOR = 3;
|
|
|
|
|
|
|
|
public static final String DATE_SEPARATOR_BODY = "DATE_SEPARATOR";
|
|
|
|
|
2016-02-29 18:05:50 +00:00
|
|
|
private static final Pattern XMPP_PATTERN = Pattern
|
|
|
|
.compile("xmpp\\:(?:(?:["
|
|
|
|
+ Patterns.GOOD_IRI_CHAR
|
|
|
|
+ "\\;\\/\\?\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])"
|
|
|
|
+ "|(?:\\%[a-fA-F0-9]{2}))+");
|
2014-07-22 13:31:54 +00:00
|
|
|
|
2017-01-09 17:05:58 +00:00
|
|
|
private static final Linkify.TransformFilter WEBURL_TRANSFORM_FILTER = new Linkify.TransformFilter() {
|
2017-01-09 16:58:11 +00:00
|
|
|
@Override
|
|
|
|
public String transformUrl(Matcher matcher, String url) {
|
|
|
|
if (url == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
final String lcUrl = url.toLowerCase(Locale.US);
|
|
|
|
if (lcUrl.startsWith("http://") || lcUrl.startsWith("https://")) {
|
|
|
|
return url;
|
|
|
|
} else {
|
|
|
|
return "http://"+url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-01-15 17:54:15 +00:00
|
|
|
private static final Linkify.MatchFilter WEBURL_MATCH_FILTER = new Linkify.MatchFilter() {
|
|
|
|
@Override
|
2017-02-09 19:14:36 +00:00
|
|
|
public boolean acceptMatch(CharSequence cs, int start, int end) {
|
2017-04-07 12:29:55 +00:00
|
|
|
return start < 1 || (cs.charAt(start-1) != '@' && cs.charAt(start-1) != '.' && !cs.subSequence(Math.max(0,start - 3),start).equals("://"));
|
2017-01-15 17:54:15 +00:00
|
|
|
}
|
|
|
|
};
|
2017-01-09 16:58:11 +00:00
|
|
|
|
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
|
|
|
|
2015-08-24 18:56:25 +00:00
|
|
|
private boolean mIndicateReceived = false;
|
Dark theme, theme switch, icons, style, strings
added some white icons,
changed hardcoded icons to theme attributes,
changed icon_edit_dark to icon_edit_body to reflect icons position,
grey message bubbles in dark theme,
misc
purged ic_action_chat as it wasn't used
preference use_white_background changed to use_green_background, default true
grey chat bubbles darker, text white
replaced all grey600 with black icons and 0.54 alpha attribute
highlightColor in dark grey chat bubble now darker than background
2016-05-12 18:00:18 +00:00
|
|
|
private boolean mUseGreenBackground = false;
|
2015-01-11 15:22:29 +00:00
|
|
|
|
2016-11-25 14:06:43 +00:00
|
|
|
private OnQuoteListener onQuoteListener;
|
|
|
|
|
2016-09-18 13:35:14 +00:00
|
|
|
private final ListSelectionManager listSelectionManager = new ListSelectionManager();
|
|
|
|
|
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();
|
2015-08-24 18:56:25 +00:00
|
|
|
updatePreferences();
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2015-01-11 15:22:29 +00:00
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
|
2016-11-25 14:06:43 +00:00
|
|
|
public void setOnQuoteListener(OnQuoteListener listener) {
|
|
|
|
this.onQuoteListener = listener;
|
|
|
|
}
|
|
|
|
|
2014-07-22 13:31:54 +00:00
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
2017-07-04 09:01:20 +00:00
|
|
|
return 4;
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2015-07-19 12:26:03 +00:00
|
|
|
public int getItemViewType(Message message) {
|
|
|
|
if (message.getType() == Message.TYPE_STATUS) {
|
2017-07-04 09:01:20 +00:00
|
|
|
if (DATE_SEPARATOR_BODY.equals(message.getBody())) {
|
|
|
|
return DATE_SEPARATOR;
|
|
|
|
} else {
|
|
|
|
return STATUS;
|
|
|
|
}
|
2015-07-19 12:26:03 +00:00
|
|
|
} else if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
2014-08-28 14:49:52 +00:00
|
|
|
return RECEIVED;
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2015-07-19 12:26:03 +00:00
|
|
|
|
|
|
|
return SENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
return this.getItemViewType(getItem(position));
|
|
|
|
}
|
|
|
|
|
2015-08-24 18:56:25 +00:00
|
|
|
private int getMessageTextColor(boolean onDark, boolean primary) {
|
|
|
|
if (onDark) {
|
2017-03-29 16:30:28 +00:00
|
|
|
return ContextCompat.getColor(activity, primary ? R.color.white : R.color.white70);
|
2015-08-24 18:56:25 +00:00
|
|
|
} else {
|
2017-03-29 16:30:28 +00:00
|
|
|
return ContextCompat.getColor(activity, primary ? R.color.black87 : R.color.black54);
|
2015-07-19 12:26:03 +00:00
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 07:26:55 +00:00
|
|
|
private void displayStatus(ViewHolder viewHolder, Message message, int type, boolean darkBackground) {
|
2014-07-22 13:31:54 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-02-15 22:15:04 +00:00
|
|
|
|
|
|
|
if (viewHolder.edit_indicator != null) {
|
|
|
|
if (message.edited()) {
|
|
|
|
viewHolder.edit_indicator.setVisibility(View.VISIBLE);
|
|
|
|
viewHolder.edit_indicator.setImageResource(darkBackground ? R.drawable.ic_mode_edit_white_18dp : R.drawable.ic_mode_edit_black_18dp);
|
|
|
|
viewHolder.edit_indicator.setAlpha(darkBackground ? 0.7f : 0.57f);
|
|
|
|
} else {
|
|
|
|
viewHolder.edit_indicator.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI
|
2015-01-11 15:22:29 +00:00
|
|
|
&& message.getMergedStatus() <= Message.STATUS_RECEIVED;
|
2015-07-10 13:11:03 +00:00
|
|
|
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getTransferable() != null) {
|
2015-06-30 15:15:02 +00:00
|
|
|
FileParams params = message.getFileParams();
|
2014-11-13 21:59:00 +00:00
|
|
|
if (params.size > (1.5 * 1024 * 1024)) {
|
2015-01-04 16:53:06 +00:00
|
|
|
filesize = params.size / (1024 * 1024)+ " MiB";
|
2017-03-31 07:26:55 +00:00
|
|
|
} else if (params.size >= 1024) {
|
2015-01-04 16:53:06 +00:00
|
|
|
filesize = params.size / 1024 + " KiB";
|
2017-04-05 19:01:29 +00:00
|
|
|
} else if (params.size > 0){
|
2017-03-31 07:26:55 +00:00
|
|
|
filesize = params.size + " B";
|
2014-10-14 17:33:35 +00:00
|
|
|
}
|
2015-07-10 13:11:03 +00:00
|
|
|
if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) {
|
2014-10-29 10:31:03 +00:00
|
|
|
error = true;
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2014-08-31 16:55:15 +00:00
|
|
|
switch (message.getMergedStatus()) {
|
2015-01-11 15:22:29 +00:00
|
|
|
case Message.STATUS_WAITING:
|
|
|
|
info = getContext().getString(R.string.waiting);
|
|
|
|
break;
|
|
|
|
case Message.STATUS_UNSEND:
|
2015-07-10 13:11:03 +00:00
|
|
|
Transferable d = message.getTransferable();
|
2015-01-11 15:22:29 +00:00
|
|
|
if (d!=null) {
|
|
|
|
info = getContext().getString(R.string.sending_file,d.getProgress());
|
2014-07-29 12:42:17 +00:00
|
|
|
} else {
|
2015-01-11 15:22:29 +00:00
|
|
|
info = getContext().getString(R.string.sending);
|
2014-07-29 12:42:17 +00:00
|
|
|
}
|
2015-01-11 15:22:29 +00:00
|
|
|
break;
|
|
|
|
case Message.STATUS_OFFERED:
|
|
|
|
info = getContext().getString(R.string.offering);
|
|
|
|
break;
|
|
|
|
case Message.STATUS_SEND_RECEIVED:
|
2015-08-24 18:56:25 +00:00
|
|
|
if (mIndicateReceived) {
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Message.STATUS_SEND_DISPLAYED:
|
2015-08-24 18:56:25 +00:00
|
|
|
if (mIndicateReceived) {
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Message.STATUS_SEND_FAILED:
|
|
|
|
info = getContext().getString(R.string.send_failed);
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (multiReceived) {
|
2015-01-12 15:09:39 +00:00
|
|
|
info = UIHelper.getMessageDisplayName(message);
|
2015-01-11 15:22:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2015-07-30 10:40:50 +00:00
|
|
|
if (error && type == SENT) {
|
2014-09-11 12:24:10 +00:00
|
|
|
viewHolder.time.setTextColor(activity.getWarningTextColor());
|
2014-07-22 13:31:54 +00:00
|
|
|
} else {
|
2015-08-24 18:56:25 +00:00
|
|
|
viewHolder.time.setTextColor(this.getMessageTextColor(darkBackground,false));
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
|
|
|
|
viewHolder.indicator.setVisibility(View.GONE);
|
|
|
|
} else {
|
2016-12-09 17:46:32 +00:00
|
|
|
boolean verified = false;
|
2015-07-15 14:32:42 +00:00
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
|
2016-12-09 17:46:32 +00:00
|
|
|
final FingerprintStatus status = message.getConversation()
|
2015-07-10 01:00:40 +00:00
|
|
|
.getAccount().getAxolotlService().getFingerprintTrust(
|
2016-03-31 19:15:49 +00:00
|
|
|
message.getFingerprint());
|
2016-12-09 17:46:32 +00:00
|
|
|
if (status != null && status.isVerified()) {
|
|
|
|
verified = true;
|
2015-07-10 01:00:40 +00:00
|
|
|
}
|
2016-12-09 17:46:32 +00:00
|
|
|
}
|
|
|
|
if (verified) {
|
|
|
|
viewHolder.indicator.setImageResource(darkBackground ? R.drawable.ic_verified_user_white_18dp : R.drawable.ic_verified_user_black_18dp);
|
2015-07-29 18:25:14 +00:00
|
|
|
} else {
|
2016-12-09 17:46:32 +00:00
|
|
|
viewHolder.indicator.setImageResource(darkBackground ? R.drawable.ic_lock_white_18dp : R.drawable.ic_lock_black_18dp);
|
|
|
|
}
|
|
|
|
if (darkBackground) {
|
|
|
|
viewHolder.indicator.setAlpha(0.7f);
|
|
|
|
} else {
|
|
|
|
viewHolder.indicator.setAlpha(0.57f);
|
2015-07-10 01:00:40 +00:00
|
|
|
}
|
2016-12-16 10:30:51 +00:00
|
|
|
viewHolder.indicator.setVisibility(View.VISIBLE);
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
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)) {
|
2015-07-10 10:42:41 +00:00
|
|
|
viewHolder.time.setText(formatedTime + " \u00B7 " + filesize +" \u00B7 " + info);
|
2014-07-22 13:31:54 +00:00
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-24 18:56:25 +00:00
|
|
|
private void displayInfoMessage(ViewHolder viewHolder, String text, boolean darkBackground) {
|
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);
|
2015-08-24 18:56:25 +00:00
|
|
|
viewHolder.messageBody.setTextColor(getMessageTextColor(darkBackground, false));
|
2014-07-22 13:31:54 +00:00
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.ITALIC);
|
2015-12-26 18:18:37 +00:00
|
|
|
viewHolder.messageBody.setTextIsSelectable(false);
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 18:56:25 +00:00
|
|
|
private void displayDecryptionFailed(ViewHolder viewHolder, boolean darkBackground) {
|
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);
|
|
|
|
viewHolder.messageBody.setText(getContext().getString(
|
2015-05-10 01:12:44 +00:00
|
|
|
R.string.decryption_failed));
|
2015-08-24 18:56:25 +00:00
|
|
|
viewHolder.messageBody.setTextColor(getMessageTextColor(darkBackground, false));
|
2014-07-22 13:31:54 +00:00
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
|
2015-12-26 18:18:37 +00:00
|
|
|
viewHolder.messageBody.setTextIsSelectable(false);
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-30 20:04:58 +00:00
|
|
|
private void displayEmojiMessage(final ViewHolder viewHolder, final String body) {
|
2015-05-10 01:12:44 +00:00
|
|
|
if (viewHolder.download_button != null) {
|
|
|
|
viewHolder.download_button.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
2015-05-11 06:45:38 +00:00
|
|
|
viewHolder.messageBody.setIncludeFontPadding(false);
|
2015-05-10 01:12:44 +00:00
|
|
|
Spannable span = new SpannableString(body);
|
2017-07-30 20:04:58 +00:00
|
|
|
float size = EmojiManager.isEmoji(body) ? 3.0f : 2.0f;
|
|
|
|
span.setSpan(new RelativeSizeSpan(size), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2015-05-10 01:12:44 +00:00
|
|
|
viewHolder.messageBody.setText(span);
|
|
|
|
}
|
|
|
|
|
2016-11-25 14:06:43 +00:00
|
|
|
private int applyQuoteSpan(SpannableStringBuilder body, int start, int end, boolean darkBackground) {
|
|
|
|
if (start > 1 && !"\n\n".equals(body.subSequence(start - 2, start).toString())) {
|
|
|
|
body.insert(start++, "\n");
|
|
|
|
body.setSpan(new DividerSpan(false), start - 2, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
if (end < body.length() - 1 && !"\n\n".equals(body.subSequence(end, end + 2).toString())) {
|
|
|
|
body.insert(end, "\n");
|
|
|
|
body.setSpan(new DividerSpan(false), end, end + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
int color = darkBackground ? this.getMessageTextColor(darkBackground, false)
|
2017-03-29 16:30:28 +00:00
|
|
|
: ContextCompat.getColor(activity, R.color.bubble);
|
2016-11-25 14:06:43 +00:00
|
|
|
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
|
|
|
|
body.setSpan(new QuoteSpan(color, metrics), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies QuoteSpan to group of lines which starts with > or » characters.
|
|
|
|
* Appends likebreaks and applies DividerSpan to them to show a padding between quote and text.
|
|
|
|
*/
|
|
|
|
private boolean handleTextQuotes(SpannableStringBuilder body, boolean darkBackground) {
|
|
|
|
boolean startsWithQuote = false;
|
|
|
|
char previous = '\n';
|
|
|
|
int lineStart = -1;
|
|
|
|
int lineTextStart = -1;
|
|
|
|
int quoteStart = -1;
|
|
|
|
for (int i = 0; i <= body.length(); i++) {
|
|
|
|
char current = body.length() > i ? body.charAt(i) : '\n';
|
|
|
|
if (lineStart == -1) {
|
|
|
|
if (previous == '\n') {
|
2017-03-26 10:29:12 +00:00
|
|
|
if ((current == '>' && UIHelper.isPositionFollowedByQuoteableCharacter(body,i))
|
|
|
|
|| current == '\u00bb' && !UIHelper.isPositionFollowedByQuote(body,i)) {
|
2016-11-25 14:06:43 +00:00
|
|
|
// Line start with quote
|
|
|
|
lineStart = i;
|
|
|
|
if (quoteStart == -1) quoteStart = i;
|
|
|
|
if (i == 0) startsWithQuote = true;
|
|
|
|
} else if (quoteStart >= 0) {
|
|
|
|
// Line start without quote, apply spans there
|
|
|
|
applyQuoteSpan(body, quoteStart, i - 1, darkBackground);
|
|
|
|
quoteStart = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Remove extra spaces between > and first character in the line
|
|
|
|
// > character will be removed too
|
|
|
|
if (current != ' ' && lineTextStart == -1) {
|
|
|
|
lineTextStart = i;
|
|
|
|
}
|
|
|
|
if (current == '\n') {
|
|
|
|
body.delete(lineStart, lineTextStart);
|
|
|
|
i -= lineTextStart - lineStart;
|
|
|
|
if (i == lineStart) {
|
|
|
|
// Avoid empty lines because span over empty line can be hidden
|
|
|
|
body.insert(i++, " ");
|
|
|
|
}
|
|
|
|
lineStart = -1;
|
|
|
|
lineTextStart = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
previous = current;
|
|
|
|
}
|
|
|
|
if (quoteStart >= 0) {
|
|
|
|
// Apply spans to finishing open quote
|
|
|
|
applyQuoteSpan(body, quoteStart, body.length(), darkBackground);
|
|
|
|
}
|
|
|
|
return startsWithQuote;
|
|
|
|
}
|
|
|
|
|
Dark theme, theme switch, icons, style, strings
added some white icons,
changed hardcoded icons to theme attributes,
changed icon_edit_dark to icon_edit_body to reflect icons position,
grey message bubbles in dark theme,
misc
purged ic_action_chat as it wasn't used
preference use_white_background changed to use_green_background, default true
grey chat bubbles darker, text white
replaced all grey600 with black icons and 0.54 alpha attribute
highlightColor in dark grey chat bubble now darker than background
2016-05-12 18:00:18 +00:00
|
|
|
private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground, int type) {
|
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);
|
2015-05-11 06:45:38 +00:00
|
|
|
viewHolder.messageBody.setIncludeFontPadding(true);
|
2014-08-10 13:27:44 +00:00
|
|
|
if (message.getBody() != null) {
|
2015-01-12 15:09:39 +00:00
|
|
|
final String nick = UIHelper.getMessageDisplayName(message);
|
2016-10-19 21:53:13 +00:00
|
|
|
SpannableStringBuilder body = message.getMergedBody();
|
|
|
|
boolean hasMeCommand = message.hasMeCommand();
|
|
|
|
if (hasMeCommand) {
|
|
|
|
body = body.replace(0, Message.ME_COMMAND.length(), nick + " ");
|
2015-10-02 09:58:03 +00:00
|
|
|
}
|
2016-05-28 21:13:47 +00:00
|
|
|
if (body.length() > Config.MAX_DISPLAY_MESSAGE_CHARS) {
|
2016-10-19 21:53:13 +00:00
|
|
|
body = new SpannableStringBuilder(body, 0, Config.MAX_DISPLAY_MESSAGE_CHARS);
|
|
|
|
body.append("\u2026");
|
2016-05-28 21:13:47 +00:00
|
|
|
}
|
2016-10-19 21:53:13 +00:00
|
|
|
Message.MergeSeparator[] mergeSeparators = body.getSpans(0, body.length(), Message.MergeSeparator.class);
|
|
|
|
for (Message.MergeSeparator mergeSeparator : mergeSeparators) {
|
|
|
|
int start = body.getSpanStart(mergeSeparator);
|
|
|
|
int end = body.getSpanEnd(mergeSeparator);
|
2016-11-25 14:06:43 +00:00
|
|
|
body.setSpan(new DividerSpan(true), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2015-05-11 07:08:56 +00:00
|
|
|
}
|
2016-11-25 14:06:43 +00:00
|
|
|
boolean startsWithQuote = handleTextQuotes(body, darkBackground);
|
2014-08-10 13:27:44 +00:00
|
|
|
if (message.getType() != Message.TYPE_PRIVATE) {
|
2016-10-19 21:53:13 +00:00
|
|
|
if (hasMeCommand) {
|
|
|
|
body.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, nick.length(),
|
2015-01-11 15:22:29 +00:00
|
|
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
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) {
|
2016-10-19 21:53:13 +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
|
|
|
}
|
2016-10-19 21:53:13 +00:00
|
|
|
body.insert(0, privateMarker);
|
|
|
|
int privateMarkerIndex = privateMarker.length();
|
2016-11-25 14:06:43 +00:00
|
|
|
if (startsWithQuote) {
|
|
|
|
body.insert(privateMarkerIndex, "\n\n");
|
|
|
|
body.setSpan(new DividerSpan(false), privateMarkerIndex, privateMarkerIndex + 2,
|
|
|
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
} else {
|
|
|
|
body.insert(privateMarkerIndex, " ");
|
|
|
|
}
|
2016-10-19 21:53:13 +00:00
|
|
|
body.setSpan(new ForegroundColorSpan(getMessageTextColor(darkBackground, false)),
|
|
|
|
0, privateMarkerIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
body.setSpan(new StyleSpan(Typeface.BOLD),
|
|
|
|
0, privateMarkerIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
if (hasMeCommand) {
|
|
|
|
body.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), privateMarkerIndex + 1,
|
|
|
|
privateMarkerIndex + 1 + nick.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2015-01-11 15:22:29 +00:00
|
|
|
}
|
2016-05-28 15:01:05 +00:00
|
|
|
}
|
2017-01-20 13:54:59 +00:00
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI && message.getStatus() == Message.STATUS_RECEIVED) {
|
|
|
|
Pattern pattern = NotificationService.generateNickHighlightPattern(message.getConversation().getMucOptions().getActualNick());
|
|
|
|
Matcher matcher = pattern.matcher(body);
|
|
|
|
while(matcher.find()) {
|
|
|
|
body.setSpan(new StyleSpan(Typeface.BOLD), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
}
|
2016-10-19 21:53:13 +00:00
|
|
|
Linkify.addLinks(body, XMPP_PATTERN, "xmpp");
|
2017-01-15 17:54:15 +00:00
|
|
|
Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER);
|
2016-10-19 21:53:13 +00:00
|
|
|
Linkify.addLinks(body, GeoHelper.GEO_URI, "geo");
|
2016-02-29 18:05:50 +00:00
|
|
|
viewHolder.messageBody.setAutoLinkMask(0);
|
2016-10-19 21:53:13 +00:00
|
|
|
viewHolder.messageBody.setText(body);
|
2016-09-15 23:15:07 +00:00
|
|
|
viewHolder.messageBody.setTextIsSelectable(true);
|
|
|
|
viewHolder.messageBody.setMovementMethod(ClickableMovementMethod.getInstance());
|
2016-09-18 13:35:14 +00:00
|
|
|
listSelectionManager.onUpdate(viewHolder.messageBody, message);
|
2014-07-22 13:31:54 +00:00
|
|
|
} else {
|
|
|
|
viewHolder.messageBody.setText("");
|
2015-12-26 18:18:37 +00:00
|
|
|
viewHolder.messageBody.setTextIsSelectable(false);
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2015-08-24 18:56:25 +00:00
|
|
|
viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true));
|
2015-09-27 19:27:07 +00:00
|
|
|
viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground, true));
|
2017-03-29 16:30:28 +00:00
|
|
|
viewHolder.messageBody.setHighlightColor(ContextCompat.getColor(activity, darkBackground
|
2016-11-25 14:06:43 +00:00
|
|
|
? (type == SENT || !mUseGreenBackground ? R.color.black26 : R.color.grey800) : R.color.grey500));
|
2014-07-22 13:31:54 +00:00
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-12-06 17:23:59 +00:00
|
|
|
activity.startDownloadable(message);
|
2014-10-17 11:09:02 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:04:05 +00:00
|
|
|
private void displayOpenableMessage(ViewHolder viewHolder,final Message message) {
|
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.GONE);
|
|
|
|
viewHolder.download_button.setVisibility(View.VISIBLE);
|
2015-05-10 01:12:44 +00:00
|
|
|
viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message)));
|
2014-11-13 20:04:05 +00:00
|
|
|
viewHolder.download_button.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-01-12 15:09:39 +00:00
|
|
|
openDownloadable(message);
|
2014-11-13 20:04:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-07 13:15:38 +00:00
|
|
|
private void displayLocationMessage(ViewHolder viewHolder, final Message message) {
|
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.GONE);
|
|
|
|
viewHolder.download_button.setVisibility(View.VISIBLE);
|
|
|
|
viewHolder.download_button.setText(R.string.show_location);
|
|
|
|
viewHolder.download_button.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
showLocation(message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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);
|
2015-06-30 15:15:02 +00:00
|
|
|
FileParams params = message.getFileParams();
|
2014-10-14 16:16:03 +00:00
|
|
|
double target = metrics.density * 288;
|
2016-08-25 11:46:33 +00:00
|
|
|
int scaledW;
|
|
|
|
int scaledH;
|
|
|
|
if (Math.max(params.height, params.width) * metrics.density <= target) {
|
|
|
|
scaledW = (int) (params.width * metrics.density);
|
|
|
|
scaledH = (int) (params.height * metrics.density);
|
|
|
|
} else if (Math.max(params.height,params.width) <= target) {
|
|
|
|
scaledW = params.width;
|
|
|
|
scaledH = params.height;
|
|
|
|
} else if (params.width <= params.height) {
|
|
|
|
scaledW = (int) (params.width / ((double) params.height / target));
|
|
|
|
scaledH = (int) target;
|
2014-10-14 16:16:03 +00:00
|
|
|
} else {
|
2016-08-25 11:46:33 +00:00
|
|
|
scaledW = (int) target;
|
|
|
|
scaledH = (int) (params.height / ((double) params.width / target));
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2016-08-25 11:46:33 +00:00
|
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scaledW, scaledH);
|
2015-08-24 18:56:25 +00:00
|
|
|
layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4));
|
2015-07-19 12:26:03 +00:00
|
|
|
viewHolder.image.setLayoutParams(layoutParams);
|
2014-07-22 13:31:54 +00:00
|
|
|
activity.loadBitmap(message, viewHolder.image);
|
|
|
|
viewHolder.image.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-11 13:23:52 +00:00
|
|
|
openDownloadable(message);
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-04 13:39:16 +00:00
|
|
|
private void loadMoreMessages(Conversation conversation) {
|
2017-05-07 19:05:35 +00:00
|
|
|
conversation.setLastClearHistory(0,null);
|
2016-10-18 11:06:24 +00:00
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
2016-02-04 13:39:16 +00:00
|
|
|
conversation.setHasMessagesLeftOnServer(true);
|
|
|
|
conversation.setFirstMamReference(null);
|
2017-05-07 19:05:35 +00:00
|
|
|
long timestamp = conversation.getLastMessageTransmitted().getTimestamp();
|
2016-02-04 13:39:16 +00:00
|
|
|
if (timestamp == 0) {
|
|
|
|
timestamp = System.currentTimeMillis();
|
|
|
|
}
|
2017-01-25 17:35:22 +00:00
|
|
|
conversation.messagesLoaded.set(true);
|
2017-05-07 19:05:35 +00:00
|
|
|
MessageArchiveService.Query query = activity.xmppConnectionService.getMessageArchiveService().query(conversation, new MamReference(0), timestamp, false);
|
2017-01-23 16:14:30 +00:00
|
|
|
if (query != null) {
|
|
|
|
Toast.makeText(activity, R.string.fetching_history_from_server, Toast.LENGTH_LONG).show();
|
|
|
|
} else {
|
|
|
|
Toast.makeText(activity,R.string.not_fetching_history_retention_period, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2016-02-04 13:39:16 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2016-11-24 10:29:26 +00:00
|
|
|
final boolean omemoEncryption = message.getEncryption() == Message.ENCRYPTION_AXOLOTL;
|
|
|
|
final boolean isInValidSession = message.isValidInSession() && (!omemoEncryption || message.isTrusted());
|
2014-12-03 09:35:30 +00:00
|
|
|
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) {
|
2017-07-04 09:01:20 +00:00
|
|
|
case DATE_SEPARATOR:
|
|
|
|
view = activity.getLayoutInflater().inflate(R.layout.message_date_bubble, parent, false);
|
|
|
|
viewHolder.status_message = (TextView) view.findViewById(R.id.message_body);
|
|
|
|
viewHolder.message_box = (LinearLayout) view.findViewById(R.id.message_box);
|
|
|
|
break;
|
2015-01-11 15:22:29 +00:00
|
|
|
case SENT:
|
|
|
|
view = activity.getLayoutInflater().inflate(
|
|
|
|
R.layout.message_sent, parent, false);
|
|
|
|
viewHolder.message_box = (LinearLayout) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_box);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.contact_picture = (ImageView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_photo);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.download_button = (Button) view
|
2014-10-15 17:32:12 +00:00
|
|
|
.findViewById(R.id.download_button);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.indicator = (ImageView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.security_indicator);
|
2016-02-15 22:15:04 +00:00
|
|
|
viewHolder.edit_indicator = (ImageView) view.findViewById(R.id.edit_indicator);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.image = (ImageView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_image);
|
2016-10-19 17:43:30 +00:00
|
|
|
viewHolder.messageBody = (CopyTextView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_body);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.time = (TextView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_time);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.indicatorReceived = (ImageView) view
|
2014-09-20 13:49:25 +00:00
|
|
|
.findViewById(R.id.indicator_received);
|
2015-01-11 15:22:29 +00:00
|
|
|
break;
|
|
|
|
case RECEIVED:
|
|
|
|
view = activity.getLayoutInflater().inflate(
|
|
|
|
R.layout.message_received, parent, false);
|
|
|
|
viewHolder.message_box = (LinearLayout) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_box);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.contact_picture = (ImageView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_photo);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.download_button = (Button) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.download_button);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.indicator = (ImageView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.security_indicator);
|
2016-02-15 22:15:04 +00:00
|
|
|
viewHolder.edit_indicator = (ImageView) view.findViewById(R.id.edit_indicator);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.image = (ImageView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_image);
|
2016-10-19 17:43:30 +00:00
|
|
|
viewHolder.messageBody = (CopyTextView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_body);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.time = (TextView) view
|
2014-07-22 13:31:54 +00:00
|
|
|
.findViewById(R.id.message_time);
|
2015-01-11 15:22:29 +00:00
|
|
|
viewHolder.indicatorReceived = (ImageView) view
|
2014-11-07 14:38:20 +00:00
|
|
|
.findViewById(R.id.indicator_received);
|
2015-10-28 21:40:09 +00:00
|
|
|
viewHolder.encryption = (TextView) view.findViewById(R.id.message_encryption);
|
2015-01-11 15:22:29 +00:00
|
|
|
break;
|
|
|
|
case STATUS:
|
2015-01-18 12:44:18 +00:00
|
|
|
view = activity.getLayoutInflater().inflate(R.layout.message_status, parent, false);
|
|
|
|
viewHolder.contact_picture = (ImageView) view.findViewById(R.id.message_photo);
|
|
|
|
viewHolder.status_message = (TextView) view.findViewById(R.id.status_message);
|
2016-02-04 13:39:16 +00:00
|
|
|
viewHolder.load_more_messages = (Button) view.findViewById(R.id.load_more_messages);
|
2015-01-11 15:22:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
viewHolder = null;
|
|
|
|
break;
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2016-10-19 17:43:30 +00:00
|
|
|
if (viewHolder.messageBody != null) {
|
2016-11-25 14:06:43 +00:00
|
|
|
listSelectionManager.onCreate(viewHolder.messageBody,
|
|
|
|
new MessageBodyActionModeCallback(viewHolder.messageBody));
|
2016-10-19 17:43:30 +00:00
|
|
|
viewHolder.messageBody.setCopyHandler(this);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
Dark theme, theme switch, icons, style, strings
added some white icons,
changed hardcoded icons to theme attributes,
changed icon_edit_dark to icon_edit_body to reflect icons position,
grey message bubbles in dark theme,
misc
purged ic_action_chat as it wasn't used
preference use_white_background changed to use_green_background, default true
grey chat bubbles darker, text white
replaced all grey600 with black icons and 0.54 alpha attribute
highlightColor in dark grey chat bubble now darker than background
2016-05-12 18:00:18 +00:00
|
|
|
boolean darkBackground = type == RECEIVED && (!isInValidSession || mUseGreenBackground) || activity.isDarkTheme();
|
2015-08-24 18:56:25 +00:00
|
|
|
|
2017-07-04 09:01:20 +00:00
|
|
|
if (type == DATE_SEPARATOR) {
|
|
|
|
if (UIHelper.today(message.getTimeSent())) {
|
|
|
|
viewHolder.status_message.setText(R.string.today);
|
|
|
|
} else if (UIHelper.yesterday(message.getTimeSent())) {
|
|
|
|
viewHolder.status_message.setText(R.string.yesterday);
|
|
|
|
} else {
|
|
|
|
viewHolder.status_message.setText(DateUtils.formatDateTime(activity,message.getTimeSent(),DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR));
|
|
|
|
}
|
|
|
|
viewHolder.message_box.setBackgroundResource(activity.isDarkTheme() ? R.drawable.date_bubble_grey : R.drawable.date_bubble_white);
|
|
|
|
viewHolder.status_message.setTextColor(activity.getSecondaryTextColor());
|
|
|
|
return view;
|
|
|
|
} else if (type == STATUS) {
|
2016-02-04 13:39:16 +00:00
|
|
|
if ("LOAD_MORE".equals(message.getBody())) {
|
|
|
|
viewHolder.status_message.setVisibility(View.GONE);
|
|
|
|
viewHolder.contact_picture.setVisibility(View.GONE);
|
|
|
|
viewHolder.load_more_messages.setVisibility(View.VISIBLE);
|
|
|
|
viewHolder.load_more_messages.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
loadMoreMessages(message.getConversation());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
viewHolder.status_message.setVisibility(View.VISIBLE);
|
|
|
|
viewHolder.load_more_messages.setVisibility(View.GONE);
|
2017-03-08 09:32:42 +00:00
|
|
|
viewHolder.status_message.setText(message.getBody());
|
|
|
|
boolean showAvatar;
|
2016-02-04 13:39:16 +00:00
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
2017-03-08 09:32:42 +00:00
|
|
|
showAvatar = true;
|
|
|
|
loadAvatar(message,viewHolder.contact_picture,activity.getPixel(32));
|
|
|
|
} else if (message.getCounterpart() != null ){
|
|
|
|
showAvatar = true;
|
|
|
|
loadAvatar(message,viewHolder.contact_picture,activity.getPixel(32));
|
|
|
|
} else {
|
|
|
|
showAvatar = false;
|
|
|
|
}
|
|
|
|
if (showAvatar) {
|
2016-02-04 13:39:16 +00:00
|
|
|
viewHolder.contact_picture.setAlpha(0.5f);
|
2017-03-08 09:32:42 +00:00
|
|
|
viewHolder.contact_picture.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
viewHolder.contact_picture.setVisibility(View.GONE);
|
2016-02-04 13:39:16 +00:00
|
|
|
}
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
2014-10-07 09:51:16 +00:00
|
|
|
return view;
|
2015-10-29 11:08:15 +00:00
|
|
|
} else {
|
2017-03-08 09:32:42 +00:00
|
|
|
loadAvatar(message, viewHolder.contact_picture,activity.getPixel(48));
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 15:55:38 +00:00
|
|
|
viewHolder.contact_picture
|
2015-01-11 15:22:29 +00:00
|
|
|
.setOnClickListener(new OnClickListener() {
|
2014-12-15 15:55:38 +00:00
|
|
|
|
2015-01-11 15:22:29 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
|
|
|
|
MessageAdapter.this.mOnContactPictureClickedListener
|
2015-08-24 18:56:25 +00:00
|
|
|
.onContactPictureClicked(message);
|
2014-12-15 15:55:38 +00:00
|
|
|
}
|
2015-01-11 15:22:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2014-12-15 15:55:38 +00:00
|
|
|
viewHolder.contact_picture
|
2015-01-11 15:22:29 +00:00
|
|
|
.setOnLongClickListener(new OnLongClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
|
|
|
|
MessageAdapter.this.mOnContactPictureLongClickedListener
|
2015-08-24 18:56:25 +00:00
|
|
|
.onContactPictureLongClicked(message);
|
2015-01-11 15:22:29 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2014-12-15 15:55:38 +00:00
|
|
|
}
|
2015-01-11 15:22:29 +00:00
|
|
|
}
|
|
|
|
});
|
2014-09-20 14:02:49 +00:00
|
|
|
|
2015-07-10 13:11:03 +00:00
|
|
|
final Transferable transferable = message.getTransferable();
|
|
|
|
if (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING) {
|
|
|
|
if (transferable.getStatus() == Transferable.STATUS_OFFER) {
|
2015-01-18 12:00:57 +00:00
|
|
|
displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message)));
|
2015-07-10 13:11:03 +00:00
|
|
|
} else if (transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) {
|
2015-07-02 21:13:00 +00:00
|
|
|
displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
|
2015-01-18 12:00:57 +00:00
|
|
|
} else {
|
2015-08-24 18:56:25 +00:00
|
|
|
displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first,darkBackground);
|
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) {
|
2015-06-30 15:15:02 +00:00
|
|
|
if (message.getFileParams().width > 0) {
|
2014-12-03 09:35:30 +00:00
|
|
|
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) {
|
2016-06-13 11:32:14 +00:00
|
|
|
if (account.isPgpDecryptionServiceConnected()) {
|
|
|
|
if (!account.hasPendingPgpIntent(conversation)) {
|
2015-10-15 22:27:12 +00:00
|
|
|
displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground);
|
|
|
|
} else {
|
|
|
|
displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground);
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
} else {
|
2015-08-24 18:56:25 +00:00
|
|
|
displayInfoMessage(viewHolder,activity.getString(R.string.install_openkeychain),darkBackground);
|
2014-11-14 11:31:57 +00:00
|
|
|
if (viewHolder != null) {
|
|
|
|
viewHolder.message_box
|
2015-01-11 15:22:29 +00:00
|
|
|
.setOnClickListener(new OnClickListener() {
|
2014-11-14 11:31:57 +00:00
|
|
|
|
2015-01-11 15:22:29 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
activity.showInstallPgpDialog();
|
|
|
|
}
|
|
|
|
});
|
2014-11-14 11:31:57 +00:00
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2014-12-03 09:35:30 +00:00
|
|
|
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
2015-08-24 18:56:25 +00:00
|
|
|
displayDecryptionFailed(viewHolder,darkBackground);
|
2014-11-14 11:31:57 +00:00
|
|
|
} else {
|
2017-08-03 11:24:41 +00:00
|
|
|
if (message.isGeoUri()) {
|
2015-03-07 13:15:38 +00:00
|
|
|
displayLocationMessage(viewHolder,message);
|
2017-07-30 20:04:58 +00:00
|
|
|
} else if (message.bodyIsOnlyEmojis()) {
|
2017-08-03 08:55:14 +00:00
|
|
|
displayEmojiMessage(viewHolder, message.getBody().replaceAll("\\s",""));
|
2017-04-05 20:32:02 +00:00
|
|
|
} else if (message.treatAsDownloadable()) {
|
2016-03-04 20:30:34 +00:00
|
|
|
try {
|
|
|
|
URL url = new URL(message.getBody());
|
|
|
|
displayDownloadableMessage(viewHolder,
|
|
|
|
message,
|
|
|
|
activity.getString(R.string.check_x_filesize_on_host,
|
|
|
|
UIHelper.getFileDescriptionString(activity, message),
|
|
|
|
url.getHost()));
|
|
|
|
} catch (Exception e) {
|
|
|
|
displayDownloadableMessage(viewHolder,
|
|
|
|
message,
|
|
|
|
activity.getString(R.string.check_x_filesize,
|
|
|
|
UIHelper.getFileDescriptionString(activity, message)));
|
|
|
|
}
|
2015-03-07 13:15:38 +00:00
|
|
|
} else {
|
Dark theme, theme switch, icons, style, strings
added some white icons,
changed hardcoded icons to theme attributes,
changed icon_edit_dark to icon_edit_body to reflect icons position,
grey message bubbles in dark theme,
misc
purged ic_action_chat as it wasn't used
preference use_white_background changed to use_green_background, default true
grey chat bubbles darker, text white
replaced all grey600 with black icons and 0.54 alpha attribute
highlightColor in dark grey chat bubble now darker than background
2016-05-12 18:00:18 +00:00
|
|
|
displayTextMessage(viewHolder, message, darkBackground, type);
|
2015-03-07 13:15:38 +00:00
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 00:49:14 +00:00
|
|
|
if (type == RECEIVED) {
|
2015-08-24 18:56:25 +00:00
|
|
|
if(isInValidSession) {
|
2016-06-10 20:39:02 +00:00
|
|
|
int bubble;
|
Dark theme, theme switch, icons, style, strings
added some white icons,
changed hardcoded icons to theme attributes,
changed icon_edit_dark to icon_edit_body to reflect icons position,
grey message bubbles in dark theme,
misc
purged ic_action_chat as it wasn't used
preference use_white_background changed to use_green_background, default true
grey chat bubbles darker, text white
replaced all grey600 with black icons and 0.54 alpha attribute
highlightColor in dark grey chat bubble now darker than background
2016-05-12 18:00:18 +00:00
|
|
|
if (!mUseGreenBackground) {
|
2016-06-10 20:39:02 +00:00
|
|
|
bubble = activity.getThemeResource(R.attr.message_bubble_received_monochrome, R.drawable.message_bubble_received_white);
|
2015-08-24 18:56:25 +00:00
|
|
|
} else {
|
2016-06-10 20:39:02 +00:00
|
|
|
bubble = activity.getThemeResource(R.attr.message_bubble_received_green, R.drawable.message_bubble_received);
|
2015-08-24 18:56:25 +00:00
|
|
|
}
|
2016-06-10 20:39:02 +00:00
|
|
|
viewHolder.message_box.setBackgroundResource(bubble);
|
2015-10-28 21:40:09 +00:00
|
|
|
viewHolder.encryption.setVisibility(View.GONE);
|
2015-07-30 17:16:58 +00:00
|
|
|
} else {
|
|
|
|
viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_warning);
|
2015-10-28 21:40:09 +00:00
|
|
|
viewHolder.encryption.setVisibility(View.VISIBLE);
|
2016-11-24 10:29:26 +00:00
|
|
|
if (omemoEncryption && !message.isTrusted()) {
|
|
|
|
viewHolder.encryption.setText(R.string.not_trusted);
|
|
|
|
} else {
|
|
|
|
viewHolder.encryption.setText(CryptoHelper.encryptionTypeToText(message.getEncryption()));
|
|
|
|
}
|
2015-07-29 00:49:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 07:26:55 +00:00
|
|
|
displayStatus(viewHolder, message, type, darkBackground);
|
2014-07-22 13:31:54 +00:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2016-09-18 13:35:14 +00:00
|
|
|
@Override
|
|
|
|
public void notifyDataSetChanged() {
|
|
|
|
listSelectionManager.onBeforeNotifyDataSetChanged();
|
|
|
|
super.notifyDataSetChanged();
|
|
|
|
listSelectionManager.onAfterNotifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2016-11-25 14:06:43 +00:00
|
|
|
private String transformText(CharSequence text, int start, int end, boolean forCopy) {
|
|
|
|
SpannableStringBuilder builder = new SpannableStringBuilder(text);
|
|
|
|
Object copySpan = new Object();
|
|
|
|
builder.setSpan(copySpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
DividerSpan[] dividerSpans = builder.getSpans(0, builder.length(), DividerSpan.class);
|
|
|
|
for (DividerSpan dividerSpan : dividerSpans) {
|
|
|
|
builder.replace(builder.getSpanStart(dividerSpan), builder.getSpanEnd(dividerSpan),
|
|
|
|
dividerSpan.isLarge() ? "\n\n" : "\n");
|
|
|
|
}
|
|
|
|
start = builder.getSpanStart(copySpan);
|
|
|
|
end = builder.getSpanEnd(copySpan);
|
|
|
|
if (start == -1 || end == -1) return "";
|
|
|
|
builder = new SpannableStringBuilder(builder, start, end);
|
|
|
|
if (forCopy) {
|
|
|
|
QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class);
|
|
|
|
for (QuoteSpan quoteSpan : quoteSpans) {
|
|
|
|
builder.insert(builder.getSpanStart(quoteSpan), "> ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
2016-10-19 17:43:30 +00:00
|
|
|
@Override
|
|
|
|
public String transformTextForCopy(CharSequence text, int start, int end) {
|
2016-11-25 14:06:43 +00:00
|
|
|
if (text instanceof Spanned) {
|
|
|
|
return transformText(text, start, end, true);
|
|
|
|
} else {
|
|
|
|
return text.toString().substring(start, end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnQuoteListener {
|
|
|
|
public void onQuote(String text);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class MessageBodyActionModeCallback implements ActionMode.Callback {
|
|
|
|
|
|
|
|
private final TextView textView;
|
|
|
|
|
|
|
|
public MessageBodyActionModeCallback(TextView textView) {
|
|
|
|
this.textView = textView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
if (onQuoteListener != null) {
|
|
|
|
int quoteResId = activity.getThemeResource(R.attr.icon_quote, R.drawable.ic_action_reply);
|
|
|
|
// 3rd item is placed after "copy" item
|
|
|
|
menu.add(0, android.R.id.button1, 3, R.string.quote).setIcon(quoteResId)
|
|
|
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
if (item.getItemId() == android.R.id.button1) {
|
|
|
|
int start = textView.getSelectionStart();
|
|
|
|
int end = textView.getSelectionEnd();
|
|
|
|
if (end > start) {
|
|
|
|
String text = transformText(textView.getText(), start, end, false);
|
|
|
|
if (onQuoteListener != null) {
|
|
|
|
onQuoteListener.onQuote(text);
|
|
|
|
}
|
|
|
|
mode.finish();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {}
|
2016-10-19 17:43:30 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 15:09:39 +00:00
|
|
|
public void openDownloadable(Message message) {
|
|
|
|
DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
|
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);
|
2015-10-20 15:41:07 +00:00
|
|
|
String mime = file.getMimeType();
|
|
|
|
if (mime == null) {
|
|
|
|
mime = "*/*";
|
|
|
|
}
|
2016-09-04 20:59:40 +00:00
|
|
|
Uri uri;
|
2017-01-09 16:00:08 +00:00
|
|
|
try {
|
|
|
|
uri = FileBackend.getUriForFile(activity, file);
|
|
|
|
} catch (SecurityException e) {
|
|
|
|
Toast.makeText(activity, activity.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
2016-09-04 20:59:40 +00:00
|
|
|
}
|
2016-08-25 20:41:33 +00:00
|
|
|
openIntent.setDataAndType(uri, mime);
|
2017-01-09 16:00:08 +00:00
|
|
|
openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
2014-11-15 14:16:40 +00:00
|
|
|
PackageManager manager = activity.getPackageManager();
|
2016-09-04 20:59:40 +00:00
|
|
|
List<ResolveInfo> info = manager.queryIntentActivities(openIntent, 0);
|
|
|
|
if (info.size() == 0) {
|
2017-01-09 16:00:08 +00:00
|
|
|
openIntent.setDataAndType(uri,"*/*");
|
2015-10-20 15:41:07 +00:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
getContext().startActivity(openIntent);
|
|
|
|
} catch (ActivityNotFoundException e) {
|
2016-09-04 20:59:40 +00:00
|
|
|
Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show();
|
2014-11-15 14:16:40 +00:00
|
|
|
}
|
2014-11-13 20:04:05 +00:00
|
|
|
}
|
|
|
|
|
2015-03-07 13:15:38 +00:00
|
|
|
public void showLocation(Message message) {
|
|
|
|
for(Intent intent : GeoHelper.createGeoIntentsFromMessage(message)) {
|
|
|
|
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
|
|
|
|
getContext().startActivity(intent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Toast.makeText(activity,R.string.no_application_found_to_display_location,Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
2015-08-24 18:56:25 +00:00
|
|
|
public void updatePreferences() {
|
|
|
|
this.mIndicateReceived = activity.indicateReceived();
|
Dark theme, theme switch, icons, style, strings
added some white icons,
changed hardcoded icons to theme attributes,
changed icon_edit_dark to icon_edit_body to reflect icons position,
grey message bubbles in dark theme,
misc
purged ic_action_chat as it wasn't used
preference use_white_background changed to use_green_background, default true
grey chat bubbles darker, text white
replaced all grey600 with black icons and 0.54 alpha attribute
highlightColor in dark grey chat bubble now darker than background
2016-05-12 18:00:18 +00:00
|
|
|
this.mUseGreenBackground = activity.useGreenBackground();
|
2015-08-24 18:56:25 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 22:18:34 +00:00
|
|
|
public TextView getMessageBody(View view) {
|
|
|
|
final Object tag = view.getTag();
|
|
|
|
if (tag instanceof ViewHolder) {
|
|
|
|
final ViewHolder viewHolder = (ViewHolder) tag;
|
|
|
|
return viewHolder.messageBody;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-11-07 14:38:20 +00:00
|
|
|
public interface OnContactPictureClicked {
|
2015-08-24 18:56:25 +00:00
|
|
|
void onContactPictureClicked(Message message);
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnContactPictureLongClicked {
|
2015-08-24 18:56:25 +00:00
|
|
|
void onContactPictureLongClicked(Message message);
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2016-10-19 17:43:30 +00:00
|
|
|
protected CopyTextView messageBody;
|
2014-07-22 13:31:54 +00:00
|
|
|
protected ImageView contact_picture;
|
2015-01-18 12:44:18 +00:00
|
|
|
protected TextView status_message;
|
2015-10-28 21:40:09 +00:00
|
|
|
protected TextView encryption;
|
2016-02-04 13:39:16 +00:00
|
|
|
public Button load_more_messages;
|
2016-02-15 22:15:04 +00:00
|
|
|
public ImageView edit_indicator;
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|
2015-10-29 11:08:15 +00:00
|
|
|
|
|
|
|
class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {
|
|
|
|
private final WeakReference<ImageView> imageViewReference;
|
|
|
|
private Message message = null;
|
2017-03-08 09:32:42 +00:00
|
|
|
private final int size;
|
2015-10-29 11:08:15 +00:00
|
|
|
|
2017-03-08 09:32:42 +00:00
|
|
|
public BitmapWorkerTask(ImageView imageView, int size) {
|
2015-10-29 11:08:15 +00:00
|
|
|
imageViewReference = new WeakReference<>(imageView);
|
2017-03-08 09:32:42 +00:00
|
|
|
this.size = size;
|
2015-10-29 11:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Bitmap doInBackground(Message... params) {
|
2017-03-08 09:32:42 +00:00
|
|
|
return activity.avatarService().get(params[0], size, isCancelled());
|
2015-10-29 11:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Bitmap bitmap) {
|
2016-04-29 18:38:23 +00:00
|
|
|
if (bitmap != null && !isCancelled()) {
|
2015-10-29 11:08:15 +00:00
|
|
|
final ImageView imageView = imageViewReference.get();
|
|
|
|
if (imageView != null) {
|
|
|
|
imageView.setImageBitmap(bitmap);
|
|
|
|
imageView.setBackgroundColor(0x00000000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 09:32:42 +00:00
|
|
|
public void loadAvatar(Message message, ImageView imageView, int size) {
|
2015-10-29 11:08:15 +00:00
|
|
|
if (cancelPotentialWork(message, imageView)) {
|
2017-03-08 09:32:42 +00:00
|
|
|
final Bitmap bm = activity.avatarService().get(message, size, true);
|
2015-10-29 11:08:15 +00:00
|
|
|
if (bm != null) {
|
2016-04-29 18:38:23 +00:00
|
|
|
cancelPotentialWork(message, imageView);
|
2015-10-29 11:08:15 +00:00
|
|
|
imageView.setImageBitmap(bm);
|
|
|
|
imageView.setBackgroundColor(0x00000000);
|
|
|
|
} else {
|
|
|
|
imageView.setBackgroundColor(UIHelper.getColorForName(UIHelper.getMessageDisplayName(message)));
|
|
|
|
imageView.setImageDrawable(null);
|
2017-03-08 09:32:42 +00:00
|
|
|
final BitmapWorkerTask task = new BitmapWorkerTask(imageView, size);
|
2015-10-29 11:08:15 +00:00
|
|
|
final AsyncDrawable asyncDrawable = new AsyncDrawable(activity.getResources(), null, task);
|
|
|
|
imageView.setImageDrawable(asyncDrawable);
|
|
|
|
try {
|
|
|
|
task.execute(message);
|
|
|
|
} catch (final RejectedExecutionException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean cancelPotentialWork(Message message, ImageView imageView) {
|
|
|
|
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
|
|
|
|
|
|
|
|
if (bitmapWorkerTask != null) {
|
|
|
|
final Message oldMessage = bitmapWorkerTask.message;
|
|
|
|
if (oldMessage == null || message != oldMessage) {
|
|
|
|
bitmapWorkerTask.cancel(true);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
|
|
|
|
if (imageView != null) {
|
|
|
|
final Drawable drawable = imageView.getDrawable();
|
|
|
|
if (drawable instanceof AsyncDrawable) {
|
|
|
|
final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
|
|
|
|
return asyncDrawable.getBitmapWorkerTask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static class AsyncDrawable extends BitmapDrawable {
|
|
|
|
private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;
|
|
|
|
|
|
|
|
public AsyncDrawable(Resources res, Bitmap bitmap, BitmapWorkerTask bitmapWorkerTask) {
|
|
|
|
super(res, bitmap);
|
|
|
|
bitmapWorkerTaskReference = new WeakReference<>(bitmapWorkerTask);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BitmapWorkerTask getBitmapWorkerTask() {
|
|
|
|
return bitmapWorkerTaskReference.get();
|
|
|
|
}
|
|
|
|
}
|
2014-07-22 13:31:54 +00:00
|
|
|
}
|