Search in sources :

Example 16 with MediaMmsMessageRecord

use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by signalapp.

the class ConversationItem method setMediaAttributes.

private void setMediaAttributes(@NonNull MessageRecord messageRecord, @NonNull Optional<MessageRecord> previousRecord, @NonNull Optional<MessageRecord> nextRecord, boolean isGroupThread, boolean hasWallpaper, boolean messageRequestAccepted, boolean allowedToPlayInline) {
    boolean showControls = !messageRecord.isFailed();
    ViewUtil.setTopMargin(bodyText, readDimen(R.dimen.message_bubble_top_padding));
    bodyBubble.setQuoteViewProjection(null);
    bodyBubble.setVideoPlayerProjection(null);
    if (eventListener != null && audioViewStub.resolved()) {
        Log.d(TAG, "setMediaAttributes: unregistering voice note callbacks for audio slide " + audioViewStub.get().getAudioSlideUri());
        eventListener.onUnregisterVoiceNoteCallbacks(audioViewStub.get().getPlaybackStateObserver());
    }
    footer.setPlaybackSpeedListener(null);
    if (isViewOnceMessage(messageRecord) && !messageRecord.isRemoteDelete()) {
        revealableStub.get().setVisibility(VISIBLE);
        if (mediaThumbnailStub.resolved())
            mediaThumbnailStub.require().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);
        if (stickerStub.resolved())
            stickerStub.get().setVisibility(View.GONE);
        revealableStub.get().setMessage((MmsMessageRecord) messageRecord, hasWallpaper);
        revealableStub.get().setOnClickListener(revealableClickListener);
        revealableStub.get().setOnLongClickListener(passthroughClickListener);
        updateRevealableMargins(messageRecord, previousRecord, nextRecord, isGroupThread);
        footer.setVisibility(VISIBLE);
    } else if (hasSharedContact(messageRecord)) {
        sharedContactStub.get().setVisibility(VISIBLE);
        if (audioViewStub.resolved())
            audioViewStub.get().setVisibility(View.GONE);
        if (mediaThumbnailStub.resolved())
            mediaThumbnailStub.require().setVisibility(View.GONE);
        if (documentViewStub.resolved())
            documentViewStub.get().setVisibility(View.GONE);
        if (linkPreviewStub.resolved())
            linkPreviewStub.get().setVisibility(GONE);
        if (stickerStub.resolved())
            stickerStub.get().setVisibility(View.GONE);
        if (revealableStub.resolved())
            revealableStub.get().setVisibility(View.GONE);
        sharedContactStub.get().setContact(((MediaMmsMessageRecord) messageRecord).getSharedContacts().get(0), glideRequests, locale);
        sharedContactStub.get().setEventListener(sharedContactEventListener);
        sharedContactStub.get().setOnClickListener(sharedContactClickListener);
        sharedContactStub.get().setOnLongClickListener(passthroughClickListener);
        setSharedContactCorners(messageRecord, previousRecord, nextRecord, isGroupThread);
        ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        footer.setVisibility(GONE);
    } else if (hasLinkPreview(messageRecord) && messageRequestAccepted) {
        linkPreviewStub.get().setVisibility(View.VISIBLE);
        if (audioViewStub.resolved())
            audioViewStub.get().setVisibility(View.GONE);
        if (mediaThumbnailStub.resolved())
            mediaThumbnailStub.require().setVisibility(View.GONE);
        if (documentViewStub.resolved())
            documentViewStub.get().setVisibility(View.GONE);
        if (sharedContactStub.resolved())
            sharedContactStub.get().setVisibility(GONE);
        if (stickerStub.resolved())
            stickerStub.get().setVisibility(View.GONE);
        if (revealableStub.resolved())
            revealableStub.get().setVisibility(View.GONE);
        // noinspection ConstantConditions
        LinkPreview linkPreview = ((MmsMessageRecord) messageRecord).getLinkPreviews().get(0);
        if (hasBigImageLinkPreview(messageRecord)) {
            mediaThumbnailStub.require().setVisibility(VISIBLE);
            mediaThumbnailStub.require().setMinimumThumbnailWidth(readDimen(R.dimen.media_bubble_min_width_with_content));
            mediaThumbnailStub.require().setImageResource(glideRequests, Collections.singletonList(new ImageSlide(context, linkPreview.getThumbnail().get())), showControls, false);
            mediaThumbnailStub.require().setThumbnailClickListener(new LinkPreviewThumbnailClickListener());
            mediaThumbnailStub.require().setDownloadClickListener(downloadClickListener);
            mediaThumbnailStub.require().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.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            ViewUtil.setTopMargin(linkPreviewStub.get(), 0);
        } 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.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            // noinspection ConstantConditions
            int topMargin = isGroupThread && isStartOfMessageCluster(messageRecord, previousRecord, isGroupThread) && !messageRecord.isOutgoing() ? readDimen(R.dimen.message_bubble_top_padding) : 0;
            ViewUtil.setTopMargin(linkPreviewStub.get(), topMargin);
        }
        linkPreviewStub.get().setOnClickListener(linkPreviewClickListener);
        linkPreviewStub.get().setOnLongClickListener(passthroughClickListener);
        footer.setVisibility(VISIBLE);
    } else if (hasAudio(messageRecord)) {
        audioViewStub.get().setVisibility(View.VISIBLE);
        if (mediaThumbnailStub.resolved())
            mediaThumbnailStub.require().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);
        if (stickerStub.resolved())
            stickerStub.get().setVisibility(View.GONE);
        if (revealableStub.resolved())
            revealableStub.get().setVisibility(View.GONE);
        audioViewStub.get().setAudio(Objects.requireNonNull(((MediaMmsMessageRecord) messageRecord).getSlideDeck().getAudioSlide()), new AudioViewCallbacks(), showControls, true);
        audioViewStub.get().setDownloadClickListener(singleDownloadClickListener);
        audioViewStub.get().setOnLongClickListener(passthroughClickListener);
        if (eventListener != null) {
            Log.d(TAG, "setMediaAttributes: registered listener for audio slide " + audioViewStub.get().getAudioSlideUri());
            eventListener.onRegisterVoiceNoteCallbacks(audioViewStub.get().getPlaybackStateObserver());
        } else {
            Log.w(TAG, "setMediaAttributes: could not register listener for audio slide " + audioViewStub.get().getAudioSlideUri());
        }
        ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        footer.setPlaybackSpeedListener(new AudioPlaybackSpeedToggleListener());
        footer.setVisibility(VISIBLE);
    } else if (hasDocument(messageRecord)) {
        documentViewStub.get().setVisibility(View.VISIBLE);
        if (mediaThumbnailStub.resolved())
            mediaThumbnailStub.require().setVisibility(View.GONE);
        if (audioViewStub.resolved())
            audioViewStub.get().setVisibility(View.GONE);
        if (sharedContactStub.resolved())
            sharedContactStub.get().setVisibility(GONE);
        if (linkPreviewStub.resolved())
            linkPreviewStub.get().setVisibility(GONE);
        if (stickerStub.resolved())
            stickerStub.get().setVisibility(View.GONE);
        if (revealableStub.resolved())
            revealableStub.get().setVisibility(View.GONE);
        // noinspection ConstantConditions
        documentViewStub.get().setDocument(((MediaMmsMessageRecord) messageRecord).getSlideDeck().getDocumentSlide(), showControls);
        documentViewStub.get().setDocumentClickListener(new ThumbnailClickListener());
        documentViewStub.get().setDownloadClickListener(singleDownloadClickListener);
        documentViewStub.get().setOnLongClickListener(passthroughClickListener);
        ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ViewUtil.setTopMargin(bodyText, 0);
        footer.setVisibility(VISIBLE);
    } else if ((hasSticker(messageRecord) && isCaptionlessMms(messageRecord)) || isBorderless(messageRecord)) {
        bodyBubble.setBackgroundColor(Color.TRANSPARENT);
        stickerStub.get().setVisibility(View.VISIBLE);
        if (mediaThumbnailStub.resolved())
            mediaThumbnailStub.require().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);
        if (revealableStub.resolved())
            revealableStub.get().setVisibility(View.GONE);
        if (hasSticker(messageRecord)) {
            // noinspection ConstantConditions
            stickerStub.get().setSlide(glideRequests, ((MmsMessageRecord) messageRecord).getSlideDeck().getStickerSlide());
            stickerStub.get().setThumbnailClickListener(new StickerClickListener());
        } else {
            // noinspection ConstantConditions
            stickerStub.get().setSlide(glideRequests, ((MmsMessageRecord) messageRecord).getSlideDeck().getThumbnailSlide());
            stickerStub.get().setThumbnailClickListener((v, slide) -> performClick());
        }
        stickerStub.get().setDownloadClickListener(downloadClickListener);
        stickerStub.get().setOnLongClickListener(passthroughClickListener);
        stickerStub.get().setOnClickListener(passthroughClickListener);
        ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        footer.setVisibility(VISIBLE);
    } else if (hasNoBubble(messageRecord)) {
        bodyBubble.setBackgroundColor(Color.TRANSPARENT);
    } else if (hasThumbnail(messageRecord)) {
        mediaThumbnailStub.require().setVisibility(View.VISIBLE);
        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);
        if (stickerStub.resolved())
            stickerStub.get().setVisibility(View.GONE);
        if (revealableStub.resolved())
            revealableStub.get().setVisibility(View.GONE);
        List<Slide> thumbnailSlides = ((MmsMessageRecord) messageRecord).getSlideDeck().getThumbnailSlides();
        mediaThumbnailStub.require().setMinimumThumbnailWidth(readDimen(isCaptionlessMms(messageRecord) ? R.dimen.media_bubble_min_width_solo : R.dimen.media_bubble_min_width_with_content));
        mediaThumbnailStub.require().setImageResource(glideRequests, thumbnailSlides, showControls, false);
        mediaThumbnailStub.require().setThumbnailClickListener(new ThumbnailClickListener());
        mediaThumbnailStub.require().setDownloadClickListener(downloadClickListener);
        mediaThumbnailStub.require().setOnLongClickListener(passthroughClickListener);
        mediaThumbnailStub.require().setOnClickListener(passthroughClickListener);
        mediaThumbnailStub.require().showShade(messageRecord.isDisplayBodyEmpty(getContext()) && !hasExtraText(messageRecord));
        if (!messageRecord.isOutgoing()) {
            mediaThumbnailStub.require().setConversationColor(getDefaultBubbleColor(hasWallpaper));
        } else {
            mediaThumbnailStub.require().setConversationColor(Color.TRANSPARENT);
        }
        mediaThumbnailStub.require().setBorderless(false);
        setThumbnailCorners(messageRecord, previousRecord, nextRecord, isGroupThread);
        ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        footer.setVisibility(VISIBLE);
        if (thumbnailSlides.size() == 1 && thumbnailSlides.get(0).isVideoGif() && thumbnailSlides.get(0) instanceof VideoSlide) {
            Uri uri = thumbnailSlides.get(0).getUri();
            if (uri != null) {
                mediaItem = MediaItem.fromUri(uri);
            } else {
                mediaItem = null;
            }
            canPlayContent = (GiphyMp4PlaybackPolicy.autoplay() || allowedToPlayInline) && mediaItem != null;
        }
    } else {
        if (mediaThumbnailStub.resolved())
            mediaThumbnailStub.require().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);
        if (stickerStub.resolved())
            stickerStub.get().setVisibility(View.GONE);
        if (revealableStub.resolved())
            revealableStub.get().setVisibility(View.GONE);
        ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        footer.setVisibility(VISIBLE);
        // noinspection ConstantConditions
        int topMargin = !messageRecord.isOutgoing() && isGroupThread && isStartOfMessageCluster(messageRecord, previousRecord, isGroupThread) ? readDimen(R.dimen.message_bubble_text_only_top_margin) : readDimen(R.dimen.message_bubble_top_padding);
        ViewUtil.setTopMargin(bodyText, topMargin);
    }
}
Also used : LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) SlideClickListener(org.thoughtcrime.securesms.mms.SlideClickListener) NonNull(androidx.annotation.NonNull) LongClickMovementMethod(org.thoughtcrime.securesms.util.LongClickMovementMethod) Uri(android.net.Uri) StringUtil(org.thoughtcrime.securesms.util.StringUtil) TouchDelegate(android.view.TouchDelegate) ColorInt(androidx.annotation.ColorInt) LinkPreviewUtil(org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) TextSlide(org.thoughtcrime.securesms.mms.TextSlide) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) BindableConversationItem(org.thoughtcrime.securesms.BindableConversationItem) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) LinkPreviewView(org.thoughtcrime.securesms.components.LinkPreviewView) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ContextCompat(androidx.core.content.ContextCompat) PlaceholderURLSpan(org.thoughtcrime.securesms.util.PlaceholderURLSpan) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) MediaPreviewActivity(org.thoughtcrime.securesms.MediaPreviewActivity) MmsDownloadJob(org.thoughtcrime.securesms.jobs.MmsDownloadJob) MessageRecordUtil(org.thoughtcrime.securesms.util.MessageRecordUtil) Nullable(androidx.annotation.Nullable) TextPaint(android.text.TextPaint) AlertView(org.thoughtcrime.securesms.components.AlertView) LinkifyCompat(androidx.core.text.util.LinkifyCompat) ViewOnceMessageView(org.thoughtcrime.securesms.revealable.ViewOnceMessageView) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) PlaybackSpeedToggleTextView(org.thoughtcrime.securesms.components.PlaybackSpeedToggleTextView) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) Toast(android.widget.Toast) Annotation(android.text.Annotation) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) MultiselectCollection(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectCollection) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) URLSpan(android.text.style.URLSpan) Contact(org.thoughtcrime.securesms.contactshare.Contact) SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) NullableStub(org.thoughtcrime.securesms.util.views.NullableStub) Optional(org.whispersystems.libsignal.util.guava.Optional) ThemeUtil(org.thoughtcrime.securesms.util.ThemeUtil) TypedValue(android.util.TypedValue) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob) DocumentView(org.thoughtcrime.securesms.components.DocumentView) ProjectionList(org.thoughtcrime.securesms.util.ProjectionList) ValueAnimator(android.animation.ValueAnimator) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Rect(android.graphics.Rect) UrlClickHandler(org.thoughtcrime.securesms.util.UrlClickHandler) DimenRes(androidx.annotation.DimenRes) ConversationItemThumbnail(org.thoughtcrime.securesms.components.ConversationItemThumbnail) AttachmentDownloadJob(org.thoughtcrime.securesms.jobs.AttachmentDownloadJob) Spannable(android.text.Spannable) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) ClickableSpan(android.text.style.ClickableSpan) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) R(org.thoughtcrime.securesms.R) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) AttributeSet(android.util.AttributeSet) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SlidesClickedListener(org.thoughtcrime.securesms.mms.SlidesClickedListener) QuoteView(org.thoughtcrime.securesms.components.QuoteView) MediaItem(com.google.android.exoplayer2.MediaItem) Outliner(org.thoughtcrime.securesms.components.Outliner) RecipientForeverObserver(org.thoughtcrime.securesms.recipients.RecipientForeverObserver) PorterDuff(android.graphics.PorterDuff) SharedContactView(org.thoughtcrime.securesms.components.SharedContactView) ViewGroup(android.view.ViewGroup) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) Slide(org.thoughtcrime.securesms.mms.Slide) MentionAnnotation(org.thoughtcrime.securesms.components.mention.MentionAnnotation) SearchUtil(org.thoughtcrime.securesms.util.SearchUtil) ActivityNotFoundException(android.content.ActivityNotFoundException) DateUtils(org.thoughtcrime.securesms.util.DateUtils) RelativeLayout(android.widget.RelativeLayout) GlideRequests(org.thoughtcrime.securesms.mms.GlideRequests) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) ReactionsConversationView(org.thoughtcrime.securesms.reactions.ReactionsConversationView) GiphyMp4PlaybackPolicy(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackPolicy) Projection(org.thoughtcrime.securesms.util.Projection) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) Typeface(android.graphics.Typeface) Context(android.content.Context) Spanned(android.text.Spanned) AlertDialog(androidx.appcompat.app.AlertDialog) InterceptableLongClickCopyLinkSpan(org.thoughtcrime.securesms.util.InterceptableLongClickCopyLinkSpan) BorderlessImageView(org.thoughtcrime.securesms.components.BorderlessImageView) MultiselectPart(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectPart) GiphyMp4PlaybackPolicyEnforcer(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackPolicyEnforcer) Intent(android.content.Intent) VibrateUtil(org.thoughtcrime.securesms.util.VibrateUtil) Linkify(android.text.util.Linkify) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) HashSet(java.util.HashSet) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob) SuppressLint(android.annotation.SuppressLint) LifecycleOwner(androidx.lifecycle.LifecycleOwner) MotionEvent(android.view.MotionEvent) Colorizer(org.thoughtcrime.securesms.conversation.colors.Colorizer) AudioView(org.thoughtcrime.securesms.components.AudioView) Stub(org.thoughtcrime.securesms.util.views.Stub) BackgroundColorSpan(android.text.style.BackgroundColorSpan) Quote(org.thoughtcrime.securesms.database.model.Quote) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) CharacterStyle(android.text.style.CharacterStyle) ConversationItemFooter(org.thoughtcrime.securesms.components.ConversationItemFooter) Collections(java.util.Collections) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) Uri(android.net.Uri) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) ArrayList(java.util.ArrayList) ProjectionList(org.thoughtcrime.securesms.util.ProjectionList) List(java.util.List)

Example 17 with MediaMmsMessageRecord

use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by signalapp.

the class ConversationItem method setQuote.

private void setQuote(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread, @NonNull ChatColors chatColors) {
    boolean startOfCluster = isStartOfMessageCluster(current, previous, isGroupThread);
    if (current.isMms() && !current.isMmsNotification() && ((MediaMmsMessageRecord) current).getQuote() != null) {
        if (quoteView == null) {
            throw new AssertionError();
        }
        Quote quote = ((MediaMmsMessageRecord) current).getQuote();
        // noinspection ConstantConditions
        quoteView.setQuote(glideRequests, quote.getId(), Recipient.live(quote.getAuthor()).get(), quote.getDisplayText(), quote.isOriginalMissing(), quote.getAttachment(), chatColors);
        quoteView.setVisibility(View.VISIBLE);
        quoteView.setTextSize(TypedValue.COMPLEX_UNIT_SP, SignalStore.settings().getMessageFontSize());
        quoteView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
        quoteView.setOnClickListener(view -> {
            if (eventListener != null && batchSelected.isEmpty()) {
                eventListener.onQuoteClicked((MmsMessageRecord) current);
            } else {
                passthroughClickListener.onClick(view);
            }
        });
        quoteView.setOnLongClickListener(passthroughClickListener);
        if (startOfCluster) {
            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);
            }
        }
        if (mediaThumbnailStub.resolved()) {
            ViewUtil.setTopMargin(mediaThumbnailStub.require(), readDimen(R.dimen.message_bubble_top_padding));
        }
        if (linkPreviewStub.resolved() && !hasBigImageLinkPreview(current)) {
            ViewUtil.setTopMargin(linkPreviewStub.get(), readDimen(R.dimen.message_bubble_top_padding));
        }
    } else {
        if (quoteView != null) {
            quoteView.dismiss();
        }
        int topMargin = (current.isOutgoing() || !startOfCluster || !groupThread) ? 0 : readDimen(R.dimen.message_bubble_top_image_margin);
        if (mediaThumbnailStub.resolved()) {
            ViewUtil.setTopMargin(mediaThumbnailStub.require(), topMargin);
        }
    }
}
Also used : Quote(org.thoughtcrime.securesms.database.model.Quote) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 18 with MediaMmsMessageRecord

use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by signalapp.

the class ConversationFragment method performSave.

private void performSave(final MediaMmsMessageRecord message) {
    List<SaveAttachmentTask.Attachment> attachments = Stream.of(message.getSlideDeck().getSlides()).filter(s -> s.getUri() != null && (s.hasImage() || s.hasVideo() || s.hasAudio() || s.hasDocument())).map(s -> new SaveAttachmentTask.Attachment(s.getUri(), s.getContentType(), message.getDateReceived(), s.getFileName().orNull())).toList();
    if (!Util.isEmpty(attachments)) {
        SaveAttachmentTask saveTask = new SaveAttachmentTask(getActivity());
        saveTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, attachments.toArray(new SaveAttachmentTask.Attachment[0]));
        return;
    }
    Log.w(TAG, "No slide with attachable media found, failing nicely.");
    Toast.makeText(getActivity(), getResources().getQuantityString(R.plurals.ConversationFragment_error_while_saving_attachments_to_sd_card, 1), Toast.LENGTH_LONG).show();
}
Also used : TypingStatusRepository(org.thoughtcrime.securesms.components.TypingStatusRepository) Bundle(android.os.Bundle) GroupMigrationMembershipChange(org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange) RecaptchaProofBottomSheetFragment(org.thoughtcrime.securesms.ratelimit.RecaptchaProofBottomSheetFragment) GiphyMp4ItemDecoration(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ItemDecoration) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) RecyclerViewColorizer(org.thoughtcrime.securesms.conversation.colors.RecyclerViewColorizer) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask) Manifest(android.Manifest) LayoutTransition(android.animation.LayoutTransition) ActivityOptionsCompat(androidx.core.app.ActivityOptionsCompat) MultiselectForwardFragmentArgs(org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragmentArgs) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) SnapToTopDataObserver(org.thoughtcrime.securesms.util.SnapToTopDataObserver) HtmlUtil(org.thoughtcrime.securesms.util.HtmlUtil) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) MultiDeviceViewOnceOpenJob(org.thoughtcrime.securesms.jobs.MultiDeviceViewOnceOpenJob) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) ViewCompat(androidx.core.view.ViewCompat) StickyHeaderViewHolder(org.thoughtcrime.securesms.conversation.ConversationAdapter.StickyHeaderViewHolder) MultiselectForwardFragment(org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragment) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) DimensionUnit(org.signal.core.util.DimensionUnit) SmoothScrollingLinearLayoutManager(org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager) MessageRecordUtil(org.thoughtcrime.securesms.util.MessageRecordUtil) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StickyHeaderDecoration(org.thoughtcrime.securesms.util.StickyHeaderDecoration) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) ViewKt(androidx.core.view.ViewKt) Util(org.thoughtcrime.securesms.util.Util) ArrayList(java.util.ArrayList) MessageRequestState(org.thoughtcrime.securesms.messagerequests.MessageRequestState) SpannableStringBuilder(android.text.SpannableStringBuilder) SignalProxyUtil(org.thoughtcrime.securesms.util.SignalProxyUtil) Toast(android.widget.Toast) Menu(android.view.Menu) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) GiphyMp4ProjectionRecycler(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ProjectionRecycler) LiveData(androidx.lifecycle.LiveData) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) Collectors(com.annimon.stream.Collectors) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Contact(org.thoughtcrime.securesms.contactshare.Contact) RecipientBottomSheetDialogFragment(org.thoughtcrime.securesms.recipients.ui.bottomsheet.RecipientBottomSheetDialogFragment) Permissions(org.thoughtcrime.securesms.permissions.Permissions) TextUtils(android.text.TextUtils) SafetyNumberChangeDialog(org.thoughtcrime.securesms.conversation.ui.error.SafetyNumberChangeDialog) IOException(java.io.IOException) Optional(org.whispersystems.libsignal.util.guava.Optional) ExecutionException(java.util.concurrent.ExecutionException) ItemClickListener(org.thoughtcrime.securesms.conversation.ConversationAdapter.ItemClickListener) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) Configuration(android.content.res.Configuration) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) RecipientExporter(org.thoughtcrime.securesms.recipients.RecipientExporter) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) PhoneNumberFormatter(org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter) ValueAnimator(android.animation.ValueAnimator) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Rect(android.graphics.Rect) ConversationTypingView(org.thoughtcrime.securesms.components.ConversationTypingView) SignalBottomActionBar(org.thoughtcrime.securesms.components.menu.SignalBottomActionBar) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) GroupLinkInviteFriendsBottomSheetDialogFragment(org.thoughtcrime.securesms.groups.ui.invitesandrequests.invite.GroupLinkInviteFriendsBottomSheetDialogFragment) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Animator(android.animation.Animator) R(org.thoughtcrime.securesms.R) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) GiphyMp4ProjectionPlayerHolder(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ProjectionPlayerHolder) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Locale(java.util.Locale) View(android.view.View) ViewOnceUtil(org.thoughtcrime.securesms.revealable.ViewOnceUtil) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Animation(android.view.animation.Animation) RecyclerView(androidx.recyclerview.widget.RecyclerView) VoiceNotePlaybackState(org.thoughtcrime.securesms.components.voice.VoiceNotePlaybackState) NavHostFragment(androidx.navigation.fragment.NavHostFragment) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) ViewSwitcher(android.widget.ViewSwitcher) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) AsyncTask(android.os.AsyncTask) ContactUtil(org.thoughtcrime.securesms.contactshare.ContactUtil) MessageRequestViewModel(org.thoughtcrime.securesms.messagerequests.MessageRequestViewModel) HtmlCompat(androidx.core.text.HtmlCompat) LongMessageFragment(org.thoughtcrime.securesms.longmessage.LongMessageFragment) NotificationProfile(org.thoughtcrime.securesms.notifications.profiles.NotificationProfile) ViewGroup(android.view.ViewGroup) VoiceNoteMediaControllerOwner(org.thoughtcrime.securesms.components.voice.VoiceNoteMediaControllerOwner) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) Slide(org.thoughtcrime.securesms.mms.Slide) ConversationItemAnimator(org.thoughtcrime.securesms.conversation.mutiselect.ConversationItemAnimator) GroupId(org.thoughtcrime.securesms.groups.GroupId) Toolbar(androidx.appcompat.widget.Toolbar) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) GiphyMp4PlaybackPolicy(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackPolicy) OnScrollListener(androidx.recyclerview.widget.RecyclerView.OnScrollListener) SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask) Snackbar(com.google.android.material.snackbar.Snackbar) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) SharedContactDetailsActivity(org.thoughtcrime.securesms.contactshare.SharedContactDetailsActivity) TopToastPopup(org.thoughtcrime.securesms.util.TopToastPopup) MultiselectPart(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectPart) ReactionsBottomSheetDialogFragment(org.thoughtcrime.securesms.reactions.ReactionsBottomSheetDialogFragment) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) Intent(android.content.Intent) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) StickerPackPreviewActivity(org.thoughtcrime.securesms.stickers.StickerPackPreviewActivity) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) GroupsV1MigrationInfoBottomSheetDialogFragment(org.thoughtcrime.securesms.groups.ui.migration.GroupsV1MigrationInfoBottomSheetDialogFragment) Colorizer(org.thoughtcrime.securesms.conversation.colors.Colorizer) ConversationScrollToView(org.thoughtcrime.securesms.components.ConversationScrollToView) ViewOnceMessageActivity(org.thoughtcrime.securesms.revealable.ViewOnceMessageActivity) GiphyMp4PlaybackController(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackController) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) VerifyIdentityActivity(org.thoughtcrime.securesms.verify.VerifyIdentityActivity) MultiselectItemDecoration(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectItemDecoration) GroupDescriptionDialog(org.thoughtcrime.securesms.groups.ui.managegroup.dialogs.GroupDescriptionDialog) GroupDescriptionUtil(org.thoughtcrime.securesms.groups.v2.GroupDescriptionUtil) LayoutInflater(android.view.LayoutInflater) ActivityCompat(androidx.core.app.ActivityCompat) MessageDetailsFragment(org.thoughtcrime.securesms.messagedetails.MessageDetailsFragment) RemoteDeleteUtil(org.thoughtcrime.securesms.util.RemoteDeleteUtil) BlobProvider(org.thoughtcrime.securesms.providers.BlobProvider) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) CachedInflater(org.thoughtcrime.securesms.util.CachedInflater) InMemoryMessageRecord(org.thoughtcrime.securesms.database.model.InMemoryMessageRecord) ActionMode(androidx.appcompat.view.ActionMode) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Color(android.graphics.Color) Observer(androidx.lifecycle.Observer) StorageUtil(org.thoughtcrime.securesms.util.StorageUtil) Bitmap(android.graphics.Bitmap) EnableCallNotificationSettingsDialog(org.thoughtcrime.securesms.conversation.ui.error.EnableCallNotificationSettingsDialog) ViewTreeObserver(android.view.ViewTreeObserver) Collections(java.util.Collections) InputStream(java.io.InputStream) SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask)

Example 19 with MediaMmsMessageRecord

use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by signalapp.

the class ConversationFragment method setCorrectActionModeMenuVisibility.

private void setCorrectActionModeMenuVisibility() {
    Set<MultiselectPart> selectedParts = getListAdapter().getSelectedItems();
    if (actionMode != null && selectedParts.size() == 0) {
        actionMode.finish();
        return;
    }
    setBottomActionBarVisibility(true);
    MenuState menuState = MenuState.getMenuState(recipient.get(), selectedParts, messageRequestViewModel.shouldShowMessageRequest(), groupViewModel.isNonAdminInAnnouncementGroup());
    List<ActionItem> items = new ArrayList<>();
    if (menuState.shouldShowReplyAction()) {
        items.add(new ActionItem(R.drawable.ic_reply_24_tinted, getResources().getString(R.string.conversation_selection__menu_reply), () -> {
            maybeShowSwipeToReplyTooltip();
            handleReplyMessage(getSelectedConversationMessage());
            actionMode.finish();
        }));
    }
    if (menuState.shouldShowForwardAction()) {
        items.add(new ActionItem(R.drawable.ic_forward_24_tinted, getResources().getString(R.string.conversation_selection__menu_forward), () -> handleForwardMessageParts(selectedParts)));
    }
    if (menuState.shouldShowSaveAttachmentAction()) {
        items.add(new ActionItem(R.drawable.ic_save_24_tinted, getResources().getString(R.string.conversation_selection__menu_save), () -> {
            handleSaveAttachment((MediaMmsMessageRecord) getSelectedConversationMessage().getMessageRecord());
            actionMode.finish();
        }));
    }
    if (menuState.shouldShowCopyAction()) {
        items.add(new ActionItem(R.drawable.ic_copy_24_tinted, getResources().getString(R.string.conversation_selection__menu_copy), () -> {
            handleCopyMessage(selectedParts);
            actionMode.finish();
        }));
    }
    if (menuState.shouldShowDetailsAction()) {
        items.add(new ActionItem(R.drawable.ic_info_tinted_24, getResources().getString(R.string.conversation_selection__menu_message_details), () -> {
            handleDisplayDetails(getSelectedConversationMessage());
            actionMode.finish();
        }));
    }
    if (menuState.shouldShowDeleteAction()) {
        items.add(new ActionItem(R.drawable.ic_delete_tinted_24, getResources().getString(R.string.conversation_selection__menu_delete), () -> {
            handleDeleteMessages(selectedParts);
            actionMode.finish();
        }));
    }
    bottomActionBar.setItems(items);
}
Also used : MultiselectPart(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectPart) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) ArrayList(java.util.ArrayList)

Example 20 with MediaMmsMessageRecord

use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by signalapp.

the class ConversationDataSource method load.

@Override
@Nullable
public ConversationMessage load(@NonNull MessageId messageId) {
    Stopwatch stopwatch = new Stopwatch("load(" + messageId + "), thread " + threadId);
    MessageDatabase database = messageId.isMms() ? SignalDatabase.mms() : SignalDatabase.sms();
    MessageRecord record = database.getMessageRecordOrNull(messageId.getId());
    stopwatch.split("message");
    try {
        if (record != null) {
            List<Mention> mentions;
            if (messageId.isMms()) {
                mentions = SignalDatabase.mentions().getMentionsForMessage(messageId.getId());
            } else {
                mentions = Collections.emptyList();
            }
            stopwatch.split("mentions");
            List<ReactionRecord> reactions = SignalDatabase.reactions().getReactions(messageId);
            record = ReactionHelper.recordWithReactions(record, reactions);
            stopwatch.split("reactions");
            if (messageId.isMms()) {
                List<DatabaseAttachment> attachments = SignalDatabase.attachments().getAttachmentsForMessage(messageId.getId());
                if (attachments.size() > 0) {
                    record = ((MediaMmsMessageRecord) record).withAttachments(context, attachments);
                }
            }
            stopwatch.split("attachments");
            return ConversationMessage.ConversationMessageFactory.createWithUnresolvedData(ApplicationDependencies.getApplication(), record, mentions);
        } else {
            return null;
        }
    } finally {
        stopwatch.stop(TAG);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) Mention(org.thoughtcrime.securesms.database.model.Mention) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) InMemoryMessageRecord(org.thoughtcrime.securesms.database.model.InMemoryMessageRecord) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) Nullable(androidx.annotation.Nullable)

Aggregations

MediaMmsMessageRecord (org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)20 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)12 Nullable (androidx.annotation.Nullable)8 MultiselectPart (org.thoughtcrime.securesms.conversation.mutiselect.MultiselectPart)8 MmsMessageRecord (org.thoughtcrime.securesms.database.model.MmsMessageRecord)8 Slide (org.thoughtcrime.securesms.mms.Slide)8 SuppressLint (android.annotation.SuppressLint)7 Intent (android.content.Intent)6 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)6 ArrayList (java.util.ArrayList)5 ValueAnimator (android.animation.ValueAnimator)4 Context (android.content.Context)4 Color (android.graphics.Color)4 Rect (android.graphics.Rect)4 Uri (android.net.Uri)4 SpannableStringBuilder (android.text.SpannableStringBuilder)4 TextPaint (android.text.TextPaint)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 TextView (android.widget.TextView)4