Fix height change handling

This commit is contained in:
Niels Andriesse 2021-06-18 16:04:22 +10:00
parent 123cd6d486
commit 9471db76c2
3 changed files with 20 additions and 4 deletions

View File

@ -10,12 +10,14 @@ import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.view_input_bar.view.* import kotlinx.android.synthetic.main.view_input_bar.view.*
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.conversation.v2.messages.QuoteView 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.MessageRecord
import org.thoughtcrime.securesms.loki.utilities.toDp import org.thoughtcrime.securesms.loki.utilities.toDp
import org.thoughtcrime.securesms.loki.utilities.toPx import org.thoughtcrime.securesms.loki.utilities.toPx
import kotlin.math.max 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 var delegate: InputBarDelegate? = null
private val attachmentsButton by lazy { InputBarButton(context, R.drawable.ic_plus_24) } 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) { override fun inputBarEditTextHeightChanged(newValue: Int) {
val vMargin = toDp(4, resources) val newHeight = max(newValue + 2 * vMargin, toPx(56, resources)) + inputBarAdditionalContentContainer.height
val newHeight = max(newValue + 2 * vMargin + inputBarAdditionalContentContainer.height, toPx(56, resources))
setHeight(newHeight) setHeight(newHeight)
} }
@ -83,9 +84,16 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate {
fun draftQuote(message: MessageRecord) { fun draftQuote(message: MessageRecord) {
inputBarAdditionalContentContainer.removeAllViews() inputBarAdditionalContentContainer.removeAllViews()
val quoteView = QuoteView(context) val quoteView = QuoteView(context)
quoteView.delegate = this
inputBarAdditionalContentContainer.addView(quoteView) inputBarAdditionalContentContainer.addView(quoteView)
quoteView.bind(message.individualRecipient.address.toString(), message.body, null, message.recipient) 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) setHeight(newHeight)
} }
// endregion // endregion

View File

@ -22,6 +22,7 @@ import kotlin.math.min
class QuoteView : LinearLayout { class QuoteView : LinearLayout {
private val screenWidth by lazy { Resources.getSystem().displayMetrics.widthPixels } private val screenWidth by lazy { Resources.getSystem().displayMetrics.widthPixels }
private val vPadding by lazy { toPx(6, resources) } private val vPadding by lazy { toPx(6, resources) }
var delegate: QuoteViewDelegate? = null
enum class Mode { Regular, Draft } enum class Mode { Regular, Draft }
@ -32,6 +33,7 @@ class QuoteView : LinearLayout {
private fun initialize() { private fun initialize() {
LayoutInflater.from(context).inflate(R.layout.view_quote, this) LayoutInflater.from(context).inflate(R.layout.view_quote, this)
quoteViewCancelButton.setOnClickListener { delegate?.cancelQuoteDraft() }
} }
// endregion // endregion
@ -76,3 +78,8 @@ class QuoteView : LinearLayout {
} }
// endregion // endregion
} }
interface QuoteViewDelegate {
fun cancelQuoteDraft()
}

View File

@ -52,6 +52,7 @@
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/quoteViewCancelButton"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="32dp" android:layout_height="32dp"
android:padding="6dp" android:padding="6dp"