16
16
17
17
package im.vector.app.features.home.room.detail.composer
18
18
19
+ import android.annotation.SuppressLint
19
20
import android.app.Activity
20
21
import android.content.Intent
21
22
import android.content.res.Configuration
@@ -249,15 +250,13 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
249
250
250
251
composerEditText.setOnEditorActionListener { v, actionId, keyEvent ->
251
252
val imeActionId = actionId and EditorInfo .IME_MASK_ACTION
252
- if (EditorInfo .IME_ACTION_DONE == imeActionId || EditorInfo .IME_ACTION_SEND == imeActionId) {
253
- sendTextMessage(v.text)
254
- true
255
- }
253
+ val isSendAction = EditorInfo .IME_ACTION_DONE == imeActionId || EditorInfo .IME_ACTION_SEND == imeActionId
256
254
// Add external keyboard functionality (to send messages)
257
- else if ( null != keyEvent &&
255
+ val externalKeyboardPressedEnter = null != keyEvent &&
258
256
! keyEvent.isShiftPressed &&
259
257
keyEvent.keyCode == KeyEvent .KEYCODE_ENTER &&
260
- resources.configuration.keyboard != Configuration .KEYBOARD_NOKEYS ) {
258
+ resources.configuration.keyboard != Configuration .KEYBOARD_NOKEYS
259
+ if (isSendAction || externalKeyboardPressedEnter) {
261
260
sendTextMessage(v.text)
262
261
true
263
262
} else false
@@ -716,6 +715,7 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
716
715
}
717
716
}
718
717
718
+ @SuppressLint(" SetTextI18n" )
719
719
private fun insertUserDisplayNameInTextEditor (userId : String ) {
720
720
val startToCompose = views.composerLayout.text.isNullOrBlank()
721
721
@@ -726,36 +726,32 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
726
726
views.composerLayout.views.composerEditText.setSelection(Command .EMOTE .command.length + 1 )
727
727
} else {
728
728
val roomMember = timelineViewModel.getMember(userId)
729
- // TODO move logic outside of fragment
730
- sanitizeDisplayName(roomMember?.displayName ? : userId)
731
- .let { displayName ->
732
- buildSpannedString {
733
- append(displayName)
734
- setSpan(
735
- PillImageSpan (
736
- glideRequests,
737
- avatarRenderer,
738
- requireContext(),
739
- MatrixItem .UserItem (userId, displayName, roomMember?.avatarUrl)
740
- )
741
- .also { it.bind(views.composerLayout.views.composerEditText) },
742
- 0 ,
743
- displayName.length,
744
- Spannable .SPAN_EXCLUSIVE_EXCLUSIVE
745
- )
746
- append(if (startToCompose) " : " else " " )
747
- }.let { pill ->
748
- if (startToCompose) {
749
- if (displayName.startsWith(" /" )) {
750
- // Ensure displayName will not be interpreted as a Slash command
751
- views.composerLayout.views.composerEditText.append(" \\ " )
752
- }
753
- views.composerLayout.views.composerEditText.append(pill)
754
- } else {
755
- views.composerLayout.views.composerEditText.text?.insert(views.composerLayout.views.composerEditText.selectionStart, pill)
756
- }
757
- }
758
- }
729
+ val displayName = sanitizeDisplayName(roomMember?.displayName ? : userId)
730
+ val pill = buildSpannedString {
731
+ append(displayName)
732
+ setSpan(
733
+ PillImageSpan (
734
+ glideRequests,
735
+ avatarRenderer,
736
+ requireContext(),
737
+ MatrixItem .UserItem (userId, displayName, roomMember?.avatarUrl)
738
+ )
739
+ .also { it.bind(views.composerLayout.views.composerEditText) },
740
+ 0 ,
741
+ displayName.length,
742
+ Spannable .SPAN_EXCLUSIVE_EXCLUSIVE
743
+ )
744
+ append(if (startToCompose) " : " else " " )
745
+ }
746
+ if (startToCompose) {
747
+ if (displayName.startsWith(" /" )) {
748
+ // Ensure displayName will not be interpreted as a Slash command
749
+ views.composerLayout.views.composerEditText.append(" \\ " )
750
+ }
751
+ views.composerLayout.views.composerEditText.append(pill)
752
+ } else {
753
+ views.composerLayout.views.composerEditText.text?.insert(views.composerLayout.views.composerEditText.selectionStart, pill)
754
+ }
759
755
}
760
756
focusComposerAndShowKeyboard()
761
757
}
0 commit comments