mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Use proper API to insert mention from timeline user
This commit is contained in:
parent
cb64175c2b
commit
9d239bf94d
@ -101,6 +101,7 @@ import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
|
||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkService
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
import reactivecircus.flowbinding.android.view.focusChanges
|
||||
import reactivecircus.flowbinding.android.widget.textChanges
|
||||
@ -123,6 +124,9 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
@Inject lateinit var session: Session
|
||||
@Inject lateinit var errorTracker: ErrorTracker
|
||||
|
||||
private val permalinkService: PermalinkService
|
||||
get() = session.permalinkService()
|
||||
|
||||
private val roomId: String get() = withState(timelineViewModel) { it.roomId }
|
||||
|
||||
private val autoCompleters: MutableMap<EditText, AutoCompleter> = hashMapOf()
|
||||
@ -792,6 +796,12 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
} else {
|
||||
val roomMember = timelineViewModel.getMember(userId)
|
||||
val displayName = sanitizeDisplayName(roomMember?.displayName ?: userId)
|
||||
if ((composer as? RichTextComposerLayout)?.isTextFormattingEnabled == true) {
|
||||
// Rich text editor is enabled so we need to use its APIs
|
||||
permalinkService.createPermalink(userId)?.let { url ->
|
||||
(composer as RichTextComposerLayout).insertMention(url, displayName)
|
||||
}
|
||||
} else {
|
||||
val pill = buildSpannedString {
|
||||
append(displayName)
|
||||
setSpan(
|
||||
@ -799,7 +809,7 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
glideRequests,
|
||||
avatarRenderer,
|
||||
requireContext(),
|
||||
MatrixItem.UserItem(userId, displayName, roomMember?.avatarUrl)
|
||||
MatrixItem.UserItem(userId, displayName, roomMember?.avatarUrl),
|
||||
)
|
||||
.also { it.bind(composer.editText) },
|
||||
0,
|
||||
@ -817,6 +827,7 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
|
||||
// https://developer.android.com/reference/android/widget/TextView#append(java.lang.CharSequence)
|
||||
composer.editText.text.insert(composer.editText.selectionStart, pill)
|
||||
}
|
||||
}
|
||||
focusComposerAndShowKeyboard()
|
||||
}
|
||||
|
||||
|
@ -305,6 +305,10 @@ internal class RichTextComposerLayout @JvmOverloads constructor(
|
||||
fun removeLink() =
|
||||
views.richTextComposerEditText.removeLink()
|
||||
|
||||
// TODO: update the API to insertMention when available
|
||||
fun insertMention(url: String, displayText: String) =
|
||||
views.richTextComposerEditText.insertLink(url, displayText)
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun disallowParentInterceptTouchEvent(view: View) {
|
||||
view.setOnTouchListener { v, event ->
|
||||
|
Loading…
Reference in New Issue
Block a user