From 9471db76c23569d610154e92079fd821f6f0b6ae Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 18 Jun 2021 16:04:22 +1000 Subject: [PATCH] Fix height change handling --- .../conversation/v2/input_bar/InputBar.kt | 16 ++++++++++++---- .../conversation/v2/messages/QuoteView.kt | 7 +++++++ app/src/main/res/layout/view_quote.xml | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) 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 cd76e4ce5e..79e116f6b1 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 @@ -10,12 +10,14 @@ import androidx.core.view.isVisible import kotlinx.android.synthetic.main.view_input_bar.view.* 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.loki.utilities.toDp import org.thoughtcrime.securesms.loki.utilities.toPx import kotlin.math.max -class InputBar : RelativeLayout, InputBarEditTextDelegate { +class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate { + private val vMargin by lazy { toDp(4, resources) } var delegate: InputBarDelegate? = null private val attachmentsButton by lazy { InputBarButton(context, R.drawable.ic_plus_24) } @@ -67,8 +69,7 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate { } override fun inputBarEditTextHeightChanged(newValue: Int) { - val vMargin = toDp(4, resources) - val newHeight = max(newValue + 2 * vMargin + inputBarAdditionalContentContainer.height, toPx(56, resources)) + val newHeight = max(newValue + 2 * vMargin, toPx(56, resources)) + inputBarAdditionalContentContainer.height setHeight(newHeight) } @@ -83,9 +84,16 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate { fun draftQuote(message: MessageRecord) { inputBarAdditionalContentContainer.removeAllViews() val quoteView = QuoteView(context) + quoteView.delegate = this inputBarAdditionalContentContainer.addView(quoteView) quoteView.bind(message.individualRecipient.address.toString(), message.body, null, message.recipient) - val newHeight = height + quoteView.getIntrinsicHeight() + val newHeight = max(inputBarEditText.height + 2 * vMargin, toPx(56, resources)) + quoteView.getIntrinsicHeight() + setHeight(newHeight) + } + + override fun cancelQuoteDraft() { + inputBarAdditionalContentContainer.removeAllViews() + val newHeight = max(inputBarEditText.height + 2 * vMargin, toPx(56, resources)) setHeight(newHeight) } // 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 4c11cf6826..35c1ead059 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 @@ -22,6 +22,7 @@ import kotlin.math.min class QuoteView : LinearLayout { private val screenWidth by lazy { Resources.getSystem().displayMetrics.widthPixels } private val vPadding by lazy { toPx(6, resources) } + var delegate: QuoteViewDelegate? = null enum class Mode { Regular, Draft } @@ -32,6 +33,7 @@ class QuoteView : LinearLayout { private fun initialize() { LayoutInflater.from(context).inflate(R.layout.view_quote, this) + quoteViewCancelButton.setOnClickListener { delegate?.cancelQuoteDraft() } } // endregion @@ -75,4 +77,9 @@ class QuoteView : LinearLayout { quoteViewAccentLine.layoutParams = accentLineLayoutParams } // endregion +} + +interface QuoteViewDelegate { + + fun cancelQuoteDraft() } \ 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 49673ec0d0..9f173e0755 100644 --- a/app/src/main/res/layout/view_quote.xml +++ b/app/src/main/res/layout/view_quote.xml @@ -52,6 +52,7 @@