From 1c92b17ecc58423928c3b53af649eec749556922 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 22 Jun 2021 15:55:32 +1000 Subject: [PATCH] Handle open group invitation weirdness & fix quote view sizing --- .../v2/messages/OpenGroupInvitationView.kt | 2 +- .../securesms/conversation/v2/messages/QuoteView.kt | 11 ++++++----- app/src/main/res/layout/view_control_message.xml | 7 ++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/OpenGroupInvitationView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/OpenGroupInvitationView.kt index 45ca31e646..330803a9e4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/OpenGroupInvitationView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/OpenGroupInvitationView.kt @@ -22,7 +22,7 @@ class OpenGroupInvitationView : LinearLayout { } fun bind(message: MessageRecord, @ColorInt textColor: Int) { - // FIXME: This is a really weird approach + // FIXME: This is a really weird approach... val umd = UpdateMessageData.fromJSON(message.body)!! val data = umd.kind as UpdateMessageData.Kind.OpenGroupInvitation val iconID = if (message.isOutgoing) R.drawable.ic_globe else R.drawable.ic_plus diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt index ea896c3580..7e4ad64d67 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt @@ -15,6 +15,7 @@ import androidx.core.view.marginStart import kotlinx.android.synthetic.main.view_quote.view.* import network.loki.messenger.R import org.session.libsession.messaging.contacts.Contact +import org.session.libsession.messaging.utilities.UpdateMessageData import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.conversation.v2.utilities.TextUtilities import org.thoughtcrime.securesms.database.DatabaseFactory @@ -29,7 +30,6 @@ import kotlin.math.roundToInt class QuoteView : LinearLayout { private lateinit var mode: Mode - private val screenWidth by lazy { Resources.getSystem().displayMetrics.widthPixels } private val vPadding by lazy { toPx(6, resources) } var delegate: QuoteViewDelegate? = null @@ -61,16 +61,16 @@ class QuoteView : LinearLayout { // region General fun getIntrinsicContentHeight(): Int { if (quoteViewAttachmentPreviewContainer.isVisible) { return toPx(40, resources) } + val maxContentWidth = quoteViewMainContentContainer.width var result = 0 - val width = screenWidth var authorTextViewIntrinsicHeight = 0 if (quoteViewAuthorTextView.isVisible) { val author = quoteViewAuthorTextView.text - authorTextViewIntrinsicHeight = TextUtilities.getIntrinsicHeight(author, quoteViewAuthorTextView.paint, width) + authorTextViewIntrinsicHeight = TextUtilities.getIntrinsicHeight(author, quoteViewAuthorTextView.paint, maxContentWidth) result += authorTextViewIntrinsicHeight } val body = quoteViewBodyTextView.text - val bodyTextViewIntrinsicHeight = TextUtilities.getIntrinsicHeight(body, quoteViewBodyTextView.paint, width) + val bodyTextViewIntrinsicHeight = TextUtilities.getIntrinsicHeight(body, quoteViewBodyTextView.paint, maxContentWidth) result += bodyTextViewIntrinsicHeight if (!quoteViewAuthorTextView.isVisible) { return min(max(result, toPx(32, resources)), toPx(54, resources)) @@ -96,7 +96,8 @@ class QuoteView : LinearLayout { } quoteViewAuthorTextView.isVisible = thread.isGroupRecipient // Body - quoteViewBodyTextView.text = body + val isOpenGroupInvitation = (body?.let { UpdateMessageData.fromJSON(it) } != null) + quoteViewBodyTextView.text = if (isOpenGroupInvitation) resources.getString(R.string.open_group_invitation_view__open_group_invitation) else body quoteViewBodyTextView.setTextColor(getTextColor(isOutgoingMessage)) // Accent line / attachment preview val hasAttachments = (attachments != null && attachments.asAttachments().isNotEmpty()) diff --git a/app/src/main/res/layout/view_control_message.xml b/app/src/main/res/layout/view_control_message.xml index e759969fff..714c7150ee 100644 --- a/app/src/main/res/layout/view_control_message.xml +++ b/app/src/main/res/layout/view_control_message.xml @@ -10,16 +10,17 @@ \ No newline at end of file