2017-10-16 13:11:42 -07:00
|
|
|
/*
|
2011-12-20 10:20:44 -08:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-07-19 19:23:49 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-07-19 19:23:49 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-01-31 19:28:40 -08:00
|
|
|
package org.thoughtcrime.securesms.conversation;
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
import android.annotation.SuppressLint;
|
2014-10-15 22:26:55 -07:00
|
|
|
import android.content.ActivityNotFoundException;
|
2011-12-20 10:20:44 -08:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2014-02-23 13:59:12 -08:00
|
|
|
import android.content.res.TypedArray;
|
2015-06-30 09:16:05 -07:00
|
|
|
import android.graphics.Color;
|
2015-06-29 08:49:32 -07:00
|
|
|
import android.graphics.PorterDuff;
|
2019-02-26 19:29:52 -08:00
|
|
|
import android.graphics.Typeface;
|
2017-03-28 12:05:30 -07:00
|
|
|
import android.net.Uri;
|
2019-02-01 09:06:59 -08:00
|
|
|
import android.text.Spannable;
|
2017-03-28 14:34:36 +02:00
|
|
|
import android.text.SpannableString;
|
2019-02-26 19:29:52 -08:00
|
|
|
import android.text.SpannableStringBuilder;
|
2017-03-28 14:34:36 +02:00
|
|
|
import android.text.Spanned;
|
2019-02-26 19:29:52 -08:00
|
|
|
import android.text.TextPaint;
|
2015-01-29 20:37:01 -10:00
|
|
|
import android.text.TextUtils;
|
2019-02-01 09:06:59 -08:00
|
|
|
import android.text.style.BackgroundColorSpan;
|
2019-02-26 19:29:52 -08:00
|
|
|
import android.text.style.CharacterStyle;
|
|
|
|
import android.text.style.ClickableSpan;
|
2019-02-01 09:06:59 -08:00
|
|
|
import android.text.style.ForegroundColorSpan;
|
2017-03-28 14:34:36 +02:00
|
|
|
import android.text.style.URLSpan;
|
2015-09-15 15:28:27 -07:00
|
|
|
import android.text.util.Linkify;
|
2012-07-19 19:23:49 -07:00
|
|
|
import android.util.AttributeSet;
|
2017-04-14 22:59:30 -07:00
|
|
|
import android.util.TypedValue;
|
2011-12-20 10:20:44 -08:00
|
|
|
import android.view.View;
|
2015-06-29 08:49:32 -07:00
|
|
|
import android.view.ViewGroup;
|
2019-09-12 16:42:52 +10:00
|
|
|
import android.widget.ImageView;
|
2011-12-20 10:20:44 -08:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
2014-10-15 22:26:55 -07:00
|
|
|
import android.widget.Toast;
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2020-08-19 11:40:34 +10:00
|
|
|
import androidx.annotation.DimenRes;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
|
2019-02-20 17:00:23 -08:00
|
|
|
import com.annimon.stream.Stream;
|
|
|
|
|
2019-06-21 12:21:48 +10:00
|
|
|
import org.thoughtcrime.securesms.ApplicationContext;
|
|
|
|
import org.thoughtcrime.securesms.BindableConversationItem;
|
|
|
|
import org.thoughtcrime.securesms.ConfirmIdentityDialog;
|
|
|
|
import org.thoughtcrime.securesms.MediaPreviewActivity;
|
|
|
|
import org.thoughtcrime.securesms.MessageDetailsActivity;
|
2017-07-21 15:59:27 -07:00
|
|
|
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
2016-08-14 07:55:43 +02:00
|
|
|
import org.thoughtcrime.securesms.components.AlertView;
|
2015-10-21 15:32:29 -07:00
|
|
|
import org.thoughtcrime.securesms.components.AudioView;
|
2018-06-26 10:27:44 -07:00
|
|
|
import org.thoughtcrime.securesms.components.ConversationItemFooter;
|
|
|
|
import org.thoughtcrime.securesms.components.ConversationItemThumbnail;
|
2017-03-28 12:05:30 -07:00
|
|
|
import org.thoughtcrime.securesms.components.DocumentView;
|
2019-06-21 12:21:48 +10:00
|
|
|
import org.thoughtcrime.securesms.components.LinkPreviewView;
|
2018-02-07 14:01:37 -08:00
|
|
|
import org.thoughtcrime.securesms.components.QuoteView;
|
2018-04-26 17:03:54 -07:00
|
|
|
import org.thoughtcrime.securesms.components.SharedContactView;
|
2019-04-17 10:21:30 -04:00
|
|
|
import org.thoughtcrime.securesms.components.StickerView;
|
2019-06-21 12:21:48 +10:00
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
|
2018-04-26 17:03:54 -07:00
|
|
|
import org.thoughtcrime.securesms.contactshare.Contact;
|
2019-06-21 12:21:48 +10:00
|
|
|
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
2014-03-01 14:17:55 -08:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2012-07-19 19:23:49 -07:00
|
|
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
2015-01-15 13:35:35 -08:00
|
|
|
import org.thoughtcrime.securesms.database.MmsSmsDatabase;
|
2014-03-01 14:17:55 -08:00
|
|
|
import org.thoughtcrime.securesms.database.SmsDatabase;
|
2015-05-21 19:13:03 +02:00
|
|
|
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch;
|
2012-10-28 16:04:24 -07:00
|
|
|
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2017-01-20 15:26:17 -08:00
|
|
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
2018-02-07 14:01:37 -08:00
|
|
|
import org.thoughtcrime.securesms.database.model.Quote;
|
2017-07-21 15:59:27 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.MmsDownloadJob;
|
2014-11-08 11:35:58 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.MmsSendJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.SmsSendJob;
|
2019-06-21 12:21:48 +10:00
|
|
|
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
|
|
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2020-05-11 16:19:26 +10:00
|
|
|
import org.thoughtcrime.securesms.loki.utilities.MentionUtilities;
|
|
|
|
import org.thoughtcrime.securesms.loki.views.ProfilePictureView;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2019-01-15 00:41:05 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.ImageSlide;
|
2014-12-12 01:03:24 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
2012-07-19 19:23:49 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.Slide;
|
2015-10-21 15:32:29 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.SlideClickListener;
|
2018-11-08 23:33:37 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.SlidesClickedListener;
|
2019-02-26 19:29:52 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.TextSlide;
|
2012-07-19 19:23:49 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
2019-04-17 10:21:30 -04:00
|
|
|
import org.thoughtcrime.securesms.stickers.StickerUrl;
|
2019-09-12 16:42:52 +10:00
|
|
|
import org.thoughtcrime.securesms.util.DateUtils;
|
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.LongClickCopySpan;
|
|
|
|
import org.thoughtcrime.securesms.util.LongClickMovementMethod;
|
|
|
|
import org.thoughtcrime.securesms.util.SearchUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.thoughtcrime.securesms.util.ThemeUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2017-01-20 09:11:40 -08:00
|
|
|
import org.thoughtcrime.securesms.util.views.Stub;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2020-07-15 12:24:43 +10:00
|
|
|
import org.whispersystems.signalservice.loki.api.opengroups.PublicChat;
|
|
|
|
import org.whispersystems.signalservice.loki.api.opengroups.PublicChatAPI;
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2018-11-08 23:33:37 -08:00
|
|
|
import java.util.Collections;
|
2015-10-21 15:32:29 -07:00
|
|
|
import java.util.HashSet;
|
2015-05-26 13:12:11 -07:00
|
|
|
import java.util.List;
|
2015-03-19 13:08:48 -07:00
|
|
|
import java.util.Locale;
|
2014-12-13 18:10:59 -08:00
|
|
|
import java.util.Set;
|
|
|
|
|
2019-08-05 16:27:37 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
/**
|
|
|
|
* A view that displays an individual conversation item within a conversation
|
|
|
|
* thread. Used by ComposeMessageActivity's ListActivity via a ConversationAdapter.
|
2012-07-19 19:23:49 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-09-15 15:28:27 -07:00
|
|
|
public class ConversationItem extends LinearLayout
|
2017-08-01 08:56:00 -07:00
|
|
|
implements RecipientModifiedListener, BindableConversationItem
|
2015-09-15 15:28:27 -07:00
|
|
|
{
|
2018-07-12 16:03:32 -07:00
|
|
|
private static final String TAG = ConversationItem.class.getSimpleName();
|
|
|
|
|
2019-02-26 19:29:52 -08:00
|
|
|
private static final int MAX_MEASURE_CALLS = 3;
|
|
|
|
private static final int MAX_BODY_DISPLAY_LENGTH = 1000;
|
2011-12-20 10:20:44 -08:00
|
|
|
|
|
|
|
private MessageRecord messageRecord;
|
2015-03-19 13:08:48 -07:00
|
|
|
private Locale locale;
|
2013-05-05 12:51:36 -07:00
|
|
|
private boolean groupThread;
|
2015-07-22 17:47:38 -07:00
|
|
|
private Recipient recipient;
|
2017-10-16 13:11:42 -07:00
|
|
|
private GlideRequests glideRequests;
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2018-07-25 01:16:48 -04:00
|
|
|
protected ViewGroup bodyBubble;
|
2018-07-18 13:53:50 -07:00
|
|
|
private QuoteView quoteView;
|
2019-02-26 19:29:52 -08:00
|
|
|
private EmojiTextView bodyText;
|
2018-07-18 13:53:50 -07:00
|
|
|
private ConversationItemFooter footer;
|
2019-04-17 10:21:30 -04:00
|
|
|
private ConversationItemFooter stickerFooter;
|
2018-07-18 13:53:50 -07:00
|
|
|
private TextView groupSender;
|
|
|
|
private TextView groupSenderProfileName;
|
|
|
|
private View groupSenderHolder;
|
2020-01-13 15:29:06 +11:00
|
|
|
private ProfilePictureView profilePictureView;
|
2019-09-12 16:42:52 +10:00
|
|
|
private ImageView moderatorIconImageView;
|
2018-07-25 01:16:48 -04:00
|
|
|
private ViewGroup contactPhotoHolder;
|
2018-07-18 13:53:50 -07:00
|
|
|
private AlertView alertView;
|
|
|
|
private ViewGroup container;
|
2018-06-26 10:27:44 -07:00
|
|
|
|
|
|
|
private @NonNull Set<MessageRecord> batchSelected = new HashSet<>();
|
2019-05-22 13:51:56 -03:00
|
|
|
private Recipient conversationRecipient;
|
|
|
|
private Stub<ConversationItemThumbnail> mediaThumbnailStub;
|
|
|
|
private Stub<AudioView> audioViewStub;
|
|
|
|
private Stub<DocumentView> documentViewStub;
|
|
|
|
private Stub<SharedContactView> sharedContactStub;
|
|
|
|
private Stub<LinkPreviewView> linkPreviewStub;
|
2019-04-17 10:21:30 -04:00
|
|
|
private Stub<StickerView> stickerStub;
|
2018-06-26 10:27:44 -07:00
|
|
|
private @Nullable EventListener eventListener;
|
2015-01-29 20:37:01 -10:00
|
|
|
|
2015-09-15 15:28:27 -07:00
|
|
|
private int defaultBubbleColor;
|
2018-07-12 16:03:32 -07:00
|
|
|
private int measureCalls;
|
2015-07-20 13:40:57 -07:00
|
|
|
|
2018-11-08 23:33:37 -08:00
|
|
|
private final PassthroughClickListener passthroughClickListener = new PassthroughClickListener();
|
|
|
|
private final AttachmentDownloadClickListener downloadClickListener = new AttachmentDownloadClickListener();
|
|
|
|
private final SlideClickPassthroughListener singleDownloadClickListener = new SlideClickPassthroughListener(downloadClickListener);
|
|
|
|
private final SharedContactEventListener sharedContactEventListener = new SharedContactEventListener();
|
|
|
|
private final SharedContactClickListener sharedContactClickListener = new SharedContactClickListener();
|
2019-01-15 00:41:05 -08:00
|
|
|
private final LinkPreviewClickListener linkPreviewClickListener = new LinkPreviewClickListener();
|
2017-01-20 09:11:40 -08:00
|
|
|
|
|
|
|
private final Context context;
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public ConversationItem(Context context) {
|
2015-09-15 15:28:27 -07:00
|
|
|
this(context, null);
|
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
|
|
|
|
public ConversationItem(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
2015-09-23 17:19:24 -07:00
|
|
|
@Override
|
|
|
|
public void setOnClickListener(OnClickListener l) {
|
|
|
|
super.setOnClickListener(new ClickListener(l));
|
|
|
|
}
|
|
|
|
|
2012-07-19 19:23:49 -07:00
|
|
|
@Override
|
|
|
|
protected void onFinishInflate() {
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
2015-07-20 13:40:57 -07:00
|
|
|
initializeAttributes();
|
2015-06-29 08:49:32 -07:00
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
this.bodyText = findViewById(R.id.conversation_item_body);
|
2018-06-26 10:27:44 -07:00
|
|
|
this.footer = findViewById(R.id.conversation_item_footer);
|
2019-04-17 10:21:30 -04:00
|
|
|
this.stickerFooter = findViewById(R.id.conversation_item_sticker_footer);
|
2017-10-16 13:11:42 -07:00
|
|
|
this.groupSender = findViewById(R.id.group_message_sender);
|
|
|
|
this.groupSenderProfileName = findViewById(R.id.group_message_sender_profile);
|
|
|
|
this.alertView = findViewById(R.id.indicators_parent);
|
2020-01-13 15:29:06 +11:00
|
|
|
this.profilePictureView = findViewById(R.id.profilePictureView);
|
2019-10-10 13:53:02 +11:00
|
|
|
this.moderatorIconImageView = findViewById(R.id.moderator_icon_image_view);
|
2018-07-25 01:16:48 -04:00
|
|
|
this.contactPhotoHolder = findViewById(R.id.contact_photo_container);
|
2017-10-16 13:11:42 -07:00
|
|
|
this.bodyBubble = findViewById(R.id.body_bubble);
|
|
|
|
this.mediaThumbnailStub = new Stub<>(findViewById(R.id.image_view_stub));
|
|
|
|
this.audioViewStub = new Stub<>(findViewById(R.id.audio_view_stub));
|
|
|
|
this.documentViewStub = new Stub<>(findViewById(R.id.document_view_stub));
|
2018-04-26 17:03:54 -07:00
|
|
|
this.sharedContactStub = new Stub<>(findViewById(R.id.shared_contact_view_stub));
|
2019-01-15 00:41:05 -08:00
|
|
|
this.linkPreviewStub = new Stub<>(findViewById(R.id.link_preview_stub));
|
2019-04-17 10:21:30 -04:00
|
|
|
this.stickerStub = new Stub<>(findViewById(R.id.sticker_view_stub));
|
2017-10-16 13:11:42 -07:00
|
|
|
this.groupSenderHolder = findViewById(R.id.group_sender_holder);
|
2018-02-07 14:01:37 -08:00
|
|
|
this.quoteView = findViewById(R.id.quote_view);
|
2018-06-26 10:27:44 -07:00
|
|
|
this.container = findViewById(R.id.container);
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2015-09-23 17:19:24 -07:00
|
|
|
setOnClickListener(new ClickListener(null));
|
2015-10-21 15:32:29 -07:00
|
|
|
|
2015-09-15 15:28:27 -07:00
|
|
|
bodyText.setOnLongClickListener(passthroughClickListener);
|
|
|
|
bodyText.setOnClickListener(passthroughClickListener);
|
2017-03-28 14:34:36 +02:00
|
|
|
|
|
|
|
bodyText.setMovementMethod(LongClickMovementMethod.getInstance(getContext()));
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2015-09-15 15:28:27 -07:00
|
|
|
@Override
|
2018-06-26 10:27:44 -07:00
|
|
|
public void bind(@NonNull MessageRecord messageRecord,
|
|
|
|
@NonNull Optional<MessageRecord> previousMessageRecord,
|
|
|
|
@NonNull Optional<MessageRecord> nextMessageRecord,
|
|
|
|
@NonNull GlideRequests glideRequests,
|
|
|
|
@NonNull Locale locale,
|
|
|
|
@NonNull Set<MessageRecord> batchSelected,
|
|
|
|
@NonNull Recipient conversationRecipient,
|
2019-02-01 09:06:59 -08:00
|
|
|
@Nullable String searchQuery,
|
2018-06-26 10:27:44 -07:00
|
|
|
boolean pulseHighlight)
|
2011-12-20 10:20:44 -08:00
|
|
|
{
|
2014-12-13 18:10:59 -08:00
|
|
|
this.messageRecord = messageRecord;
|
2015-03-19 13:08:48 -07:00
|
|
|
this.locale = locale;
|
2017-10-16 13:11:42 -07:00
|
|
|
this.glideRequests = glideRequests;
|
2014-12-13 18:10:59 -08:00
|
|
|
this.batchSelected = batchSelected;
|
2017-08-01 08:56:00 -07:00
|
|
|
this.conversationRecipient = conversationRecipient;
|
|
|
|
this.groupThread = conversationRecipient.isGroupRecipient();
|
2015-07-22 17:47:38 -07:00
|
|
|
this.recipient = messageRecord.getIndividualRecipient();
|
|
|
|
|
|
|
|
this.recipient.addListener(this);
|
2017-08-01 08:56:00 -07:00
|
|
|
this.conversationRecipient.addListener(this);
|
2014-12-13 18:10:59 -08:00
|
|
|
|
2018-07-18 13:53:50 -07:00
|
|
|
setGutterSizes(messageRecord, groupThread);
|
|
|
|
setMessageShape(messageRecord, previousMessageRecord, nextMessageRecord, groupThread);
|
|
|
|
setMediaAttributes(messageRecord, previousMessageRecord, nextMessageRecord, conversationRecipient, groupThread);
|
2018-07-12 16:03:32 -07:00
|
|
|
setInteractionState(messageRecord, pulseHighlight);
|
2019-10-09 16:41:14 +11:00
|
|
|
setBodyText(messageRecord, searchQuery, groupThread);
|
2018-07-12 16:03:32 -07:00
|
|
|
setBubbleState(messageRecord);
|
|
|
|
setStatusIcons(messageRecord);
|
|
|
|
setContactPhoto(recipient);
|
|
|
|
setGroupMessageStatus(messageRecord, recipient);
|
2019-04-17 10:21:30 -04:00
|
|
|
setGroupAuthorColor(messageRecord);
|
2018-07-12 16:03:32 -07:00
|
|
|
setAuthor(messageRecord, previousMessageRecord, nextMessageRecord, groupThread);
|
|
|
|
setQuote(messageRecord, previousMessageRecord, nextMessageRecord, groupThread);
|
2018-07-23 14:08:45 +02:00
|
|
|
setMessageSpacing(context, messageRecord, previousMessageRecord, nextMessageRecord, groupThread);
|
2018-07-12 16:03:32 -07:00
|
|
|
setFooter(messageRecord, nextMessageRecord, locale, groupThread);
|
2020-01-15 16:13:28 +11:00
|
|
|
adjustMarginsIfNeeded(messageRecord);
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2018-04-02 16:17:32 -07:00
|
|
|
@Override
|
|
|
|
public void setEventListener(@Nullable EventListener eventListener) {
|
|
|
|
this.eventListener = eventListener;
|
|
|
|
}
|
|
|
|
|
2017-08-15 19:23:42 -07:00
|
|
|
@Override
|
2018-06-26 10:27:44 -07:00
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
2017-08-15 19:23:42 -07:00
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
if (isInEditMode()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-15 19:23:42 -07:00
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
boolean needsMeasure = false;
|
2017-08-15 19:23:42 -07:00
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
if (hasQuote(messageRecord)) {
|
|
|
|
int quoteWidth = quoteView.getMeasuredWidth();
|
|
|
|
int availableWidth = getAvailableMessageBubbleWidth(quoteView);
|
2017-08-15 19:23:42 -07:00
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
if (quoteWidth != availableWidth) {
|
|
|
|
quoteView.getLayoutParams().width = availableWidth;
|
|
|
|
needsMeasure = true;
|
2017-08-15 19:23:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 15:13:08 +10:00
|
|
|
if (hasThumbnail(messageRecord) && messageRecord.getDisplayBody(context).length() > 0) {
|
|
|
|
ViewUtil.updateLayoutParams(bodyText, getAvailableMessageBubbleWidth(bodyText), ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
}
|
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
ConversationItemFooter activeFooter = getActiveFooter(messageRecord);
|
|
|
|
int availableWidth = getAvailableMessageBubbleWidth(footer);
|
2018-04-02 16:17:32 -07:00
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
if (activeFooter.getVisibility() != GONE && activeFooter.getMeasuredWidth() != availableWidth) {
|
|
|
|
activeFooter.getLayoutParams().width = availableWidth;
|
|
|
|
needsMeasure = true;
|
|
|
|
}
|
2018-04-02 16:17:32 -07:00
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
if (needsMeasure) {
|
2018-07-12 16:03:32 -07:00
|
|
|
if (measureCalls < MAX_MEASURE_CALLS) {
|
|
|
|
measureCalls++;
|
2018-07-23 07:54:24 -07:00
|
|
|
measure(widthMeasureSpec, heightMeasureSpec);
|
2018-07-12 16:03:32 -07:00
|
|
|
} else {
|
|
|
|
Log.w(TAG, "Hit measure() cap of " + MAX_MEASURE_CALLS);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
measureCalls = 0;
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
|
|
|
}
|
2018-04-02 16:17:32 -07:00
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
private int getAvailableMessageBubbleWidth(@NonNull View forView) {
|
|
|
|
int availableWidth;
|
|
|
|
if (hasAudio(messageRecord)) {
|
|
|
|
availableWidth = audioViewStub.get().getMeasuredWidth() + ViewUtil.getLeftMargin(audioViewStub.get()) + ViewUtil.getRightMargin(audioViewStub.get());
|
2019-05-28 11:13:40 -04:00
|
|
|
} else if (hasThumbnail(messageRecord) || hasBigImageLinkPreview(messageRecord)) {
|
2018-06-26 10:27:44 -07:00
|
|
|
availableWidth = mediaThumbnailStub.get().getMeasuredWidth();
|
|
|
|
} else {
|
|
|
|
availableWidth = bodyBubble.getMeasuredWidth() - bodyBubble.getPaddingLeft() - bodyBubble.getPaddingRight();
|
2018-04-02 16:17:32 -07:00
|
|
|
}
|
2018-06-26 10:27:44 -07:00
|
|
|
|
|
|
|
availableWidth -= ViewUtil.getLeftMargin(forView) + ViewUtil.getRightMargin(forView);
|
|
|
|
|
|
|
|
return availableWidth;
|
2018-04-02 16:17:32 -07:00
|
|
|
}
|
|
|
|
|
2015-07-20 13:40:57 -07:00
|
|
|
private void initializeAttributes() {
|
2017-11-13 18:01:05 -08:00
|
|
|
final int[] attributes = new int[] {R.attr.conversation_item_bubble_background};
|
2015-07-20 13:40:57 -07:00
|
|
|
final TypedArray attrs = context.obtainStyledAttributes(attributes);
|
|
|
|
|
|
|
|
defaultBubbleColor = attrs.getColor(0, Color.WHITE);
|
|
|
|
attrs.recycle();
|
|
|
|
}
|
|
|
|
|
2015-09-16 17:31:24 -07:00
|
|
|
@Override
|
2013-04-26 11:23:43 -07:00
|
|
|
public void unbind() {
|
2015-07-22 17:47:38 -07:00
|
|
|
if (recipient != null) {
|
|
|
|
recipient.removeListener(this);
|
|
|
|
}
|
2013-04-26 11:23:43 -07:00
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public MessageRecord getMessageRecord() {
|
|
|
|
return messageRecord;
|
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2012-10-28 16:04:24 -07:00
|
|
|
/// MessageRecord Attribute Parsers
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setBubbleState(MessageRecord messageRecord) {
|
2015-06-29 15:33:36 -07:00
|
|
|
if (messageRecord.isOutgoing()) {
|
2020-01-13 15:29:06 +11:00
|
|
|
bodyBubble.getBackground().setColorFilter(getResources().getColor(R.color.sent_message_background), PorterDuff.Mode.MULTIPLY);
|
2016-08-14 07:55:43 +02:00
|
|
|
} else {
|
2020-01-13 15:29:06 +11:00
|
|
|
bodyBubble.getBackground().setColorFilter(getResources().getColor(R.color.received_message_background), PorterDuff.Mode.MULTIPLY);
|
2016-08-14 07:55:43 +02:00
|
|
|
}
|
2016-11-21 18:58:10 -08:00
|
|
|
|
2017-01-20 09:11:40 -08:00
|
|
|
if (audioViewStub.resolved()) {
|
2018-06-26 10:27:44 -07:00
|
|
|
setAudioViewTint(messageRecord, this.conversationRecipient);
|
2017-03-28 12:05:30 -07:00
|
|
|
}
|
2016-08-14 07:55:43 +02:00
|
|
|
}
|
2015-11-06 17:48:37 -08:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
private void setAudioViewTint(MessageRecord messageRecord, Recipient recipient) {
|
2020-01-14 16:36:03 +11:00
|
|
|
audioViewStub.get().setTint(Color.WHITE, getResources().getColor(R.color.action_bar_background));
|
2015-05-18 08:38:48 -07:00
|
|
|
}
|
2014-02-26 00:30:29 -08:00
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setInteractionState(MessageRecord messageRecord, boolean pulseHighlight) {
|
2018-04-02 16:17:32 -07:00
|
|
|
if (batchSelected.contains(messageRecord)) {
|
|
|
|
setBackgroundResource(R.drawable.conversation_item_background);
|
|
|
|
setSelected(true);
|
|
|
|
} else if (pulseHighlight) {
|
|
|
|
setBackgroundResource(R.drawable.conversation_item_background_animated);
|
|
|
|
setSelected(true);
|
|
|
|
postDelayed(() -> setSelected(false), 500);
|
|
|
|
} else {
|
|
|
|
setSelected(false);
|
|
|
|
}
|
2017-01-20 09:30:08 -08:00
|
|
|
|
|
|
|
if (mediaThumbnailStub.resolved()) {
|
|
|
|
mediaThumbnailStub.get().setFocusable(!shouldInterceptClicks(messageRecord) && batchSelected.isEmpty());
|
|
|
|
mediaThumbnailStub.get().setClickable(!shouldInterceptClicks(messageRecord) && batchSelected.isEmpty());
|
|
|
|
mediaThumbnailStub.get().setLongClickable(batchSelected.isEmpty());
|
|
|
|
}
|
2017-01-13 03:13:28 +01:00
|
|
|
|
|
|
|
if (audioViewStub.resolved()) {
|
|
|
|
audioViewStub.get().setFocusable(!shouldInterceptClicks(messageRecord) && batchSelected.isEmpty());
|
|
|
|
audioViewStub.get().setClickable(batchSelected.isEmpty());
|
|
|
|
audioViewStub.get().setEnabled(batchSelected.isEmpty());
|
|
|
|
}
|
2017-03-28 12:05:30 -07:00
|
|
|
|
|
|
|
if (documentViewStub.resolved()) {
|
|
|
|
documentViewStub.get().setFocusable(!shouldInterceptClicks(messageRecord) && batchSelected.isEmpty());
|
|
|
|
documentViewStub.get().setClickable(batchSelected.isEmpty());
|
|
|
|
}
|
2014-12-13 18:10:59 -08:00
|
|
|
}
|
|
|
|
|
2015-01-29 20:37:01 -10:00
|
|
|
private boolean isCaptionlessMms(MessageRecord messageRecord) {
|
2019-03-13 18:28:16 -03:00
|
|
|
return TextUtils.isEmpty(messageRecord.getDisplayBody(getContext())) && messageRecord.isMms() && ((MmsMessageRecord) messageRecord).getSlideDeck().getTextSlide() == null;
|
2015-01-29 20:37:01 -10:00
|
|
|
}
|
|
|
|
|
2015-10-21 15:32:29 -07:00
|
|
|
private boolean hasAudio(MessageRecord messageRecord) {
|
2017-01-20 15:26:17 -08:00
|
|
|
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getAudioSlide() != null;
|
2015-10-21 15:32:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean hasThumbnail(MessageRecord messageRecord) {
|
2017-01-20 15:26:17 -08:00
|
|
|
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getThumbnailSlide() != null;
|
2015-01-29 20:37:01 -10:00
|
|
|
}
|
|
|
|
|
2019-04-17 10:21:30 -04:00
|
|
|
private boolean hasSticker(MessageRecord messageRecord) {
|
|
|
|
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getStickerSlide() != null;
|
|
|
|
}
|
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
private boolean hasOnlyThumbnail(MessageRecord messageRecord) {
|
2019-04-17 10:21:30 -04:00
|
|
|
return hasThumbnail(messageRecord) &&
|
|
|
|
!hasAudio(messageRecord) &&
|
|
|
|
!hasDocument(messageRecord) &&
|
|
|
|
!hasSharedContact(messageRecord) &&
|
|
|
|
!hasSticker(messageRecord);
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
|
|
|
|
2020-01-15 16:13:28 +11:00
|
|
|
private boolean hasOnlyDocument(MessageRecord messageRecord) {
|
|
|
|
return messageRecord.getBody().length() == 0 &&
|
|
|
|
!hasThumbnail(messageRecord) &&
|
|
|
|
!hasAudio(messageRecord) &&
|
|
|
|
hasDocument(messageRecord) &&
|
|
|
|
!hasSharedContact(messageRecord) &&
|
|
|
|
!hasSticker(messageRecord) &&
|
|
|
|
!hasQuote(messageRecord);
|
|
|
|
}
|
|
|
|
|
2020-01-15 12:20:10 +11:00
|
|
|
private boolean hasOnlyText(MessageRecord messageRecord) {
|
|
|
|
return messageRecord.getBody().length() != 0 &&
|
|
|
|
!hasThumbnail(messageRecord) &&
|
|
|
|
!hasAudio(messageRecord) &&
|
|
|
|
!hasDocument(messageRecord) &&
|
|
|
|
!hasSharedContact(messageRecord) &&
|
|
|
|
!hasSticker(messageRecord) &&
|
|
|
|
!hasQuote(messageRecord);
|
|
|
|
}
|
|
|
|
|
2017-03-28 12:05:30 -07:00
|
|
|
private boolean hasDocument(MessageRecord messageRecord) {
|
|
|
|
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getDocumentSlide() != null;
|
|
|
|
}
|
|
|
|
|
2019-02-26 19:29:52 -08:00
|
|
|
private boolean hasExtraText(MessageRecord messageRecord) {
|
|
|
|
boolean hasTextSlide = messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getTextSlide() != null;
|
|
|
|
boolean hasOverflowText = messageRecord.getBody().length() > MAX_BODY_DISPLAY_LENGTH;
|
|
|
|
|
|
|
|
return hasTextSlide || hasOverflowText;
|
|
|
|
}
|
|
|
|
|
2018-04-02 16:17:32 -07:00
|
|
|
private boolean hasQuote(MessageRecord messageRecord) {
|
|
|
|
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getQuote() != null;
|
|
|
|
}
|
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
private boolean hasSharedContact(MessageRecord messageRecord) {
|
|
|
|
return messageRecord.isMms() && !((MmsMessageRecord)messageRecord).getSharedContacts().isEmpty();
|
|
|
|
}
|
|
|
|
|
2019-01-15 00:41:05 -08:00
|
|
|
private boolean hasLinkPreview(MessageRecord messageRecord) {
|
|
|
|
return messageRecord.isMms() && !((MmsMessageRecord)messageRecord).getLinkPreviews().isEmpty();
|
|
|
|
}
|
|
|
|
|
2019-05-28 11:13:40 -04:00
|
|
|
private boolean hasBigImageLinkPreview(MessageRecord messageRecord) {
|
|
|
|
if (!hasLinkPreview(messageRecord)) return false;
|
|
|
|
|
|
|
|
LinkPreview linkPreview = ((MmsMessageRecord) messageRecord).getLinkPreviews().get(0);
|
|
|
|
int minWidth = getResources().getDimensionPixelSize(R.dimen.media_bubble_min_width);
|
|
|
|
|
|
|
|
return linkPreview.getThumbnail().isPresent() &&
|
|
|
|
linkPreview.getThumbnail().get().getWidth() >= minWidth &&
|
|
|
|
!StickerUrl.isValidShareLink(linkPreview.getUrl());
|
|
|
|
}
|
|
|
|
|
2019-10-09 16:41:14 +11:00
|
|
|
private void setBodyText(MessageRecord messageRecord, @Nullable String searchQuery, boolean isGroupThread) {
|
2014-12-13 18:10:59 -08:00
|
|
|
bodyText.setClickable(false);
|
|
|
|
bodyText.setFocusable(false);
|
2017-04-14 22:59:30 -07:00
|
|
|
bodyText.setTextSize(TypedValue.COMPLEX_UNIT_SP, TextSecurePreferences.getMessageBodyTextSize(context));
|
2015-01-29 20:37:01 -10:00
|
|
|
if (isCaptionlessMms(messageRecord)) {
|
|
|
|
bodyText.setVisibility(View.GONE);
|
2019-10-18 12:40:41 +11:00
|
|
|
} else {
|
2019-10-15 13:51:18 +11:00
|
|
|
Spannable text = MentionUtilities.highlightMentions(linkifyMessageBody(messageRecord.getDisplayBody(context), batchSelected.isEmpty()), messageRecord.isOutgoing(), messageRecord.getThreadId(), context);
|
2020-01-15 17:13:46 +11:00
|
|
|
text = SearchUtil.getHighlightedSpan(locale, () -> new BackgroundColorSpan(Color.WHITE), text, searchQuery);
|
2019-10-09 16:41:14 +11:00
|
|
|
text = SearchUtil.getHighlightedSpan(locale, () -> new ForegroundColorSpan(Color.BLACK), text, searchQuery);
|
2019-02-01 09:06:59 -08:00
|
|
|
|
2019-02-26 19:29:52 -08:00
|
|
|
if (hasExtraText(messageRecord)) {
|
|
|
|
bodyText.setOverflowText(getLongMessageSpan(messageRecord));
|
|
|
|
} else {
|
|
|
|
bodyText.setOverflowText(null);
|
|
|
|
}
|
|
|
|
|
2019-10-09 16:41:14 +11:00
|
|
|
bodyText.setText(text);
|
2015-01-29 20:37:01 -10:00
|
|
|
bodyText.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2020-01-15 12:20:10 +11:00
|
|
|
private void adjustMarginsIfNeeded(MessageRecord messageRecord) {
|
|
|
|
LinearLayout.LayoutParams bodyTextLayoutParams = (LinearLayout.LayoutParams)bodyText.getLayoutParams();
|
|
|
|
bodyTextLayoutParams.topMargin = 0;
|
|
|
|
if (hasOnlyThumbnail(messageRecord)) {
|
|
|
|
int topPadding = 0;
|
|
|
|
if (groupSenderHolder.getVisibility() == VISIBLE) {
|
|
|
|
topPadding = (int)getResources().getDimension(R.dimen.medium_spacing);
|
|
|
|
}
|
|
|
|
int bottomPadding = 0;
|
|
|
|
if (messageRecord.getBody().length() > 0) {
|
|
|
|
bodyTextLayoutParams.topMargin = (int)getResources().getDimension(R.dimen.medium_spacing);
|
|
|
|
bottomPadding = (int)getResources().getDimension(R.dimen.medium_spacing);
|
|
|
|
}
|
|
|
|
bodyBubble.setPadding(0, topPadding, 0, bottomPadding);
|
|
|
|
} else {
|
|
|
|
bodyBubble.setPadding(0, (int)getResources().getDimension(R.dimen.medium_spacing), 0, (int)getResources().getDimension(R.dimen.medium_spacing));
|
|
|
|
}
|
|
|
|
bodyText.setLayoutParams(bodyTextLayoutParams);
|
|
|
|
LinearLayout.LayoutParams senderHolderLayoutParams = (LinearLayout.LayoutParams)groupSenderHolder.getLayoutParams();
|
|
|
|
if (groupSenderHolder.getVisibility() == VISIBLE && hasOnlyText(messageRecord)) {
|
|
|
|
senderHolderLayoutParams.bottomMargin = (int)(getResources().getDisplayMetrics().density * 4);
|
|
|
|
} else {
|
|
|
|
senderHolderLayoutParams.bottomMargin = (int)getResources().getDimension(R.dimen.medium_spacing);
|
|
|
|
}
|
|
|
|
groupSenderHolder.setLayoutParams(senderHolderLayoutParams);
|
2020-01-15 16:13:28 +11:00
|
|
|
if (documentViewStub.resolved()) {
|
|
|
|
LinearLayout.LayoutParams documentViewLayoutParams = (LinearLayout.LayoutParams)documentViewStub.get().getLayoutParams();
|
|
|
|
int bottomMargin = 0;
|
|
|
|
if (hasOnlyDocument(messageRecord)) {
|
|
|
|
if (footer.getVisibility() == VISIBLE) {
|
|
|
|
bottomMargin = (int)(4 * getResources().getDisplayMetrics().density);
|
|
|
|
} else {
|
|
|
|
bottomMargin = (int)(-4 * getResources().getDisplayMetrics().density);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bottomMargin = (int)(4 * getResources().getDisplayMetrics().density);
|
|
|
|
}
|
|
|
|
documentViewLayoutParams.bottomMargin = bottomMargin;
|
|
|
|
documentViewStub.get().setLayoutParams(documentViewLayoutParams);
|
|
|
|
}
|
2020-01-15 12:20:10 +11:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setMediaAttributes(@NonNull MessageRecord messageRecord,
|
|
|
|
@NonNull Optional<MessageRecord> previousRecord,
|
|
|
|
@NonNull Optional<MessageRecord> nextRecord,
|
|
|
|
@NonNull Recipient conversationRecipient,
|
|
|
|
boolean isGroupThread)
|
2018-06-26 10:27:44 -07:00
|
|
|
{
|
2019-01-13 23:30:54 -08:00
|
|
|
boolean showControls = !messageRecord.isFailed();
|
2018-06-26 10:27:44 -07:00
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
if (hasSharedContact(messageRecord)) {
|
2018-04-26 17:03:54 -07:00
|
|
|
sharedContactStub.get().setVisibility(VISIBLE);
|
|
|
|
if (audioViewStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
|
|
|
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
|
|
|
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
2019-01-15 00:41:05 -08:00
|
|
|
if (linkPreviewStub.resolved()) linkPreviewStub.get().setVisibility(GONE);
|
2019-04-17 10:21:30 -04:00
|
|
|
if (stickerStub.resolved()) stickerStub.get().setVisibility(View.GONE);
|
2018-04-26 17:03:54 -07:00
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
sharedContactStub.get().setContact(((MediaMmsMessageRecord) messageRecord).getSharedContacts().get(0), glideRequests, locale);
|
2018-04-26 17:03:54 -07:00
|
|
|
sharedContactStub.get().setEventListener(sharedContactEventListener);
|
|
|
|
sharedContactStub.get().setOnClickListener(sharedContactClickListener);
|
|
|
|
sharedContactStub.get().setOnLongClickListener(passthroughClickListener);
|
|
|
|
|
2018-07-18 13:53:50 -07:00
|
|
|
setSharedContactCorners(messageRecord, previousRecord, nextRecord, isGroupThread);
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2019-01-15 00:41:05 -08:00
|
|
|
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2018-06-26 10:27:44 -07:00
|
|
|
footer.setVisibility(GONE);
|
2019-01-15 00:41:05 -08:00
|
|
|
} else if (hasLinkPreview(messageRecord)) {
|
|
|
|
linkPreviewStub.get().setVisibility(View.VISIBLE);
|
|
|
|
if (audioViewStub.resolved()) audioViewStub.get().setVisibility(View.GONE);
|
|
|
|
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
|
|
|
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
|
|
|
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
2019-04-17 10:21:30 -04:00
|
|
|
if (stickerStub.resolved()) stickerStub.get().setVisibility(View.GONE);
|
2019-01-15 00:41:05 -08:00
|
|
|
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
LinkPreview linkPreview = ((MmsMessageRecord) messageRecord).getLinkPreviews().get(0);
|
|
|
|
|
2019-05-28 11:13:40 -04:00
|
|
|
if (hasBigImageLinkPreview(messageRecord)) {
|
2019-01-15 00:41:05 -08:00
|
|
|
mediaThumbnailStub.get().setVisibility(VISIBLE);
|
|
|
|
mediaThumbnailStub.get().setImageResource(glideRequests, Collections.singletonList(new ImageSlide(context, linkPreview.getThumbnail().get())), showControls, false);
|
|
|
|
mediaThumbnailStub.get().setThumbnailClickListener(new LinkPreviewThumbnailClickListener());
|
|
|
|
mediaThumbnailStub.get().setDownloadClickListener(downloadClickListener);
|
|
|
|
mediaThumbnailStub.get().setOnLongClickListener(passthroughClickListener);
|
|
|
|
|
|
|
|
linkPreviewStub.get().setLinkPreview(glideRequests, linkPreview, false);
|
|
|
|
|
|
|
|
setThumbnailCorners(messageRecord, previousRecord, nextRecord, isGroupThread);
|
|
|
|
setLinkPreviewCorners(messageRecord, previousRecord, nextRecord, isGroupThread, true);
|
|
|
|
|
|
|
|
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
} else {
|
|
|
|
linkPreviewStub.get().setLinkPreview(glideRequests, linkPreview, true);
|
|
|
|
linkPreviewStub.get().setDownloadClickedListener(downloadClickListener);
|
|
|
|
setLinkPreviewCorners(messageRecord, previousRecord, nextRecord, isGroupThread, false);
|
|
|
|
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
linkPreviewStub.get().setOnClickListener(linkPreviewClickListener);
|
|
|
|
linkPreviewStub.get().setOnLongClickListener(passthroughClickListener);
|
|
|
|
|
|
|
|
|
|
|
|
footer.setVisibility(VISIBLE);
|
2018-07-12 16:03:32 -07:00
|
|
|
} else if (hasAudio(messageRecord)) {
|
2017-01-20 09:11:40 -08:00
|
|
|
audioViewStub.get().setVisibility(View.VISIBLE);
|
2017-01-20 09:30:08 -08:00
|
|
|
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
2017-03-28 12:05:30 -07:00
|
|
|
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
2018-04-26 17:03:54 -07:00
|
|
|
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
2019-01-15 00:41:05 -08:00
|
|
|
if (linkPreviewStub.resolved()) linkPreviewStub.get().setVisibility(GONE);
|
2019-04-17 10:21:30 -04:00
|
|
|
if (stickerStub.resolved()) stickerStub.get().setVisibility(View.GONE);
|
2015-10-21 15:32:29 -07:00
|
|
|
|
|
|
|
//noinspection ConstantConditions
|
2018-07-12 16:03:32 -07:00
|
|
|
audioViewStub.get().setAudio(((MediaMmsMessageRecord) messageRecord).getSlideDeck().getAudioSlide(), showControls);
|
2018-11-08 23:33:37 -08:00
|
|
|
audioViewStub.get().setDownloadClickListener(singleDownloadClickListener);
|
2017-01-20 09:11:40 -08:00
|
|
|
audioViewStub.get().setOnLongClickListener(passthroughClickListener);
|
2018-07-12 16:03:32 -07:00
|
|
|
|
|
|
|
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2018-07-20 18:24:52 -07:00
|
|
|
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2019-04-17 10:21:30 -04:00
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
footer.setVisibility(VISIBLE);
|
|
|
|
} else if (hasDocument(messageRecord)) {
|
2017-03-28 12:05:30 -07:00
|
|
|
documentViewStub.get().setVisibility(View.VISIBLE);
|
|
|
|
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
|
|
|
if (audioViewStub.resolved()) audioViewStub.get().setVisibility(View.GONE);
|
2018-04-26 17:03:54 -07:00
|
|
|
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
2019-01-15 00:41:05 -08:00
|
|
|
if (linkPreviewStub.resolved()) linkPreviewStub.get().setVisibility(GONE);
|
2019-04-17 10:21:30 -04:00
|
|
|
if (stickerStub.resolved()) stickerStub.get().setVisibility(View.GONE);
|
2017-03-28 12:05:30 -07:00
|
|
|
|
|
|
|
//noinspection ConstantConditions
|
2019-04-17 10:21:30 -04:00
|
|
|
documentViewStub.get().setDocument(((MediaMmsMessageRecord) messageRecord).getSlideDeck().getDocumentSlide(), showControls);
|
2017-03-28 12:05:30 -07:00
|
|
|
documentViewStub.get().setDocumentClickListener(new ThumbnailClickListener());
|
2018-11-08 23:33:37 -08:00
|
|
|
documentViewStub.get().setDownloadClickListener(singleDownloadClickListener);
|
2017-03-28 12:05:30 -07:00
|
|
|
documentViewStub.get().setOnLongClickListener(passthroughClickListener);
|
2018-07-12 16:03:32 -07:00
|
|
|
|
|
|
|
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2018-07-20 18:24:52 -07:00
|
|
|
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2019-04-17 10:21:30 -04:00
|
|
|
|
|
|
|
footer.setVisibility(VISIBLE);
|
|
|
|
} else if (hasSticker(messageRecord) && isCaptionlessMms(messageRecord)) {
|
|
|
|
bodyBubble.setBackgroundColor(Color.TRANSPARENT);
|
|
|
|
|
|
|
|
stickerStub.get().setVisibility(View.VISIBLE);
|
|
|
|
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
|
|
|
if (audioViewStub.resolved()) audioViewStub.get().setVisibility(View.GONE);
|
|
|
|
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
|
|
|
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
|
|
|
if (linkPreviewStub.resolved()) linkPreviewStub.get().setVisibility(GONE);
|
|
|
|
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
stickerStub.get().setSticker(glideRequests, ((MmsMessageRecord) messageRecord).getSlideDeck().getStickerSlide());
|
|
|
|
stickerStub.get().setThumbnailClickListener(new StickerClickListener());
|
|
|
|
stickerStub.get().setDownloadClickListener(downloadClickListener);
|
|
|
|
stickerStub.get().setOnLongClickListener(passthroughClickListener);
|
|
|
|
stickerStub.get().setOnClickListener(passthroughClickListener);
|
|
|
|
|
|
|
|
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
footer.setVisibility(VISIBLE);
|
|
|
|
} else if (hasThumbnail(messageRecord)) {
|
2017-01-20 09:30:08 -08:00
|
|
|
mediaThumbnailStub.get().setVisibility(View.VISIBLE);
|
2019-01-15 00:41:05 -08:00
|
|
|
if (audioViewStub.resolved()) audioViewStub.get().setVisibility(View.GONE);
|
|
|
|
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
|
|
|
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
|
|
|
if (linkPreviewStub.resolved()) linkPreviewStub.get().setVisibility(GONE);
|
2019-04-17 10:21:30 -04:00
|
|
|
if (stickerStub.resolved()) stickerStub.get().setVisibility(View.GONE);
|
2015-10-21 15:32:29 -07:00
|
|
|
|
2015-10-21 15:32:19 -07:00
|
|
|
//noinspection ConstantConditions
|
2018-11-08 23:33:37 -08:00
|
|
|
List<Slide> thumbnailSlides = ((MmsMessageRecord) messageRecord).getSlideDeck().getThumbnailSlides();
|
2018-01-24 19:17:44 -08:00
|
|
|
mediaThumbnailStub.get().setImageResource(glideRequests,
|
2018-11-08 23:33:37 -08:00
|
|
|
thumbnailSlides,
|
2018-03-20 11:27:11 -07:00
|
|
|
showControls,
|
2018-11-08 23:33:37 -08:00
|
|
|
false);
|
2017-01-20 09:30:08 -08:00
|
|
|
mediaThumbnailStub.get().setThumbnailClickListener(new ThumbnailClickListener());
|
|
|
|
mediaThumbnailStub.get().setDownloadClickListener(downloadClickListener);
|
|
|
|
mediaThumbnailStub.get().setOnLongClickListener(passthroughClickListener);
|
|
|
|
mediaThumbnailStub.get().setOnClickListener(passthroughClickListener);
|
2019-03-13 18:28:16 -03:00
|
|
|
mediaThumbnailStub.get().showShade(TextUtils.isEmpty(messageRecord.getDisplayBody(getContext())) && !hasExtraText(messageRecord));
|
2018-11-08 23:33:37 -08:00
|
|
|
mediaThumbnailStub.get().setConversationColor(messageRecord.isOutgoing() ? defaultBubbleColor
|
|
|
|
: messageRecord.getRecipient().getColor().toConversationColor(context));
|
2019-04-17 10:21:30 -04:00
|
|
|
mediaThumbnailStub.get().setBorderless(false);
|
2017-01-20 09:30:08 -08:00
|
|
|
|
2019-01-15 00:41:05 -08:00
|
|
|
setThumbnailCorners(messageRecord, previousRecord, nextRecord, isGroupThread);
|
2018-06-26 10:27:44 -07:00
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2018-07-20 18:24:52 -07:00
|
|
|
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2019-04-17 10:21:30 -04:00
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
footer.setVisibility(VISIBLE);
|
2015-06-29 08:49:32 -07:00
|
|
|
} else {
|
2017-01-20 09:30:08 -08:00
|
|
|
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
|
|
|
if (audioViewStub.resolved()) audioViewStub.get().setVisibility(View.GONE);
|
2017-03-28 12:05:30 -07:00
|
|
|
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
2018-04-26 17:03:54 -07:00
|
|
|
if (sharedContactStub.resolved()) sharedContactStub.get().setVisibility(GONE);
|
2019-01-15 00:41:05 -08:00
|
|
|
if (linkPreviewStub.resolved()) linkPreviewStub.get().setVisibility(GONE);
|
2019-04-17 10:21:30 -04:00
|
|
|
if (stickerStub.resolved()) stickerStub.get().setVisibility(View.GONE);
|
2018-07-12 16:03:32 -07:00
|
|
|
|
|
|
|
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2018-07-20 18:24:52 -07:00
|
|
|
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2019-04-17 10:21:30 -04:00
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
footer.setVisibility(VISIBLE);
|
2015-01-29 20:37:01 -10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 00:41:05 -08:00
|
|
|
private void setThumbnailCorners(@NonNull MessageRecord current,
|
|
|
|
@NonNull Optional<MessageRecord> previous,
|
|
|
|
@NonNull Optional<MessageRecord> next,
|
|
|
|
boolean isGroupThread)
|
2018-06-26 10:27:44 -07:00
|
|
|
{
|
|
|
|
int defaultRadius = readDimen(R.dimen.message_corner_radius);
|
|
|
|
int collapseRadius = readDimen(R.dimen.message_corner_collapse_radius);
|
|
|
|
|
|
|
|
int topLeft = defaultRadius;
|
|
|
|
int topRight = defaultRadius;
|
|
|
|
int bottomLeft = defaultRadius;
|
|
|
|
int bottomRight = defaultRadius;
|
|
|
|
|
|
|
|
if (isSingularMessage(current, previous, next, isGroupThread)) {
|
|
|
|
topLeft = defaultRadius;
|
|
|
|
topRight = defaultRadius;
|
|
|
|
bottomLeft = defaultRadius;
|
|
|
|
bottomRight = defaultRadius;
|
|
|
|
} else if (isStartOfMessageCluster(current, previous, isGroupThread)) {
|
|
|
|
if (current.isOutgoing()) {
|
|
|
|
bottomRight = collapseRadius;
|
|
|
|
} else {
|
|
|
|
bottomLeft = collapseRadius;
|
|
|
|
}
|
|
|
|
} else if (isEndOfMessageCluster(current, next, isGroupThread)) {
|
|
|
|
if (current.isOutgoing()) {
|
|
|
|
topRight = collapseRadius;
|
|
|
|
} else {
|
|
|
|
topLeft = collapseRadius;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (current.isOutgoing()) {
|
|
|
|
topRight = collapseRadius;
|
|
|
|
bottomRight = collapseRadius;
|
|
|
|
} else {
|
|
|
|
topLeft = collapseRadius;
|
|
|
|
bottomLeft = collapseRadius;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 18:28:16 -03:00
|
|
|
if (!TextUtils.isEmpty(current.getDisplayBody(getContext()))) {
|
2018-06-26 10:27:44 -07:00
|
|
|
bottomLeft = 0;
|
|
|
|
bottomRight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isStartOfMessageCluster(current, previous, isGroupThread) && !current.isOutgoing() && isGroupThread) {
|
|
|
|
topLeft = 0;
|
|
|
|
topRight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasQuote(messageRecord)) {
|
|
|
|
topLeft = 0;
|
|
|
|
topRight = 0;
|
|
|
|
}
|
|
|
|
|
2019-02-26 19:29:52 -08:00
|
|
|
if (hasLinkPreview(messageRecord) || hasExtraText(messageRecord)) {
|
2019-01-15 00:41:05 -08:00
|
|
|
bottomLeft = 0;
|
|
|
|
bottomRight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mediaThumbnailStub.get().setCorners(topLeft, topRight, bottomRight, bottomLeft);
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:53:50 -07:00
|
|
|
private void setSharedContactCorners(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
|
|
|
|
if (isSingularMessage(current, previous, next, isGroupThread) || isEndOfMessageCluster(current, next, isGroupThread)) {
|
|
|
|
sharedContactStub.get().setSingularStyle();
|
2019-01-15 00:41:05 -08:00
|
|
|
} else if (current.isOutgoing()) {
|
|
|
|
sharedContactStub.get().setClusteredOutgoingStyle();
|
2018-07-18 13:53:50 -07:00
|
|
|
} else {
|
2019-01-15 00:41:05 -08:00
|
|
|
sharedContactStub.get().setClusteredIncomingStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setLinkPreviewCorners(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread, boolean bigImage) {
|
|
|
|
int defaultRadius = readDimen(R.dimen.message_corner_radius);
|
|
|
|
int collapseRadius = readDimen(R.dimen.message_corner_collapse_radius);
|
|
|
|
|
|
|
|
if (bigImage) {
|
|
|
|
linkPreviewStub.get().setCorners(0, 0);
|
|
|
|
} else if (isStartOfMessageCluster(current, previous, isGroupThread) && !current.isOutgoing() && isGroupThread) {
|
|
|
|
linkPreviewStub.get().setCorners(0, 0);
|
|
|
|
} else if (isSingularMessage(current, previous, next, isGroupThread) || isStartOfMessageCluster(current, previous, isGroupThread)) {
|
|
|
|
linkPreviewStub.get().setCorners(defaultRadius, defaultRadius);
|
|
|
|
} else if (current.isOutgoing()) {
|
|
|
|
linkPreviewStub.get().setCorners(defaultRadius, collapseRadius);
|
|
|
|
} else {
|
|
|
|
linkPreviewStub.get().setCorners(collapseRadius, defaultRadius);
|
2018-07-18 13:53:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setContactPhoto(@NonNull Recipient recipient) {
|
2020-03-13 14:26:54 +11:00
|
|
|
if (messageRecord == null) return; // TODO: Figure out how this happens
|
2019-08-06 10:22:05 +10:00
|
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)bodyBubble.getLayoutParams();
|
2020-03-12 10:49:17 +11:00
|
|
|
int groupThreadMargin = (int)((12 * getResources().getDisplayMetrics().density) + getResources().getDimension(R.dimen.small_profile_picture_size));
|
2020-01-13 15:29:06 +11:00
|
|
|
int defaultMargin = 0;
|
2020-07-13 14:40:42 +10:00
|
|
|
Recipient r = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(messageRecord.getThreadId());
|
|
|
|
String threadName = r != null ? r.getName() : "";
|
2020-02-04 13:07:54 +11:00
|
|
|
boolean isRSSFeed = threadName != null && (threadName.equals("Loki News") || threadName.equals("Session Updates"));
|
2020-01-15 12:20:10 +11:00
|
|
|
layoutParams.setMarginStart((groupThread && !isRSSFeed) ? groupThreadMargin : defaultMargin);
|
2019-08-06 10:22:05 +10:00
|
|
|
bodyBubble.setLayoutParams(layoutParams);
|
2020-01-13 15:29:06 +11:00
|
|
|
if (profilePictureView == null) return;
|
2020-07-15 14:26:20 +10:00
|
|
|
profilePictureView.setPublicKey(recipient.getAddress().toString());
|
|
|
|
profilePictureView.setAdditionalPublicKey(null);
|
2020-01-13 15:29:06 +11:00
|
|
|
profilePictureView.setRSSFeed(false);
|
|
|
|
profilePictureView.setGlide(glideRequests);
|
|
|
|
profilePictureView.update();
|
2012-10-28 16:04:24 -07:00
|
|
|
}
|
|
|
|
|
2017-03-28 14:34:36 +02:00
|
|
|
private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) {
|
2018-08-13 15:23:28 -04:00
|
|
|
int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
|
|
|
|
boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? linkPattern : 0);
|
2017-03-28 14:34:36 +02:00
|
|
|
|
|
|
|
if (hasLinks) {
|
2019-02-20 17:00:23 -08:00
|
|
|
Stream.of(messageBody.getSpans(0, messageBody.length(), URLSpan.class))
|
|
|
|
.filterNot(url -> LinkPreviewUtil.isLegalUrl(url.getURL()))
|
|
|
|
.forEach(messageBody::removeSpan);
|
|
|
|
|
2017-03-28 14:34:36 +02:00
|
|
|
URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
|
2019-02-20 17:00:23 -08:00
|
|
|
|
2017-03-28 14:34:36 +02:00
|
|
|
for (URLSpan urlSpan : urlSpans) {
|
|
|
|
int start = messageBody.getSpanStart(urlSpan);
|
|
|
|
int end = messageBody.getSpanEnd(urlSpan);
|
|
|
|
messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return messageBody;
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setStatusIcons(MessageRecord messageRecord) {
|
2015-06-29 08:49:32 -07:00
|
|
|
bodyText.setCompoundDrawablesWithIntrinsicBounds(0, 0, messageRecord.isKeyExchange() ? R.drawable.ic_menu_login : 0, 0);
|
|
|
|
|
2015-11-24 16:06:41 +01:00
|
|
|
if (messageRecord.isFailed()) {
|
2018-07-12 16:03:32 -07:00
|
|
|
alertView.setFailed();
|
2015-11-24 16:06:41 +01:00
|
|
|
} else if (messageRecord.isPendingInsecureSmsFallback()) {
|
2018-07-12 16:03:32 -07:00
|
|
|
alertView.setPendingApproval();
|
2015-11-24 16:06:41 +01:00
|
|
|
} else {
|
|
|
|
alertView.setNone();
|
2016-08-15 20:23:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setQuote(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
|
2018-06-26 10:27:44 -07:00
|
|
|
if (current.isMms() && !current.isMmsNotification() && ((MediaMmsMessageRecord)current).getQuote() != null) {
|
|
|
|
Quote quote = ((MediaMmsMessageRecord)current).getQuote();
|
2019-04-17 10:21:30 -04:00
|
|
|
//noinspection ConstantConditions
|
2019-10-15 13:51:18 +11:00
|
|
|
String quoteBody = MentionUtilities.highlightMentions(quote.getText(), current.getThreadId(), context);
|
2019-10-11 13:24:20 +11:00
|
|
|
quoteView.setQuote(glideRequests, quote.getId(), Recipient.from(context, quote.getAuthor(), true), quoteBody, quote.isOriginalMissing(), quote.getAttachment(), conversationRecipient);
|
2018-02-07 14:01:37 -08:00
|
|
|
quoteView.setVisibility(View.VISIBLE);
|
2018-04-02 16:17:32 -07:00
|
|
|
quoteView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
|
|
|
|
|
|
quoteView.setOnClickListener(view -> {
|
|
|
|
if (eventListener != null && batchSelected.isEmpty()) {
|
2018-06-26 10:27:44 -07:00
|
|
|
eventListener.onQuoteClicked((MmsMessageRecord) current);
|
2018-04-02 16:17:32 -07:00
|
|
|
} else {
|
|
|
|
passthroughClickListener.onClick(view);
|
|
|
|
}
|
|
|
|
});
|
2018-07-12 16:03:32 -07:00
|
|
|
|
2018-04-02 16:17:32 -07:00
|
|
|
quoteView.setOnLongClickListener(passthroughClickListener);
|
2018-06-26 10:27:44 -07:00
|
|
|
|
|
|
|
if (isStartOfMessageCluster(current, previous, isGroupThread)) {
|
|
|
|
if (current.isOutgoing()) {
|
|
|
|
quoteView.setTopCornerSizes(true, true);
|
|
|
|
} else if (isGroupThread) {
|
|
|
|
quoteView.setTopCornerSizes(false, false);
|
|
|
|
} else {
|
|
|
|
quoteView.setTopCornerSizes(true, true);
|
|
|
|
}
|
|
|
|
} else if (!isSingularMessage(current, previous, next, isGroupThread)) {
|
|
|
|
if (current.isOutgoing()) {
|
|
|
|
quoteView.setTopCornerSizes(true, false);
|
|
|
|
} else {
|
|
|
|
quoteView.setTopCornerSizes(false, true);
|
|
|
|
}
|
|
|
|
}
|
2018-07-12 16:03:32 -07:00
|
|
|
|
|
|
|
if (mediaThumbnailStub.resolved()) {
|
|
|
|
ViewUtil.setTopMargin(mediaThumbnailStub.get(), readDimen(R.dimen.message_bubble_top_padding));
|
|
|
|
}
|
2018-02-07 14:01:37 -08:00
|
|
|
} else {
|
|
|
|
quoteView.dismiss();
|
2018-07-12 16:03:32 -07:00
|
|
|
|
|
|
|
if (mediaThumbnailStub.resolved()) {
|
|
|
|
ViewUtil.setTopMargin(mediaThumbnailStub.get(), 0);
|
|
|
|
}
|
2018-02-07 14:01:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setGutterSizes(@NonNull MessageRecord current, boolean isGroupThread) {
|
2018-07-18 13:53:50 -07:00
|
|
|
if (isGroupThread && current.isOutgoing()) {
|
|
|
|
ViewUtil.setLeftMargin(container, readDimen(R.dimen.conversation_group_left_gutter));
|
|
|
|
} else if (current.isOutgoing()) {
|
|
|
|
ViewUtil.setLeftMargin(container, readDimen(R.dimen.conversation_individual_left_gutter));
|
2015-03-27 10:37:59 -07:00
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setFooter(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> next, @NonNull Locale locale, boolean isGroupThread) {
|
2018-06-26 10:27:44 -07:00
|
|
|
ViewUtil.updateLayoutParams(footer, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
|
|
|
|
|
|
|
footer.setVisibility(GONE);
|
2019-04-17 10:21:30 -04:00
|
|
|
stickerFooter.setVisibility(GONE);
|
2019-02-26 19:29:52 -08:00
|
|
|
if (sharedContactStub.resolved()) sharedContactStub.get().getFooter().setVisibility(GONE);
|
2018-06-26 10:27:44 -07:00
|
|
|
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().getFooter().setVisibility(GONE);
|
|
|
|
|
2018-08-06 10:34:02 -04:00
|
|
|
boolean differentTimestamps = next.isPresent() && !DateUtils.isSameExtendedRelativeTimestamp(context, locale, next.get().getTimestamp(), current.getTimestamp());
|
2018-07-20 18:35:04 -07:00
|
|
|
|
2018-07-20 18:45:18 -07:00
|
|
|
if (current.getExpiresIn() > 0 || !current.isSecure() || current.isPending() || current.isPendingInsecureSmsFallback() ||
|
2018-08-06 10:34:02 -04:00
|
|
|
current.isFailed() || differentTimestamps || isEndOfMessageCluster(current, next, isGroupThread))
|
2018-07-20 18:45:18 -07:00
|
|
|
{
|
2018-06-26 10:27:44 -07:00
|
|
|
ConversationItemFooter activeFooter = getActiveFooter(current);
|
|
|
|
activeFooter.setVisibility(VISIBLE);
|
|
|
|
activeFooter.setMessageRecord(current, locale);
|
|
|
|
}
|
2012-10-28 16:04:24 -07:00
|
|
|
}
|
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
private ConversationItemFooter getActiveFooter(@NonNull MessageRecord messageRecord) {
|
2019-04-17 10:21:30 -04:00
|
|
|
if (hasSticker(messageRecord)) {
|
|
|
|
return stickerFooter;
|
|
|
|
} else if (hasSharedContact(messageRecord)) {
|
2018-06-26 10:27:44 -07:00
|
|
|
return sharedContactStub.get().getFooter();
|
2019-03-13 18:28:16 -03:00
|
|
|
} else if (hasOnlyThumbnail(messageRecord) && TextUtils.isEmpty(messageRecord.getDisplayBody(getContext()))) {
|
2018-06-26 10:27:44 -07:00
|
|
|
return mediaThumbnailStub.get().getFooter();
|
2014-03-01 14:17:55 -08:00
|
|
|
} else {
|
2018-06-26 10:27:44 -07:00
|
|
|
return footer;
|
2014-03-01 14:17:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
private int readDimen(@DimenRes int dimenId) {
|
|
|
|
return context.getResources().getDimensionPixelOffset(dimenId);
|
|
|
|
}
|
|
|
|
|
2015-09-23 17:19:24 -07:00
|
|
|
private boolean shouldInterceptClicks(MessageRecord messageRecord) {
|
|
|
|
return batchSelected.isEmpty() &&
|
2015-10-01 15:02:50 +09:00
|
|
|
((messageRecord.isFailed() && !messageRecord.isMmsNotification()) ||
|
2015-09-23 17:19:24 -07:00
|
|
|
messageRecord.isPendingInsecureSmsFallback() ||
|
|
|
|
messageRecord.isBundleKeyExchange());
|
2012-10-28 16:04:24 -07:00
|
|
|
}
|
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
@SuppressLint("SetTextI18n")
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setGroupMessageStatus(MessageRecord messageRecord, Recipient recipient) {
|
|
|
|
if (groupThread && !messageRecord.isOutgoing()) {
|
2019-09-09 12:53:31 +10:00
|
|
|
// Show custom display names for group chats
|
|
|
|
String displayName = recipient.toShortString();
|
|
|
|
try {
|
|
|
|
String serverId = GroupUtil.getDecodedStringId(conversationRecipient.getAddress().serialize());
|
|
|
|
String senderDisplayName = DatabaseFactory.getLokiUserDatabase(context).getServerDisplayName(serverId, recipient.getAddress().serialize());
|
|
|
|
if (senderDisplayName != null) { displayName = senderDisplayName; }
|
2019-09-10 13:50:59 +10:00
|
|
|
} catch (Exception e) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2019-09-09 12:53:31 +10:00
|
|
|
|
|
|
|
this.groupSender.setText(displayName);
|
2017-08-15 19:23:42 -07:00
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
if (recipient.getName() == null && !TextUtils.isEmpty(recipient.getProfileName())) {
|
|
|
|
this.groupSenderProfileName.setText("~" + recipient.getProfileName());
|
|
|
|
this.groupSenderProfileName.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
this.groupSenderProfileName.setText(null);
|
|
|
|
this.groupSenderProfileName.setVisibility(View.GONE);
|
|
|
|
}
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 10:21:30 -04:00
|
|
|
private void setGroupAuthorColor(@NonNull MessageRecord messageRecord) {
|
|
|
|
if (hasSticker(messageRecord)) {
|
|
|
|
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
|
|
|
|
groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
|
|
|
|
} else {
|
|
|
|
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color));
|
|
|
|
groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setAuthor(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
|
2020-08-19 11:40:34 +10:00
|
|
|
Recipient recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(current.getThreadId());
|
|
|
|
String threadName = null;
|
|
|
|
if (recipient != null) {
|
|
|
|
threadName = recipient.getName();
|
|
|
|
}
|
2020-02-04 13:07:54 +11:00
|
|
|
boolean isRSSFeed = threadName != null && (threadName.equals("Loki News") || threadName.equals("Session Updates"));
|
2020-01-15 12:20:10 +11:00
|
|
|
if (isGroupThread && !isRSSFeed && !current.isOutgoing()) {
|
2018-07-25 01:16:48 -04:00
|
|
|
contactPhotoHolder.setVisibility(VISIBLE);
|
|
|
|
|
2018-07-24 16:33:45 -04:00
|
|
|
if (!previous.isPresent() || previous.get().isUpdate() || !current.getRecipient().getAddress().equals(previous.get().getRecipient().getAddress()) ||
|
|
|
|
!DateUtils.isSameDay(previous.get().getTimestamp(), current.getTimestamp()))
|
|
|
|
{
|
2018-06-26 10:27:44 -07:00
|
|
|
groupSenderHolder.setVisibility(VISIBLE);
|
2017-08-15 19:23:42 -07:00
|
|
|
} else {
|
2018-06-26 10:27:44 -07:00
|
|
|
groupSenderHolder.setVisibility(GONE);
|
2017-08-15 19:23:42 -07:00
|
|
|
}
|
|
|
|
|
2020-01-15 12:20:10 +11:00
|
|
|
if (!previous.isPresent() || previous.get().isUpdate() || !current.getRecipient().getAddress().equals(previous.get().getRecipient().getAddress())) {
|
2020-01-13 15:29:06 +11:00
|
|
|
profilePictureView.setVisibility(VISIBLE);
|
2019-10-10 11:38:43 +11:00
|
|
|
int visibility = View.GONE;
|
|
|
|
|
2020-07-15 12:24:43 +10:00
|
|
|
PublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(messageRecord.getThreadId());
|
2019-10-15 14:32:23 +11:00
|
|
|
if (publicChat != null) {
|
2020-07-15 12:24:43 +10:00
|
|
|
boolean isModerator = PublicChatAPI.Companion.isUserModerator(current.getRecipient().getAddress().toString(), publicChat.getChannel(), publicChat.getServer());
|
2019-09-12 16:42:52 +10:00
|
|
|
visibility = isModerator ? View.VISIBLE : View.GONE;
|
|
|
|
}
|
2019-10-10 11:38:43 +11:00
|
|
|
|
2019-09-12 16:42:52 +10:00
|
|
|
moderatorIconImageView.setVisibility(visibility);
|
2018-06-26 10:27:44 -07:00
|
|
|
} else {
|
2020-01-13 15:29:06 +11:00
|
|
|
profilePictureView.setVisibility(GONE);
|
2019-09-12 16:42:52 +10:00
|
|
|
moderatorIconImageView.setVisibility(GONE);
|
|
|
|
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
2013-05-05 12:51:36 -07:00
|
|
|
} else {
|
2018-06-26 10:27:44 -07:00
|
|
|
groupSenderHolder.setVisibility(GONE);
|
|
|
|
|
2018-07-25 01:16:48 -04:00
|
|
|
if (contactPhotoHolder != null) {
|
|
|
|
contactPhotoHolder.setVisibility(GONE);
|
2019-09-12 16:42:52 +10:00
|
|
|
moderatorIconImageView.setVisibility(GONE);
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
2013-05-05 12:51:36 -07:00
|
|
|
}
|
2012-10-29 16:51:42 -07:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:03:32 -07:00
|
|
|
private void setMessageShape(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
|
2018-07-18 13:53:50 -07:00
|
|
|
int background;
|
2018-06-26 10:27:44 -07:00
|
|
|
if (isSingularMessage(current, previous, next, isGroupThread)) {
|
2020-01-13 15:29:06 +11:00
|
|
|
background = current.isOutgoing() ? R.drawable.message_bubble_background_sent_alone : R.drawable.message_bubble_background_received_alone;
|
2018-06-26 10:27:44 -07:00
|
|
|
} else if (isStartOfMessageCluster(current, previous, isGroupThread)) {
|
2020-01-13 15:29:06 +11:00
|
|
|
background = current.isOutgoing() ? R.drawable.message_bubble_background_sent_start : R.drawable.message_bubble_background_received_start;
|
2018-06-26 10:27:44 -07:00
|
|
|
} else if (isEndOfMessageCluster(current, next, isGroupThread)) {
|
2020-01-13 15:29:06 +11:00
|
|
|
background = current.isOutgoing() ? R.drawable.message_bubble_background_sent_end : R.drawable.message_bubble_background_received_end;
|
2018-06-26 10:27:44 -07:00
|
|
|
} else {
|
2020-01-13 15:29:06 +11:00
|
|
|
background = current.isOutgoing() ? R.drawable.message_bubble_background_sent_middle : R.drawable.message_bubble_background_received_middle;
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
2018-07-18 13:53:50 -07:00
|
|
|
|
|
|
|
bodyBubble.setBackgroundResource(background);
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isStartOfMessageCluster(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, boolean isGroupThread) {
|
|
|
|
if (isGroupThread) {
|
|
|
|
return !previous.isPresent() || previous.get().isUpdate() || !DateUtils.isSameDay(current.getTimestamp(), previous.get().getTimestamp()) ||
|
|
|
|
!current.getRecipient().getAddress().equals(previous.get().getRecipient().getAddress());
|
|
|
|
} else {
|
|
|
|
return !previous.isPresent() || previous.get().isUpdate() || !DateUtils.isSameDay(current.getTimestamp(), previous.get().getTimestamp()) ||
|
|
|
|
current.isOutgoing() != previous.get().isOutgoing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isEndOfMessageCluster(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
|
|
|
|
if (isGroupThread) {
|
|
|
|
return !next.isPresent() || next.get().isUpdate() || !DateUtils.isSameDay(current.getTimestamp(), next.get().getTimestamp()) ||
|
|
|
|
!current.getRecipient().getAddress().equals(next.get().getRecipient().getAddress());
|
|
|
|
} else {
|
|
|
|
return !next.isPresent() || next.get().isUpdate() || !DateUtils.isSameDay(current.getTimestamp(), next.get().getTimestamp()) ||
|
|
|
|
current.isOutgoing() != next.get().isOutgoing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isSingularMessage(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
|
|
|
|
return isStartOfMessageCluster(current, previous, isGroupThread) && isEndOfMessageCluster(current, next, isGroupThread);
|
|
|
|
}
|
|
|
|
|
2018-07-23 14:08:45 +02:00
|
|
|
private void setMessageSpacing(@NonNull Context context, @NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
|
|
|
|
int spacingTop = readDimen(context, R.dimen.conversation_vertical_message_spacing_collapse);
|
|
|
|
int spacingBottom = spacingTop;
|
2018-07-12 16:03:32 -07:00
|
|
|
|
2018-07-23 14:08:45 +02:00
|
|
|
if (isStartOfMessageCluster(current, previous, isGroupThread)) {
|
|
|
|
spacingTop = readDimen(context, R.dimen.conversation_vertical_message_spacing_default);
|
|
|
|
}
|
2018-06-26 10:27:44 -07:00
|
|
|
|
2018-07-23 14:08:45 +02:00
|
|
|
if (isEndOfMessageCluster(current, next, isGroupThread)) {
|
|
|
|
spacingBottom = readDimen(context, R.dimen.conversation_vertical_message_spacing_default);
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
2018-07-12 16:03:32 -07:00
|
|
|
|
2018-07-23 14:08:45 +02:00
|
|
|
ViewUtil.setPaddingTop(this, spacingTop);
|
|
|
|
ViewUtil.setPaddingBottom(this, spacingBottom);
|
2018-06-26 10:27:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private int readDimen(@NonNull Context context, @DimenRes int dimenId) {
|
|
|
|
return context.getResources().getDimensionPixelOffset(dimenId);
|
|
|
|
}
|
|
|
|
|
2015-05-26 13:12:11 -07:00
|
|
|
/// Event handlers
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2015-05-26 13:12:11 -07:00
|
|
|
private void handleApproveIdentity() {
|
|
|
|
List<IdentityKeyMismatch> mismatches = messageRecord.getIdentityKeyMismatches();
|
2015-05-21 19:13:03 +02:00
|
|
|
|
2015-05-26 13:12:11 -07:00
|
|
|
if (mismatches.size() != 1) {
|
|
|
|
throw new AssertionError("Identity mismatch count: " + mismatches.size());
|
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
new ConfirmIdentityDialog(context, messageRecord, mismatches.get(0)).show();
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2019-02-26 19:29:52 -08:00
|
|
|
private Spannable getLongMessageSpan(@NonNull MessageRecord messageRecord) {
|
|
|
|
String message;
|
|
|
|
Runnable action;
|
|
|
|
|
|
|
|
if (messageRecord.isMms()) {
|
|
|
|
TextSlide slide = ((MmsMessageRecord) messageRecord).getSlideDeck().getTextSlide();
|
|
|
|
|
|
|
|
if (slide != null && slide.asAttachment().getTransferState() == AttachmentDatabase.TRANSFER_PROGRESS_DONE) {
|
|
|
|
message = getResources().getString(R.string.ConversationItem_read_more);
|
|
|
|
action = () -> eventListener.onMoreTextClicked(conversationRecipient.getAddress(), messageRecord.getId(), messageRecord.isMms());
|
|
|
|
} else if (slide != null && slide.asAttachment().getTransferState() == AttachmentDatabase.TRANSFER_PROGRESS_STARTED) {
|
|
|
|
message = getResources().getString(R.string.ConversationItem_pending);
|
|
|
|
action = () -> {};
|
|
|
|
} else if (slide != null) {
|
|
|
|
message = getResources().getString(R.string.ConversationItem_download_more);
|
|
|
|
action = () -> singleDownloadClickListener.onClick(bodyText, slide);
|
|
|
|
} else {
|
|
|
|
message = getResources().getString(R.string.ConversationItem_read_more);
|
|
|
|
action = () -> eventListener.onMoreTextClicked(conversationRecipient.getAddress(), messageRecord.getId(), messageRecord.isMms());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
message = getResources().getString(R.string.ConversationItem_read_more);
|
|
|
|
action = () -> eventListener.onMoreTextClicked(conversationRecipient.getAddress(), messageRecord.getId(), messageRecord.isMms());
|
|
|
|
}
|
|
|
|
|
|
|
|
SpannableStringBuilder span = new SpannableStringBuilder(message);
|
|
|
|
CharacterStyle style = new ClickableSpan() {
|
|
|
|
@Override
|
|
|
|
public void onClick(@NonNull View widget) {
|
|
|
|
if (eventListener != null && batchSelected.isEmpty()) {
|
|
|
|
action.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateDrawState(@NonNull TextPaint ds) {
|
|
|
|
ds.setTypeface(Typeface.DEFAULT_BOLD);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
span.setSpan(style, 0, span.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
return span;
|
|
|
|
}
|
|
|
|
|
2015-07-22 17:47:38 -07:00
|
|
|
@Override
|
2017-09-06 10:31:48 -07:00
|
|
|
public void onModified(final Recipient modified) {
|
2017-09-12 22:48:30 -07:00
|
|
|
Util.runOnMain(() -> {
|
2018-07-12 16:03:32 -07:00
|
|
|
setBubbleState(messageRecord);
|
|
|
|
setContactPhoto(recipient);
|
|
|
|
setGroupMessageStatus(messageRecord, recipient);
|
2017-09-12 22:48:30 -07:00
|
|
|
setAudioViewTint(messageRecord, conversationRecipient);
|
2016-08-14 07:55:43 +02:00
|
|
|
});
|
2015-10-21 15:32:29 -07:00
|
|
|
}
|
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
private class SharedContactEventListener implements SharedContactView.EventListener {
|
|
|
|
@Override
|
|
|
|
public void onAddToContactsClicked(@NonNull Contact contact) {
|
|
|
|
if (eventListener != null && batchSelected.isEmpty()) {
|
|
|
|
eventListener.onAddToContactsClicked(contact);
|
|
|
|
} else {
|
|
|
|
passthroughClickListener.onClick(sharedContactStub.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInviteClicked(@NonNull List<Recipient> choices) {
|
|
|
|
if (eventListener != null && batchSelected.isEmpty()) {
|
|
|
|
eventListener.onInviteSharedContactClicked(choices);
|
|
|
|
} else {
|
|
|
|
passthroughClickListener.onClick(sharedContactStub.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMessageClicked(@NonNull List<Recipient> choices) {
|
|
|
|
if (eventListener != null && batchSelected.isEmpty()) {
|
|
|
|
eventListener.onMessageSharedContactClicked(choices);
|
|
|
|
} else {
|
|
|
|
passthroughClickListener.onClick(sharedContactStub.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class SharedContactClickListener implements View.OnClickListener {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (eventListener != null && batchSelected.isEmpty() && messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getSharedContacts().isEmpty()) {
|
|
|
|
eventListener.onSharedContactDetailsClicked(((MmsMessageRecord) messageRecord).getSharedContacts().get(0), sharedContactStub.get().getAvatarView());
|
|
|
|
} else {
|
|
|
|
passthroughClickListener.onClick(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 00:41:05 -08:00
|
|
|
private class LinkPreviewClickListener implements View.OnClickListener {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (eventListener != null && batchSelected.isEmpty() && messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getLinkPreviews().isEmpty()) {
|
|
|
|
eventListener.onLinkPreviewClicked(((MmsMessageRecord) messageRecord).getLinkPreviews().get(0));
|
|
|
|
} else {
|
|
|
|
passthroughClickListener.onClick(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class LinkPreviewThumbnailClickListener implements SlideClickListener {
|
|
|
|
public void onClick(final View v, final Slide slide) {
|
|
|
|
if (eventListener != null && batchSelected.isEmpty() && messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getLinkPreviews().isEmpty()) {
|
|
|
|
eventListener.onLinkPreviewClicked(((MmsMessageRecord) messageRecord).getLinkPreviews().get(0));
|
|
|
|
} else {
|
|
|
|
performClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 23:33:37 -08:00
|
|
|
private class AttachmentDownloadClickListener implements SlidesClickedListener {
|
2017-01-20 15:26:17 -08:00
|
|
|
@Override
|
2018-11-08 23:33:37 -08:00
|
|
|
public void onClick(View v, final List<Slide> slides) {
|
2018-08-02 09:50:36 -04:00
|
|
|
Log.i(TAG, "onClick() for attachment download");
|
2017-01-20 15:26:17 -08:00
|
|
|
if (messageRecord.isMmsNotification()) {
|
2018-08-02 09:50:36 -04:00
|
|
|
Log.i(TAG, "Scheduling MMS attachment download");
|
2017-01-20 15:26:17 -08:00
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2019-03-28 08:56:35 -07:00
|
|
|
.add(new MmsDownloadJob(messageRecord.getId(),
|
2017-01-20 15:26:17 -08:00
|
|
|
messageRecord.getThreadId(), false));
|
|
|
|
} else {
|
2018-11-08 23:33:37 -08:00
|
|
|
Log.i(TAG, "Scheduling push attachment downloads for " + slides.size() + " items");
|
2017-07-21 15:59:27 -07:00
|
|
|
|
2018-11-08 23:33:37 -08:00
|
|
|
for (Slide slide : slides) {
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2019-03-28 08:56:35 -07:00
|
|
|
.add(new AttachmentDownloadJob(messageRecord.getId(),
|
2018-11-08 23:33:37 -08:00
|
|
|
((DatabaseAttachment)slide.asAttachment()).getAttachmentId(), true));
|
|
|
|
}
|
2017-01-20 15:26:17 -08:00
|
|
|
}
|
2015-08-24 15:24:31 -07:00
|
|
|
}
|
|
|
|
}
|
2015-09-16 17:31:24 -07:00
|
|
|
|
2018-11-08 23:33:37 -08:00
|
|
|
private class SlideClickPassthroughListener implements SlideClickListener {
|
|
|
|
|
|
|
|
private final SlidesClickedListener original;
|
|
|
|
|
|
|
|
private SlideClickPassthroughListener(@NonNull SlidesClickedListener original) {
|
|
|
|
this.original = original;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v, Slide slide) {
|
|
|
|
original.onClick(v, Collections.singletonList(slide));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 10:21:30 -04:00
|
|
|
private class StickerClickListener implements SlideClickListener {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v, Slide slide) {
|
|
|
|
if (shouldInterceptClicks(messageRecord) || !batchSelected.isEmpty()) {
|
|
|
|
performClick();
|
|
|
|
} else if (eventListener != null && hasSticker(messageRecord)){
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
eventListener.onStickerClicked(((MmsMessageRecord) messageRecord).getSlideDeck().getStickerSlide().asAttachment().getSticker());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-21 15:32:29 -07:00
|
|
|
private class ThumbnailClickListener implements SlideClickListener {
|
2015-03-31 15:44:41 -07:00
|
|
|
public void onClick(final View v, final Slide slide) {
|
2015-09-24 16:46:57 -07:00
|
|
|
if (shouldInterceptClicks(messageRecord) || !batchSelected.isEmpty()) {
|
|
|
|
performClick();
|
2016-11-26 12:10:14 -08:00
|
|
|
} else if (MediaPreviewActivity.isContentTypeSupported(slide.getContentType()) && slide.getUri() != null) {
|
2014-08-12 12:11:23 -07:00
|
|
|
Intent intent = new Intent(context, MediaPreviewActivity.class);
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
intent.setDataAndType(slide.getUri(), slide.getContentType());
|
2017-09-20 18:14:28 -07:00
|
|
|
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, conversationRecipient.getAddress());
|
2017-10-04 11:35:16 -07:00
|
|
|
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, messageRecord.isOutgoing());
|
2015-07-06 17:14:57 -05:00
|
|
|
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, messageRecord.getTimestamp());
|
2016-11-26 12:10:14 -08:00
|
|
|
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, slide.asAttachment().getSize());
|
2018-11-08 23:33:37 -08:00
|
|
|
intent.putExtra(MediaPreviewActivity.CAPTION_EXTRA, slide.getCaption().orNull());
|
2018-01-23 12:39:30 -08:00
|
|
|
intent.putExtra(MediaPreviewActivity.LEFT_IS_RECENT_EXTRA, false);
|
2015-01-29 20:37:01 -10:00
|
|
|
|
2015-03-13 11:23:01 -07:00
|
|
|
context.startActivity(intent);
|
2016-12-11 13:37:27 -08:00
|
|
|
} else if (slide.getUri() != null) {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "Clicked: " + slide.getUri() + " , " + slide.getContentType());
|
2017-03-28 12:05:30 -07:00
|
|
|
Uri publicUri = PartAuthority.getAttachmentPublicUri(slide.getUri());
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "Public URI: " + publicUri);
|
2017-03-28 12:05:30 -07:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
intent.setDataAndType(PartAuthority.getAttachmentPublicUri(slide.getUri()), slide.getContentType());
|
|
|
|
try {
|
|
|
|
context.startActivity(intent);
|
|
|
|
} catch (ActivityNotFoundException anfe) {
|
|
|
|
Log.w(TAG, "No activity existed to view the media.");
|
|
|
|
Toast.makeText(context, R.string.ConversationItem_unable_to_open_media, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2014-08-12 12:11:23 -07:00
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
|
2015-09-15 15:28:27 -07:00
|
|
|
private class PassthroughClickListener implements View.OnLongClickListener, View.OnClickListener {
|
|
|
|
|
2015-09-24 16:46:57 -07:00
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
2017-03-28 14:34:36 +02:00
|
|
|
if (bodyText.hasSelection()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-15 15:28:27 -07:00
|
|
|
performLongClick();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:46:57 -07:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-09-15 15:28:27 -07:00
|
|
|
performClick();
|
|
|
|
}
|
|
|
|
}
|
2017-03-28 12:05:30 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
private class ClickListener implements View.OnClickListener {
|
2015-09-23 17:19:24 -07:00
|
|
|
private OnClickListener parent;
|
2015-09-15 15:28:27 -07:00
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
ClickListener(@Nullable OnClickListener parent) {
|
2015-09-23 17:19:24 -07:00
|
|
|
this.parent = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (!shouldInterceptClicks(messageRecord) && parent != null) {
|
|
|
|
parent.onClick(v);
|
|
|
|
} else if (messageRecord.isFailed()) {
|
2015-01-15 13:35:35 -08:00
|
|
|
Intent intent = new Intent(context, MessageDetailsActivity.class);
|
|
|
|
intent.putExtra(MessageDetailsActivity.MESSAGE_ID_EXTRA, messageRecord.getId());
|
2015-08-15 14:00:08 +02:00
|
|
|
intent.putExtra(MessageDetailsActivity.THREAD_ID_EXTRA, messageRecord.getThreadId());
|
2015-01-15 13:35:35 -08:00
|
|
|
intent.putExtra(MessageDetailsActivity.TYPE_EXTRA, messageRecord.isMms() ? MmsSmsDatabase.MMS_TRANSPORT : MmsSmsDatabase.SMS_TRANSPORT);
|
2015-09-21 17:41:27 -07:00
|
|
|
intent.putExtra(MessageDetailsActivity.IS_PUSH_GROUP_EXTRA, groupThread && messageRecord.isPush());
|
2017-08-01 08:56:00 -07:00
|
|
|
intent.putExtra(MessageDetailsActivity.ADDRESS_EXTRA, conversationRecipient.getAddress());
|
2015-01-15 13:35:35 -08:00
|
|
|
context.startActivity(intent);
|
2015-05-26 13:12:11 -07:00
|
|
|
} else if (!messageRecord.isOutgoing() && messageRecord.isIdentityMismatchFailure()) {
|
|
|
|
handleApproveIdentity();
|
2015-03-11 14:23:45 -07:00
|
|
|
} else if (messageRecord.isPendingInsecureSmsFallback()) {
|
2014-03-01 14:17:55 -08:00
|
|
|
handleMessageApproval();
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2012-07-19 19:23:49 -07:00
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
|
|
|
|
2014-03-01 14:17:55 -08:00
|
|
|
private void handleMessageApproval() {
|
2014-03-31 18:47:24 -07:00
|
|
|
final int title;
|
|
|
|
final int message;
|
2014-06-13 17:39:29 -07:00
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
if (messageRecord.isMms()) title = R.string.ConversationItem_click_to_approve_unencrypted_mms_dialog_title;
|
|
|
|
else title = R.string.ConversationItem_click_to_approve_unencrypted_sms_dialog_title;
|
2014-06-13 17:39:29 -07:00
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
message = R.string.ConversationItem_click_to_approve_unencrypted_dialog_message;
|
2014-03-31 18:47:24 -07:00
|
|
|
|
2015-05-20 23:36:30 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
2014-03-31 18:47:24 -07:00
|
|
|
builder.setTitle(title);
|
2014-06-13 17:39:29 -07:00
|
|
|
|
2014-03-31 18:47:24 -07:00
|
|
|
if (message > -1) builder.setMessage(message);
|
2014-06-13 17:39:29 -07:00
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
builder.setPositiveButton(R.string.yes, (dialogInterface, i) -> {
|
|
|
|
if (messageRecord.isMms()) {
|
|
|
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
|
|
|
database.markAsInsecure(messageRecord.getId());
|
|
|
|
database.markAsOutbox(messageRecord.getId());
|
|
|
|
database.markAsForcedSms(messageRecord.getId());
|
|
|
|
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2019-03-28 08:56:35 -07:00
|
|
|
.add(new MmsSendJob(messageRecord.getId()));
|
2018-02-01 19:22:48 -08:00
|
|
|
} else {
|
|
|
|
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
|
|
|
|
database.markAsInsecure(messageRecord.getId());
|
|
|
|
database.markAsOutbox(messageRecord.getId());
|
|
|
|
database.markAsForcedSms(messageRecord.getId());
|
|
|
|
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
|
|
|
.add(new SmsSendJob(context, messageRecord.getId(),
|
|
|
|
messageRecord.getIndividualRecipient().getAddress().serialize()));
|
2014-03-01 14:17:55 -08:00
|
|
|
}
|
|
|
|
});
|
2014-06-13 17:39:29 -07:00
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
builder.setNegativeButton(R.string.no, (dialogInterface, i) -> {
|
|
|
|
if (messageRecord.isMms()) {
|
|
|
|
DatabaseFactory.getMmsDatabase(context).markAsSentFailed(messageRecord.getId());
|
|
|
|
} else {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageRecord.getId());
|
2014-03-01 14:17:55 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.show();
|
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|