mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 10:03:39 +00:00
Add send button
This commit is contained in:
parent
2188200717
commit
eac0a87e40
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
15
app/src/main/res/drawable/ic_arrow_up.xml
Normal file
15
app/src/main/res/drawable/ic_arrow_up.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="32dp"
|
||||
android:height="32dp"
|
||||
android:viewportWidth="32"
|
||||
android:viewportHeight="32">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M14.5,26.5C14.5,27.3284 15.1716,28 16,28C16.8284,28 17.5,27.3284 17.5,26.5L14.5,26.5ZM17.5,5.5C17.5,4.6716 16.8284,4 16,4C15.1716,4 14.5,4.6716 14.5,5.5L17.5,5.5ZM17.5,26.5L17.5,5.5L14.5,5.5L14.5,26.5L17.5,26.5Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M5.9393,13.4393C5.3536,14.0251 5.3536,14.9749 5.9393,15.5607C6.5251,16.1464 7.4749,16.1464 8.0607,15.5607L5.9393,13.4393ZM17.0607,6.5607C17.6464,5.9749 17.6464,5.0251 17.0607,4.4393C16.4749,3.8536 15.5251,3.8536 14.9393,4.4393L17.0607,6.5607ZM8.0607,15.5607L17.0607,6.5607L14.9393,4.4393L5.9393,13.4393L8.0607,15.5607Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M17.0607,4.4393C16.4749,3.8536 15.5251,3.8536 14.9393,4.4393C14.3536,5.0251 14.3536,5.9749 14.9393,6.5607L17.0607,4.4393ZM23.9393,15.5607C24.5251,16.1464 25.4749,16.1464 26.0607,15.5607C26.6464,14.9749 26.6464,14.0251 26.0607,13.4393L23.9393,15.5607ZM14.9393,6.5607L23.9393,15.5607L26.0607,13.4393L17.0607,4.4393L14.9393,6.5607Z"/>
|
||||
</vector>
|
@ -38,7 +38,7 @@
|
||||
android:hint="@string/ConversationActivity_message" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/microphoneButtonContainer"
|
||||
android:id="@+id/microphoneOrSendButtonContainer"
|
||||
android:layout_width="@dimen/input_bar_button_expanded_size"
|
||||
android:layout_height="@dimen/input_bar_button_expanded_size"
|
||||
android:layout_alignParentEnd="true"
|
||||
|
Loading…
x
Reference in New Issue
Block a user