Merge pull request #3918 from nextcloud/bugfix/3897/fixTextOverwrittenByClipboard

Fix to not set clipboard text repeatedly
This commit is contained in:
Julius Linus 2024-05-17 09:36:06 -05:00 committed by GitHub
commit b2fe29d0cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1156,92 +1156,94 @@ class ChatActivity :
} }
private fun initMessageInputView() { private fun initMessageInputView() {
val filters = arrayOfNulls<InputFilter>(1) if (binding.messageInputView.inputEditText?.filters?.isEmpty() == true) {
val lengthFilter = CapabilitiesUtil.getMessageMaxLength(spreedCapabilities) val filters = arrayOfNulls<InputFilter>(1)
val lengthFilter = CapabilitiesUtil.getMessageMaxLength(spreedCapabilities)
filters[0] = InputFilter.LengthFilter(lengthFilter) filters[0] = InputFilter.LengthFilter(lengthFilter)
binding.messageInputView.inputEditText?.filters = filters binding.messageInputView.inputEditText?.filters = filters
binding.messageInputView.inputEditText?.addTextChangedListener(object : TextWatcher { binding.messageInputView.inputEditText?.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
// unused atm // unused atm
}
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
updateOwnTypingStatus(s)
if (s.length >= lengthFilter) {
binding.messageInputView.inputEditText?.error = String.format(
Objects.requireNonNull<Resources>(resources).getString(R.string.nc_limit_hit),
lengthFilter.toString()
)
} else {
binding.messageInputView.inputEditText?.error = null
} }
val editable = binding.messageInputView.inputEditText?.editableText @Suppress("Detekt.TooGenericExceptionCaught")
editedTextBehaviorSubject.onNext(editable.toString().trim()) override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
updateOwnTypingStatus(s)
if (editable != null && binding.messageInputView.inputEditText != null) { if (s.length >= lengthFilter) {
val mentionSpans = editable.getSpans( binding.messageInputView.inputEditText?.error = String.format(
0, Objects.requireNonNull<Resources>(resources).getString(R.string.nc_limit_hit),
binding.messageInputView.inputEditText!!.length(), lengthFilter.toString()
Spans.MentionChipSpan::class.java )
) } else {
var mentionSpan: Spans.MentionChipSpan binding.messageInputView.inputEditText?.error = null
for (i in mentionSpans.indices) { }
mentionSpan = mentionSpans[i]
if (start >= editable.getSpanStart(mentionSpan) && val editable = binding.messageInputView.inputEditText?.editableText
start < editable.getSpanEnd(mentionSpan) editedTextBehaviorSubject.onNext(editable.toString().trim())
) {
if (editable.subSequence( if (editable != null && binding.messageInputView.inputEditText != null) {
editable.getSpanStart(mentionSpan), val mentionSpans = editable.getSpans(
editable.getSpanEnd(mentionSpan) 0,
).toString().trim { it <= ' ' } != mentionSpan.label binding.messageInputView.inputEditText!!.length(),
Spans.MentionChipSpan::class.java
)
var mentionSpan: Spans.MentionChipSpan
for (i in mentionSpans.indices) {
mentionSpan = mentionSpans[i]
if (start >= editable.getSpanStart(mentionSpan) &&
start < editable.getSpanEnd(mentionSpan)
) { ) {
editable.removeSpan(mentionSpan) if (editable.subSequence(
editable.getSpanStart(mentionSpan),
editable.getSpanEnd(mentionSpan)
).toString().trim { it <= ' ' } != mentionSpan.label
) {
editable.removeSpan(mentionSpan)
}
} }
} }
} }
} }
override fun afterTextChanged(s: Editable) {
// unused atm
}
})
// Image keyboard support
// See: https://developer.android.com/guide/topics/text/image-keyboard
(binding.messageInputView.inputEditText as ImageEmojiEditText).onCommitContentListener = {
uploadFile(it.toString(), false)
}
initVoiceRecordButton()
if (sharedText.isNotEmpty()) {
binding.messageInputView.inputEditText?.setText(sharedText)
} }
override fun afterTextChanged(s: Editable) { binding.messageInputView.setAttachmentsListener {
// unused atm AttachmentDialog(this, this).show()
} }
})
// Image keyboard support binding.messageInputView.button?.setOnClickListener {
// See: https://developer.android.com/guide/topics/text/image-keyboard submitMessage(false)
(binding.messageInputView.inputEditText as ImageEmojiEditText).onCommitContentListener = {
uploadFile(it.toString(), false)
}
initVoiceRecordButton()
if (sharedText.isNotEmpty()) {
binding.messageInputView.inputEditText?.setText(sharedText)
}
binding.messageInputView.setAttachmentsListener {
AttachmentDialog(this, this).show()
}
binding.messageInputView.button?.setOnClickListener {
submitMessage(false)
}
if (CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.SILENT_SEND)) {
binding.messageInputView.button?.setOnLongClickListener {
showSendButtonMenu()
true
} }
}
binding.messageInputView.button?.contentDescription = if (CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.SILENT_SEND)) {
resources?.getString(R.string.nc_description_send_message_button) binding.messageInputView.button?.setOnLongClickListener {
showSendButtonMenu()
true
}
}
binding.messageInputView.button?.contentDescription =
resources?.getString(R.string.nc_description_send_message_button)
}
} }
private fun editMessageAPI(message: ChatMessage, editedMessageText: String) { private fun editMessageAPI(message: ChatMessage, editedMessageText: String) {