Add send button

This commit is contained in:
Niels Andriesse
2021-06-16 10:39:24 +10:00
parent 2188200717
commit eac0a87e40
5 changed files with 41 additions and 10 deletions

View File

@@ -2,21 +2,22 @@ package org.thoughtcrime.securesms.conversation.v2.input_bar
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.RelativeLayout
import kotlinx.android.synthetic.main.activity_conversation_v2.*
import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.view_input_bar.view.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.loki.utilities.toDp
import kotlin.math.roundToInt
import org.thoughtcrime.securesms.loki.utilities.toPx
import kotlin.math.max
class InputBar : LinearLayout, InputBarEditTextDelegate {
var delegate: InputBarDelegate? = null
private val attachmentsButton by lazy { InputBarButton(context, R.drawable.ic_plus_24) }
private val microphoneButton by lazy { InputBarButton(context, R.drawable.ic_microphone) }
private val sendButton by lazy { InputBarButton(context, R.drawable.ic_arrow_up, true) }
// region Lifecycle
constructor(context: Context) : super(context) {
@@ -36,18 +37,28 @@ class InputBar : LinearLayout, InputBarEditTextDelegate {
attachmentsButtonContainer.addView(attachmentsButton)
attachmentsButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
attachmentsButton.setOnClickListener { }
microphoneButtonContainer.addView(microphoneButton)
microphoneOrSendButtonContainer.addView(microphoneButton)
microphoneButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
microphoneButton.setOnClickListener { }
microphoneOrSendButtonContainer.addView(sendButton)
sendButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
sendButton.setOnClickListener { }
sendButton.isVisible = false
inputBarEditText.imeOptions = inputBarEditText.imeOptions or 16777216 // Always use incognito keyboard
inputBarEditText.delegate = this
}
// endregion
// region Updating
override fun inputBarEditTextContentChanged(text: CharSequence) {
sendButton.isVisible = text.isNotEmpty()
microphoneButton.isVisible = text.isEmpty()
}
override fun inputBarEditTextHeightChanged(newValue: Int) {
val vMargin = toDp(4, resources)
val layoutParams = inputBarLinearLayout.layoutParams as LayoutParams
val newHeight = newValue + 2 * vMargin
val newHeight = max(newValue + 2 * vMargin, toPx(56, resources))
layoutParams.height = newHeight
inputBarLinearLayout.layoutParams = layoutParams
delegate?.inputBarHeightChanged(newHeight)

View File

@@ -19,6 +19,7 @@ import org.thoughtcrime.securesms.loki.views.GlowViewUtilities
import org.thoughtcrime.securesms.loki.views.InputBarButtonImageViewContainer
class InputBarButton : RelativeLayout {
private var isSendButton = false
@DrawableRes private var iconID = 0
companion object {
@@ -27,6 +28,7 @@ class InputBarButton : RelativeLayout {
private val expandedImageViewPosition by lazy { PointF(0.0f, 0.0f) }
private val collapsedImageViewPosition by lazy { PointF((expandedSize - collapsedSize) / 2, (expandedSize - collapsedSize) / 2) }
private val defaultColorID by lazy { if (isSendButton) R.color.accent else R.color.input_bar_button_background }
val expandedSize by lazy { resources.getDimension(R.dimen.input_bar_button_expanded_size) }
val collapsedSize by lazy { resources.getDimension(R.dimen.input_bar_button_collapsed_size) }
@@ -36,7 +38,7 @@ class InputBarButton : RelativeLayout {
val size = collapsedSize.toInt()
result.layoutParams = LayoutParams(size, size)
result.setBackgroundResource(R.drawable.input_bar_button_background)
result.mainColor = resources.getColorWithID(R.color.input_bar_button_background, context.theme)
result.mainColor = resources.getColorWithID(defaultColorID, context.theme)
result
}
@@ -54,7 +56,8 @@ class InputBarButton : RelativeLayout {
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { throw IllegalAccessException("Use InputBarButton(context:iconID:) instead.") }
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { throw IllegalAccessException("Use InputBarButton(context:iconID:) instead.") }
constructor(context: Context, @DrawableRes iconID: Int) : super(context) {
constructor(context: Context, @DrawableRes iconID: Int, isSendButton: Boolean = false) : super(context) {
this.isSendButton = isSendButton
this.iconID = iconID
val size = resources.getDimension(R.dimen.input_bar_button_expanded_size).toInt()
val layoutParams = LayoutParams(size, size)
@@ -71,13 +74,13 @@ class InputBarButton : RelativeLayout {
}
fun expand() {
GlowViewUtilities.animateColorChange(context, imageViewContainer, R.color.input_bar_button_background, R.color.accent)
GlowViewUtilities.animateColorChange(context, imageViewContainer, defaultColorID, R.color.accent)
imageViewContainer.animateSizeChange(R.dimen.input_bar_button_collapsed_size, R.dimen.input_bar_button_expanded_size, animationDuration)
animateImageViewContainerPositionChange(collapsedImageViewPosition, expandedImageViewPosition)
}
fun collapse() {
GlowViewUtilities.animateColorChange(context, imageViewContainer, R.color.accent, R.color.input_bar_button_background)
GlowViewUtilities.animateColorChange(context, imageViewContainer, R.color.accent, defaultColorID)
imageViewContainer.animateSizeChange(R.dimen.input_bar_button_expanded_size, R.dimen.input_bar_button_collapsed_size, animationDuration)
animateImageViewContainerPositionChange(expandedImageViewPosition, collapsedImageViewPosition)
}

View File

@@ -23,6 +23,7 @@ class InputBarEditText : AppCompatEditText {
override fun onTextChanged(text: CharSequence, start: Int, lengthBefore: Int, lengthAfter: Int) {
super.onTextChanged(text, start, lengthBefore, lengthAfter)
delegate?.inputBarEditTextContentChanged(text)
val builder = StaticLayout.Builder.obtain(text, 0, text.length, paint, width)
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
.setLineSpacing(0.0f, 1.0f)
@@ -40,5 +41,6 @@ class InputBarEditText : AppCompatEditText {
interface InputBarEditTextDelegate {
fun inputBarEditTextContentChanged(text: CharSequence)
fun inputBarEditTextHeightChanged(newValue: Int)
}