mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
Cleanup InputBar
This commit is contained in:
parent
38e73cf514
commit
4c395cb71e
@ -2,19 +2,16 @@ package org.thoughtcrime.securesms.conversation.v2.input_bar
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Resources
|
|
||||||
import android.graphics.PointF
|
import android.graphics.PointF
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
import android.text.TextWatcher
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.EditText
|
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
@ -31,11 +28,8 @@ 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.database.model.MmsMessageRecord
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
import org.thoughtcrime.securesms.util.SimpleTextWatcher
|
|
||||||
import org.thoughtcrime.securesms.util.addTextChangedListener
|
import org.thoughtcrime.securesms.util.addTextChangedListener
|
||||||
import org.thoughtcrime.securesms.util.contains
|
import org.thoughtcrime.securesms.util.contains
|
||||||
import org.thoughtcrime.securesms.util.toDp
|
|
||||||
import org.thoughtcrime.securesms.util.toPx
|
|
||||||
|
|
||||||
// Enums to keep track of the state of our voice recording mechanism as the user can
|
// Enums to keep track of the state of our voice recording mechanism as the user can
|
||||||
// manipulate the UI faster than we can setup & teardown.
|
// manipulate the UI faster than we can setup & teardown.
|
||||||
@ -46,16 +40,24 @@ enum class VoiceRecorderState {
|
|||||||
ShuttingDownAfterRecord
|
ShuttingDownAfterRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, LinkPreviewDraftViewDelegate,
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
class InputBar @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
defStyleAttr: Int = 0
|
||||||
|
) : RelativeLayout(
|
||||||
|
context,
|
||||||
|
attrs,
|
||||||
|
defStyleAttr
|
||||||
|
), InputBarEditTextDelegate,
|
||||||
|
QuoteViewDelegate,
|
||||||
|
LinkPreviewDraftViewDelegate,
|
||||||
TextView.OnEditorActionListener {
|
TextView.OnEditorActionListener {
|
||||||
private lateinit var binding: ViewInputBarBinding
|
|
||||||
private val screenWidth = Resources.getSystem().displayMetrics.widthPixels
|
private var binding: ViewInputBarBinding = ViewInputBarBinding.inflate(LayoutInflater.from(context), this, true)
|
||||||
private val vMargin by lazy { toDp(4, resources) }
|
|
||||||
private val minHeight by lazy { toPx(56, resources) }
|
|
||||||
private var linkPreviewDraftView: LinkPreviewDraftView? = null
|
private var linkPreviewDraftView: LinkPreviewDraftView? = null
|
||||||
private var quoteView: QuoteView? = null
|
private var quoteView: QuoteView? = null
|
||||||
var delegate: InputBarDelegate? = null
|
var delegate: InputBarDelegate? = null
|
||||||
var additionalContentHeight = 0
|
|
||||||
var quote: MessageRecord? = null
|
var quote: MessageRecord? = null
|
||||||
var linkPreview: LinkPreview? = null
|
var linkPreview: LinkPreview? = null
|
||||||
var showInput: Boolean = true
|
var showInput: Boolean = true
|
||||||
@ -68,7 +70,7 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li
|
|||||||
}
|
}
|
||||||
|
|
||||||
var text: String
|
var text: String
|
||||||
get() { return binding.inputBarEditText.text?.toString() ?: "" }
|
get() = binding.inputBarEditText.text?.toString() ?: ""
|
||||||
set(value) { binding.inputBarEditText.setText(value) }
|
set(value) { binding.inputBarEditText.setText(value) }
|
||||||
|
|
||||||
// Keep track of when the user pressed the record voice message button, the duration that
|
// Keep track of when the user pressed the record voice message button, the duration that
|
||||||
@ -77,21 +79,11 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li
|
|||||||
var voiceMessageDurationMS = 0L
|
var voiceMessageDurationMS = 0L
|
||||||
var voiceRecorderState = VoiceRecorderState.Idle
|
var voiceRecorderState = VoiceRecorderState.Idle
|
||||||
|
|
||||||
val attachmentButtonsContainerHeight: Int
|
private val attachmentsButton = InputBarButton(context, R.drawable.ic_plus_24).apply { contentDescription = context.getString(R.string.AccessibilityId_attachments_button)}
|
||||||
get() = binding.attachmentsButtonContainer.height
|
val microphoneButton = InputBarButton(context, R.drawable.ic_microphone).apply { contentDescription = context.getString(R.string.AccessibilityId_microphone_button)}
|
||||||
|
private val sendButton = InputBarButton(context, R.drawable.ic_arrow_up, true).apply { contentDescription = context.getString(R.string.AccessibilityId_send_message_button)}
|
||||||
|
|
||||||
private val attachmentsButton by lazy { InputBarButton(context, R.drawable.ic_plus_24).apply { contentDescription = context.getString(R.string.AccessibilityId_attachments_button)} }
|
init {
|
||||||
private val microphoneButton by lazy { InputBarButton(context, R.drawable.ic_microphone).apply { contentDescription = context.getString(R.string.AccessibilityId_microphone_button)} }
|
|
||||||
private val sendButton by lazy { InputBarButton(context, R.drawable.ic_arrow_up, true).apply { contentDescription = context.getString(R.string.AccessibilityId_send_message_button)} }
|
|
||||||
|
|
||||||
// region Lifecycle
|
|
||||||
constructor(context: Context) : super(context) { initialize() }
|
|
||||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() }
|
|
||||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
|
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
|
||||||
private fun initialize() {
|
|
||||||
binding = ViewInputBarBinding.inflate(LayoutInflater.from(context), this, true)
|
|
||||||
// Attachments button
|
// Attachments button
|
||||||
binding.attachmentsButtonContainer.addView(attachmentsButton)
|
binding.attachmentsButtonContainer.addView(attachmentsButton)
|
||||||
attachmentsButton.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
|
attachmentsButton.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
|
||||||
@ -160,12 +152,11 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li
|
|||||||
binding.inputBarEditText.setOnEditorActionListener(this)
|
binding.inputBarEditText.setOnEditorActionListener(this)
|
||||||
if (TextSecurePreferences.isEnterSendsEnabled(context)) {
|
if (TextSecurePreferences.isEnterSendsEnabled(context)) {
|
||||||
binding.inputBarEditText.imeOptions = EditorInfo.IME_ACTION_SEND
|
binding.inputBarEditText.imeOptions = EditorInfo.IME_ACTION_SEND
|
||||||
binding.inputBarEditText.inputType =
|
binding.inputBarEditText.inputType = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
|
||||||
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
|
|
||||||
} else {
|
} else {
|
||||||
binding.inputBarEditText.imeOptions = EditorInfo.IME_ACTION_NONE
|
binding.inputBarEditText.imeOptions = EditorInfo.IME_ACTION_NONE
|
||||||
binding.inputBarEditText.inputType =
|
binding.inputBarEditText.inputType =
|
||||||
binding.inputBarEditText.inputType or
|
binding.inputBarEditText.inputType
|
||||||
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
|
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
|
||||||
}
|
}
|
||||||
val incognitoFlag = if (TextSecurePreferences.isIncognitoKeyboardEnabled(context)) 16777216 else 0
|
val incognitoFlag = if (TextSecurePreferences.isIncognitoKeyboardEnabled(context)) 16777216 else 0
|
||||||
@ -182,9 +173,6 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
|
||||||
|
|
||||||
// region Updating
|
|
||||||
override fun inputBarEditTextContentChanged(text: CharSequence) {
|
override fun inputBarEditTextContentChanged(text: CharSequence) {
|
||||||
microphoneButton.isVisible = text.trim().isEmpty()
|
microphoneButton.isVisible = text.trim().isEmpty()
|
||||||
sendButton.isVisible = microphoneButton.isGone
|
sendButton.isVisible = microphoneButton.isGone
|
||||||
@ -286,12 +274,9 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li
|
|||||||
fun setInputBarEditableFactory(factory: Editable.Factory) {
|
fun setInputBarEditableFactory(factory: Editable.Factory) {
|
||||||
binding.inputBarEditText.setEditableFactory(factory)
|
binding.inputBarEditText.setEditableFactory(factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InputBarDelegate {
|
interface InputBarDelegate {
|
||||||
|
|
||||||
fun inputBarEditTextContentChanged(newContent: CharSequence)
|
fun inputBarEditTextContentChanged(newContent: CharSequence)
|
||||||
fun toggleAttachmentOptions()
|
fun toggleAttachmentOptions()
|
||||||
fun showVoiceMessageUI()
|
fun showVoiceMessageUI()
|
||||||
@ -301,4 +286,4 @@ interface InputBarDelegate {
|
|||||||
fun onMicrophoneButtonUp(event: MotionEvent)
|
fun onMicrophoneButtonUp(event: MotionEvent)
|
||||||
fun sendMessage()
|
fun sendMessage()
|
||||||
fun commitInputContent(contentUri: Uri)
|
fun commitInputContent(contentUri: Uri)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user