From e5b19d4ea4e6e1c52076ac8f46c3259c21626a9f Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 6 Jul 2023 19:05:09 +0930 Subject: [PATCH] Fix incorrect recipient used as threadRecipient to launch MediaPreview --- .../securesms/MediaPreviewActivity.java | 1 - .../conversation/v2/MessageDetailActivity.kt | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java index 6544c2ab89..a1648e0763 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java @@ -531,7 +531,6 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im @Override public void onLoadFinished(@NonNull Loader> loader, @Nullable Pair data) { if (data != null) { - @SuppressWarnings("ConstantConditions") CursorPagerAdapter adapter = new CursorPagerAdapter(this, GlideApp.with(this), getWindow(), data.first, data.second, leftIsRecent); mediaPager.setAdapter(adapter); adapter.setActive(true); diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt index 07230eadee..d8f8a9d7f9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt @@ -7,7 +7,6 @@ import android.view.LayoutInflater import android.view.MotionEvent.ACTION_UP import androidx.activity.viewModels import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -32,7 +31,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.res.painterResource @@ -52,6 +50,8 @@ import network.loki.messenger.R import network.loki.messenger.databinding.ViewVisibleMessageContentBinding import org.session.libsession.messaging.jobs.AttachmentDownloadJob import org.session.libsession.messaging.jobs.JobQueue +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentTransferProgress +import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment import org.thoughtcrime.securesms.MediaPreviewActivity import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.database.Storage @@ -124,13 +124,19 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { onResend = { setResultAndFinish(ON_RESEND) }, onDelete = { setResultAndFinish(ON_DELETE) }, onClickImage = { slide -> - MediaPreviewActivity.getPreviewIntent( + // only open to downloaded images + if (slide.transferState == AttachmentTransferProgress.TRANSFER_PROGRESS_FAILED) { + // Restart download here (on IO thread) + (slide.asAttachment() as? DatabaseAttachment)?.let { attachment -> + onAttachmentNeedsDownload(attachment.attachmentId.rowId, details.mmsRecord!!.getId()) + } + } + if (!slide.isInProgress) MediaPreviewActivity.getPreviewIntent( this, slide, details.mmsRecord, - details.sender - ) - .let(::startActivity) + DatabaseComponent.get(this).threadDatabase().getRecipientForThreadId(details.mmsRecord!!.threadId), + ).let(::startActivity) } ) } @@ -184,7 +190,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { ViewVisibleMessageContentBinding.inflate(LayoutInflater.from(it)).mainContainerConstraint.apply { bind( message, - thread = message.individualRecipient, + thread = DatabaseComponent.get(this@MessageDetailActivity).threadDatabase().getRecipientForThreadId(message.threadId)!!, onAttachmentNeedsDownload = ::onAttachmentNeedsDownload, suppressThumbnails = true ) @@ -286,10 +292,9 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { HorizontalPagerIndicator(pagerState) ExpandButton( modifier = Modifier - .clickable { onClick(imageAttachments[pagerState.currentPage].slide) } .align(Alignment.BottomEnd) .padding(8.dp) - ) + ) { onClick(imageAttachments[pagerState.currentPage].slide) } } CarouselNextButton(pagerState) } @@ -323,7 +328,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { } @Composable - fun ExpandButton(modifier: Modifier) { + fun ExpandButton(modifier: Modifier, onClick: () -> Unit) { Surface( shape = CircleShape, color = blackAlpha40, @@ -331,7 +336,8 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { ) { Icon( painter = painterResource(id = R.drawable.ic_expand), - contentDescription = "" + contentDescription = "", + modifier = Modifier.clickable { onClick() } ) } }