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;
}
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);
}
Aggregations