From 48df7337737de861f3b582e0fe1a25f1906d7014 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 21 Jun 2021 14:24:00 +1000 Subject: [PATCH] Basic quote view attachment handling --- .../conversation/v2/input_bar/InputBar.kt | 5 ++- .../v2/messages/LinkPreviewView.kt | 16 +++------ .../conversation/v2/messages/QuoteView.kt | 33 ++++++++++++++++--- ...ew_quote_attachment_preview_background.xml | 9 +++++ app/src/main/res/layout/view_quote.xml | 18 +++++++++- app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/drawable/view_quote_attachment_preview_background.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt index 9f0076da61..dc47e4ff6a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt @@ -13,8 +13,10 @@ import network.loki.messenger.R import org.thoughtcrime.securesms.conversation.v2.messages.QuoteView import org.thoughtcrime.securesms.conversation.v2.messages.QuoteViewDelegate import org.thoughtcrime.securesms.database.model.MessageRecord +import org.thoughtcrime.securesms.database.model.MmsMessageRecord import org.thoughtcrime.securesms.loki.utilities.toDp import org.thoughtcrime.securesms.loki.utilities.toPx +import org.thoughtcrime.securesms.mms.SlideDeck import kotlin.math.max class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate { @@ -88,7 +90,8 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate { val quoteView = QuoteView(context, QuoteView.Mode.Draft) quoteView.delegate = this inputBarAdditionalContentContainer.addView(quoteView) - quoteView.bind(message.individualRecipient.address.toString(), message.body, null, message.recipient, true) + val attachments = (message as? MmsMessageRecord)?.slideDeck + quoteView.bind(message.individualRecipient.address.toString(), message.body, attachments, message.recipient, true) val quoteViewIntrinsicHeight = quoteView.getIntrinsicHeight() val newHeight = max(inputBarEditText.height + 2 * vMargin, toPx(56, resources)) + quoteViewIntrinsicHeight additionalContentHeight = quoteViewIntrinsicHeight diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt index e9f951593b..17bd350d5a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt @@ -11,19 +11,11 @@ import org.thoughtcrime.securesms.database.model.MessageRecord class LinkPreviewView : LinearLayout { // region Lifecycle - constructor(context: Context) : super(context) { - setUpViewHierarchy() - } + constructor(context: Context) : super(context) { initialize() } + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() } + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() } - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { - setUpViewHierarchy() - } - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { - setUpViewHierarchy() - } - - private fun setUpViewHierarchy() { + private fun initialize() { LayoutInflater.from(context).inflate(R.layout.view_link_preview, this) } // endregion 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 c0353939c2..6e6601877c 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 @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.conversation.v2.messages import android.content.Context +import android.content.res.ColorStateList import android.content.res.Resources import android.util.AttributeSet import android.util.Log @@ -10,6 +11,7 @@ import android.widget.RelativeLayout import androidx.annotation.ColorInt import androidx.core.content.res.ResourcesCompat import androidx.core.view.isVisible +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 @@ -58,6 +60,7 @@ class QuoteView : LinearLayout { // region General fun getIntrinsicContentHeight(): Int { + if (quoteViewAttachmentPreviewContainer.isVisible) { return toPx(40, resources) } var result = 0 val width = screenWidth var authorTextViewIntrinsicHeight = 0 @@ -95,11 +98,31 @@ class QuoteView : LinearLayout { // Body quoteViewBodyTextView.text = body quoteViewBodyTextView.setTextColor(getTextColor(isOutgoingMessage)) - // Accent line - val accentLineLayoutParams = quoteViewAccentLine.layoutParams as RelativeLayout.LayoutParams - accentLineLayoutParams.height = getIntrinsicContentHeight() - quoteViewAccentLine.layoutParams = accentLineLayoutParams - quoteViewAccentLine.setBackgroundColor(getLineColor(isOutgoingMessage)) + // Accent line / attachment preview + val hasAttachments = (attachments != null && attachments.asAttachments().isNotEmpty()) + quoteViewAccentLine.isVisible = !hasAttachments + quoteViewAttachmentPreviewContainer.isVisible = hasAttachments + if (!hasAttachments) { + val accentLineLayoutParams = quoteViewAccentLine.layoutParams as RelativeLayout.LayoutParams + accentLineLayoutParams.height = getIntrinsicContentHeight() + quoteViewAccentLine.layoutParams = accentLineLayoutParams + quoteViewAccentLine.setBackgroundColor(getLineColor(isOutgoingMessage)) + } else { + attachments!! + quoteViewAttachmentPreviewImageView.imageTintList = ColorStateList.valueOf(ResourcesCompat.getColor(resources, R.color.white, context.theme)) + if (attachments.audioSlide != null) { + quoteViewAttachmentPreviewImageView.setImageResource(R.drawable.ic_microphone) + quoteViewBodyTextView.text = resources.getString(R.string.Slide_audio) + } else if (attachments.documentSlide != null) { + quoteViewAttachmentPreviewImageView.setImageResource(R.drawable.ic_document_large_light) + quoteViewBodyTextView.text = resources.getString(R.string.document) + } + // TODO: Link previews + // TODO: Images/video + } + val quoteViewMainContentContainerLayoutParams = quoteViewMainContentContainer.layoutParams as RelativeLayout.LayoutParams + quoteViewMainContentContainerLayoutParams.marginStart = if (!hasAttachments) toPx(16, resources) else toPx(48, resources) + quoteViewMainContentContainer.layoutParams = quoteViewMainContentContainerLayoutParams } // endregion diff --git a/app/src/main/res/drawable/view_quote_attachment_preview_background.xml b/app/src/main/res/drawable/view_quote_attachment_preview_background.xml new file mode 100644 index 0000000000..2044a98c1a --- /dev/null +++ b/app/src/main/res/drawable/view_quote_attachment_preview_background.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_quote.xml b/app/src/main/res/layout/view_quote.xml index 7adc8a652e..d5891afeb3 100644 --- a/app/src/main/res/layout/view_quote.xml +++ b/app/src/main/res/layout/view_quote.xml @@ -18,7 +18,23 @@ android:layout_centerVertical="true" android:background="@color/text" /> - + + + + + Enter a nickname Invalid public key + Document +