From 7cd2bd0e0d8c1ca4cf98e82d2f40239fd1b45d35 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 4 Jul 2023 15:11:40 +0930 Subject: [PATCH] Cleanup --- .../components/ProfilePictureView.kt | 4 + .../conversation/v2/MessageDetailActivity.kt | 76 +++++++++++-------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt b/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt index 37a3e764e8..4ee4777c62 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt @@ -43,6 +43,10 @@ class ProfilePictureView @JvmOverloads constructor( // endregion + constructor(context: Context, sender: Recipient): this(context) { + update(sender) + } + // region Updating fun update(recipient: Recipient) { fun getUserDisplayName(publicKey: String): String { 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 8d59dea734..b8abb7152a 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 @@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding @@ -266,38 +267,17 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { fun MetaDataCell( messageDetails: MessageDetails, ) { - if (messageDetails.sent != null || messageDetails.received != null || messageDetails.senderInfo != null) CellWithPaddingAndMargin { - Column(verticalArrangement = Arrangement.spacedBy(16.dp)) { - messageDetails.sent?.let { TitledText(it) } - messageDetails.received?.let { TitledText(it) } - messageDetails.error?.let { - TitledText( - it, - valueStyle = LocalTextStyle.current.copy(color = colorDestructive) - ) - } - messageDetails.senderInfo?.let { - TitledView("From:") { - Row { - messageDetails.sender?.let { sender -> - Box( - modifier = Modifier - .width(60.dp) - .align(Alignment.CenterVertically) - ) { - AndroidView( - factory = { - ProfilePictureView(it).apply { update(sender) } - }, - modifier = Modifier.width(46.dp).height(46.dp) - ) - } - } - Column { - TitledText( - it, - valueStyle = LocalTextStyle.current.copy(fontFamily = FontFamily.Monospace) - ) + messageDetails.apply { + if (sent != null || received != null || senderInfo != null) CellWithPaddingAndMargin { + Column(verticalArrangement = Arrangement.spacedBy(16.dp)) { + sent?.let { TitledText(it) } + received?.let { TitledText(it) } + error?.let { TitledErrorText(it) } + senderInfo?.let { + TitledView("From:") { + Row { + sender?.let { Avatar(it) } + TitledMonospaceText(it) } } } @@ -306,6 +286,22 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { } } + @Composable + fun RowScope.Avatar(sender: Recipient) { + Box( + modifier = Modifier + .width(60.dp) + .align(Alignment.CenterVertically) + ) { + AndroidView( + factory = { + ProfilePictureView(it).apply { update(sender) } + }, + modifier = Modifier.width(46.dp).height(46.dp) + ) + } + } + @Composable fun Buttons( hasError: Boolean, @@ -417,6 +413,22 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { } } + @Composable + fun TitledErrorText(titledText: TitledText, modifier: Modifier = Modifier) { + TitledText( + titledText, + modifier = modifier, + valueStyle = LocalTextStyle.current.copy(color = colorDestructive)) + } + + @Composable + fun TitledMonospaceText(titledText: TitledText, modifier: Modifier = Modifier) { + TitledText( + titledText, + modifier = modifier, + valueStyle = LocalTextStyle.current.copy(fontFamily = FontFamily.Monospace)) + } + @Composable fun TitledText( titledText: TitledText,