From c0d5c22a2163ab58c2d1b7cf5e383643a55d67fa Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 2 Sep 2020 16:59:52 +1000 Subject: [PATCH] WIP: show attachment in conversation preview as iOS --- res/values/strings.xml | 4 +++ .../securesms/database/ThreadDatabase.java | 10 +++++-- src/org/thoughtcrime/securesms/mms/Slide.java | 29 ++++++++++++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 4a2b5ca5e3..d61a5ce87c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1855,4 +1855,8 @@ Secure session reset done + + Attachment + Voice Message + diff --git a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java index 1de021e206..d614b412f7 100644 --- a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -618,9 +618,13 @@ public class ThreadDatabase extends Database { } private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) { - if (messageRecord.isMms() && ((MmsMessageRecord) messageRecord).getSharedContacts().size() > 0) { - Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0); - return ContactUtil.getStringSummary(context, contact).toString(); + if (messageRecord.isMms()) { + MmsMessageRecord record = (MmsMessageRecord) messageRecord; + if (record.getSlideDeck().getBody()) + if (record.getSharedContacts().size() > 0) { + Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0); + return ContactUtil.getStringSummary(context, contact).toString(); + } } return messageRecord.getBody(); diff --git a/src/org/thoughtcrime/securesms/mms/Slide.java b/src/org/thoughtcrime/securesms/mms/Slide.java index 2c5dc1cb16..bd3838c4aa 100644 --- a/src/org/thoughtcrime/securesms/mms/Slide.java +++ b/src/org/thoughtcrime/securesms/mms/Slide.java @@ -22,6 +22,7 @@ import android.net.Uri; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.exoplayer2.util.MimeTypes; import org.thoughtcrime.securesms.attachments.Attachment; import org.thoughtcrime.securesms.attachments.UriAttachment; @@ -33,6 +34,8 @@ import org.whispersystems.libsignal.util.guava.Optional; import java.security.SecureRandom; +import network.loki.messenger.R; + public abstract class Slide { protected final Attachment attachment; @@ -59,7 +62,31 @@ public abstract class Slide { @NonNull public Optional getBody() { - return Optional.absent(); + String attachmentString = context.getString(R.string.attachment); + + if (MimeTypes.isAudio(attachment.getContentType())) { + // a missing filename is the legacy way to determine if an audio attachment is + // a voice note vs. other arbitrary audio attachments. + if (attachment.isVoiceNote() || !attachment.getFileName().isEmpty()) { + attachmentString = context.getString(R.string.attachment_type_voice_message); + return Optional.fromNullable("🎤 " + attachmentString); + } + } + return Optional.fromNullable(emojiForMimeType(attachment.getContentType()) + attachmentString); + } + + private String emojiForMimeType(String contentType) { + if (MimeTypes.isVideo(contentType)) { + return "📷 "; + } else if (MimeTypes.isVideo(contentType)) { + return "🎥 "; + } else if (MimeTypes.isAudio(contentType)) { + return "🎧 "; + } else if (MimeTypes.is) { + return "🎡 "; + } else { + return "📎 "; + } } @NonNull