mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-03 20:08:21 +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.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.RelativeLayout
|
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 kotlinx.android.synthetic.main.view_input_bar.view.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.thoughtcrime.securesms.loki.utilities.toDp
|
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 {
|
class InputBar : LinearLayout, InputBarEditTextDelegate {
|
||||||
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) }
|
||||||
private val microphoneButton by lazy { InputBarButton(context, R.drawable.ic_microphone) }
|
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
|
// region Lifecycle
|
||||||
constructor(context: Context) : super(context) {
|
constructor(context: Context) : super(context) {
|
||||||
@ -36,18 +37,28 @@ class InputBar : LinearLayout, InputBarEditTextDelegate {
|
|||||||
attachmentsButtonContainer.addView(attachmentsButton)
|
attachmentsButtonContainer.addView(attachmentsButton)
|
||||||
attachmentsButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
|
attachmentsButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
|
||||||
attachmentsButton.setOnClickListener { }
|
attachmentsButton.setOnClickListener { }
|
||||||
microphoneButtonContainer.addView(microphoneButton)
|
microphoneOrSendButtonContainer.addView(microphoneButton)
|
||||||
microphoneButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
|
microphoneButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
|
||||||
microphoneButton.setOnClickListener { }
|
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.imeOptions = inputBarEditText.imeOptions or 16777216 // Always use incognito keyboard
|
||||||
inputBarEditText.delegate = this
|
inputBarEditText.delegate = this
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
// region Updating
|
||||||
|
override fun inputBarEditTextContentChanged(text: CharSequence) {
|
||||||
|
sendButton.isVisible = text.isNotEmpty()
|
||||||
|
microphoneButton.isVisible = text.isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
override fun inputBarEditTextHeightChanged(newValue: Int) {
|
override fun inputBarEditTextHeightChanged(newValue: Int) {
|
||||||
val vMargin = toDp(4, resources)
|
val vMargin = toDp(4, resources)
|
||||||
val layoutParams = inputBarLinearLayout.layoutParams as LayoutParams
|
val layoutParams = inputBarLinearLayout.layoutParams as LayoutParams
|
||||||
val newHeight = newValue + 2 * vMargin
|
val newHeight = max(newValue + 2 * vMargin, toPx(56, resources))
|
||||||
layoutParams.height = newHeight
|
layoutParams.height = newHeight
|
||||||
inputBarLinearLayout.layoutParams = layoutParams
|
inputBarLinearLayout.layoutParams = layoutParams
|
||||||
delegate?.inputBarHeightChanged(newHeight)
|
delegate?.inputBarHeightChanged(newHeight)
|
||||||
|
@ -19,6 +19,7 @@ import org.thoughtcrime.securesms.loki.views.GlowViewUtilities
|
|||||||
import org.thoughtcrime.securesms.loki.views.InputBarButtonImageViewContainer
|
import org.thoughtcrime.securesms.loki.views.InputBarButtonImageViewContainer
|
||||||
|
|
||||||
class InputBarButton : RelativeLayout {
|
class InputBarButton : RelativeLayout {
|
||||||
|
private var isSendButton = false
|
||||||
@DrawableRes private var iconID = 0
|
@DrawableRes private var iconID = 0
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -27,6 +28,7 @@ class InputBarButton : RelativeLayout {
|
|||||||
|
|
||||||
private val expandedImageViewPosition by lazy { PointF(0.0f, 0.0f) }
|
private val expandedImageViewPosition by lazy { PointF(0.0f, 0.0f) }
|
||||||
private val collapsedImageViewPosition by lazy { PointF((expandedSize - collapsedSize) / 2, (expandedSize - collapsedSize) / 2) }
|
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 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) }
|
val collapsedSize by lazy { resources.getDimension(R.dimen.input_bar_button_collapsed_size) }
|
||||||
@ -36,7 +38,7 @@ class InputBarButton : RelativeLayout {
|
|||||||
val size = collapsedSize.toInt()
|
val size = collapsedSize.toInt()
|
||||||
result.layoutParams = LayoutParams(size, size)
|
result.layoutParams = LayoutParams(size, size)
|
||||||
result.setBackgroundResource(R.drawable.input_bar_button_background)
|
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
|
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) : 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, 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
|
this.iconID = iconID
|
||||||
val size = resources.getDimension(R.dimen.input_bar_button_expanded_size).toInt()
|
val size = resources.getDimension(R.dimen.input_bar_button_expanded_size).toInt()
|
||||||
val layoutParams = LayoutParams(size, size)
|
val layoutParams = LayoutParams(size, size)
|
||||||
@ -71,13 +74,13 @@ class InputBarButton : RelativeLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun expand() {
|
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)
|
imageViewContainer.animateSizeChange(R.dimen.input_bar_button_collapsed_size, R.dimen.input_bar_button_expanded_size, animationDuration)
|
||||||
animateImageViewContainerPositionChange(collapsedImageViewPosition, expandedImageViewPosition)
|
animateImageViewContainerPositionChange(collapsedImageViewPosition, expandedImageViewPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun collapse() {
|
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)
|
imageViewContainer.animateSizeChange(R.dimen.input_bar_button_expanded_size, R.dimen.input_bar_button_collapsed_size, animationDuration)
|
||||||
animateImageViewContainerPositionChange(expandedImageViewPosition, collapsedImageViewPosition)
|
animateImageViewContainerPositionChange(expandedImageViewPosition, collapsedImageViewPosition)
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ class InputBarEditText : AppCompatEditText {
|
|||||||
|
|
||||||
override fun onTextChanged(text: CharSequence, start: Int, lengthBefore: Int, lengthAfter: Int) {
|
override fun onTextChanged(text: CharSequence, start: Int, lengthBefore: Int, lengthAfter: Int) {
|
||||||
super.onTextChanged(text, start, lengthBefore, lengthAfter)
|
super.onTextChanged(text, start, lengthBefore, lengthAfter)
|
||||||
|
delegate?.inputBarEditTextContentChanged(text)
|
||||||
val builder = StaticLayout.Builder.obtain(text, 0, text.length, paint, width)
|
val builder = StaticLayout.Builder.obtain(text, 0, text.length, paint, width)
|
||||||
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
|
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
|
||||||
.setLineSpacing(0.0f, 1.0f)
|
.setLineSpacing(0.0f, 1.0f)
|
||||||
@ -40,5 +41,6 @@ class InputBarEditText : AppCompatEditText {
|
|||||||
|
|
||||||
interface InputBarEditTextDelegate {
|
interface InputBarEditTextDelegate {
|
||||||
|
|
||||||
|
fun inputBarEditTextContentChanged(text: CharSequence)
|
||||||
fun inputBarEditTextHeightChanged(newValue: Int)
|
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" />
|
android:hint="@string/ConversationActivity_message" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/microphoneButtonContainer"
|
android:id="@+id/microphoneOrSendButtonContainer"
|
||||||
android:layout_width="@dimen/input_bar_button_expanded_size"
|
android:layout_width="@dimen/input_bar_button_expanded_size"
|
||||||
android:layout_height="@dimen/input_bar_button_expanded_size"
|
android:layout_height="@dimen/input_bar_button_expanded_size"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user