Search in sources :

Example 1 with TextSlide

use of org.thoughtcrime.securesms.mms.TextSlide in project Signal-Android by WhisperSystems.

the class ConversationItem method getLongMessageSpan.

// / Event handlers
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.getId(), 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.getId(), messageRecord.getId(), messageRecord.isMms());
        }
    } else {
        message = getResources().getString(R.string.ConversationItem_read_more);
        action = () -> eventListener.onMoreTextClicked(conversationRecipient.getId(), 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;
}
Also used : NonNull(androidx.annotation.NonNull) TextSlide(org.thoughtcrime.securesms.mms.TextSlide) SpannableString(android.text.SpannableString) ClickableSpan(android.text.style.ClickableSpan) LinkPreviewView(org.thoughtcrime.securesms.components.LinkPreviewView) AlertView(org.thoughtcrime.securesms.components.AlertView) ViewOnceMessageView(org.thoughtcrime.securesms.revealable.ViewOnceMessageView) PlaybackSpeedToggleTextView(org.thoughtcrime.securesms.components.PlaybackSpeedToggleTextView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) DocumentView(org.thoughtcrime.securesms.components.DocumentView) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) View(android.view.View) QuoteView(org.thoughtcrime.securesms.components.QuoteView) SharedContactView(org.thoughtcrime.securesms.components.SharedContactView) TextView(android.widget.TextView) ReactionsConversationView(org.thoughtcrime.securesms.reactions.ReactionsConversationView) BorderlessImageView(org.thoughtcrime.securesms.components.BorderlessImageView) AudioView(org.thoughtcrime.securesms.components.AudioView) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) SpannableStringBuilder(android.text.SpannableStringBuilder) CharacterStyle(android.text.style.CharacterStyle) TextPaint(android.text.TextPaint)

Example 2 with TextSlide

use of org.thoughtcrime.securesms.mms.TextSlide in project Signal-Android by WhisperSystems.

the class MessageUtil method getSplitMessage.

/**
 * @return If the message is longer than the allowed text size, this will return trimmed text with
 *         an accompanying TextSlide. Otherwise it'll just return the original text.
 */
public static SplitResult getSplitMessage(@NonNull Context context, @NonNull String rawText, int maxPrimaryMessageSize) {
    String bodyText = rawText;
    Optional<TextSlide> textSlide = Optional.absent();
    if (bodyText.length() > maxPrimaryMessageSize) {
        bodyText = rawText.substring(0, maxPrimaryMessageSize);
        byte[] textData = rawText.getBytes();
        String timestamp = new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.US).format(new Date());
        String filename = String.format("signal-%s.txt", timestamp);
        Uri textUri = BlobProvider.getInstance().forData(textData).withMimeType(MediaUtil.LONG_TEXT).withFileName(filename).createForSingleSessionInMemory();
        textSlide = Optional.of(new TextSlide(context, textUri, filename, textData.length));
    }
    return new SplitResult(bodyText, textSlide);
}
Also used : TextSlide(org.thoughtcrime.securesms.mms.TextSlide) SimpleDateFormat(java.text.SimpleDateFormat) Uri(android.net.Uri) Date(java.util.Date)

Aggregations

TextSlide (org.thoughtcrime.securesms.mms.TextSlide)2 Uri (android.net.Uri)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextPaint (android.text.TextPaint)1 CharacterStyle (android.text.style.CharacterStyle)1 ClickableSpan (android.text.style.ClickableSpan)1 View (android.view.View)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 BadgeImageView (org.thoughtcrime.securesms.badges.BadgeImageView)1 AlertView (org.thoughtcrime.securesms.components.AlertView)1 AudioView (org.thoughtcrime.securesms.components.AudioView)1 AvatarImageView (org.thoughtcrime.securesms.components.AvatarImageView)1 BorderlessImageView (org.thoughtcrime.securesms.components.BorderlessImageView)1 DocumentView (org.thoughtcrime.securesms.components.DocumentView)1 LinkPreviewView (org.thoughtcrime.securesms.components.LinkPreviewView)1 PlaybackSpeedToggleTextView (org.thoughtcrime.securesms.components.PlaybackSpeedToggleTextView)1