From e79ee7803fea85ec999e0f6dc803fc1227096cd0 Mon Sep 17 00:00:00 2001 From: McLoo Date: Fri, 11 Dec 2015 10:39:55 +0100 Subject: [PATCH] Enable preview for image drafts Closes #4863 --- .../securesms/MediaPreviewActivity.java | 2 +- .../securesms/mms/AttachmentManager.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/MediaPreviewActivity.java b/src/org/thoughtcrime/securesms/MediaPreviewActivity.java index 158b4da6c6..d0f8d11da5 100644 --- a/src/org/thoughtcrime/securesms/MediaPreviewActivity.java +++ b/src/org/thoughtcrime/securesms/MediaPreviewActivity.java @@ -138,7 +138,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im mediaUri = getIntent().getData(); mediaType = getIntent().getType(); - date = getIntent().getLongExtra(DATE_EXTRA, -1); + date = getIntent().getLongExtra(DATE_EXTRA, System.currentTimeMillis()); if (recipientId > -1) { recipient = RecipientFactory.getRecipientForId(this, recipientId, true); diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java index f8f584fd00..a75ac3eb40 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -32,13 +32,13 @@ import android.util.Log; import android.view.View; import android.widget.Toast; +import org.thoughtcrime.securesms.MediaPreviewActivity; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.components.AudioView; import org.thoughtcrime.securesms.components.RemovableMediaView; import org.thoughtcrime.securesms.components.ThumbnailView; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.providers.PersistentBlobProvider; -import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture.Listener; @@ -76,6 +76,7 @@ public class AttachmentManager { this.attachmentListener = listener; removableMediaView.setRemoveClickListener(new RemoveButtonListener()); + thumbnail.setOnClickListener(new ThumbnailClickListener()); } public void clear() { @@ -274,6 +275,23 @@ public class AttachmentManager { constraints.canResize(slide.asAttachment()); } + private void previewImageDraft(final @NonNull Slide slide) { + if (MediaPreviewActivity.isContentTypeSupported(slide.getContentType()) && slide.getThumbnailUri() != null) { + Intent intent = new Intent(context, MediaPreviewActivity.class); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setDataAndType(slide.getUri(), slide.getContentType()); + + context.startActivity(intent); + } + } + + private class ThumbnailClickListener implements View.OnClickListener { + @Override + public void onClick(View v) { + if (slide.isPresent()) previewImageDraft(slide.get()); + } + } + private class RemoveButtonListener implements View.OnClickListener { @Override public void onClick(View v) {