Improved typing performances
This commit is contained in:
parent
a8b057c05a
commit
e96d073ff0
2 changed files with 23 additions and 19 deletions
|
@ -129,6 +129,10 @@ class DetailChatRoomFragment : MasterFragment() {
|
||||||
}
|
}
|
||||||
binding.chatMessagesList.addOnScrollListener(chatScrollListener)
|
binding.chatMessagesList.addOnScrollListener(chatScrollListener)
|
||||||
|
|
||||||
|
chatSendingViewModel.textToSend.observe(viewLifecycleOwner, Observer {
|
||||||
|
chatSendingViewModel.onTextToSendChanged(it)
|
||||||
|
})
|
||||||
|
|
||||||
listViewModel.events.observe(viewLifecycleOwner, Observer { events ->
|
listViewModel.events.observe(viewLifecycleOwner, Observer { events ->
|
||||||
adapter.submitList(events)
|
adapter.submitList(events)
|
||||||
})
|
})
|
||||||
|
|
|
@ -47,21 +47,7 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
||||||
|
|
||||||
val isReadOnly = MutableLiveData<Boolean>()
|
val isReadOnly = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
var textToSend: String = ""
|
var textToSend = MutableLiveData<String>()
|
||||||
set(value) {
|
|
||||||
sendMessageEnabled.value = value.isNotEmpty() || attachments.value?.isNotEmpty() ?: false
|
|
||||||
if (value.isNotEmpty()) {
|
|
||||||
if (!corePreferences.allowMultipleFilesAndTextInSameMessage) {
|
|
||||||
attachFileEnabled.value = false
|
|
||||||
}
|
|
||||||
chatRoom.compose()
|
|
||||||
} else {
|
|
||||||
if (!corePreferences.allowMultipleFilesAndTextInSameMessage) {
|
|
||||||
attachFileEnabled.value = attachments.value?.isEmpty() ?: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
field = value
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
attachments.value = arrayListOf()
|
attachments.value = arrayListOf()
|
||||||
|
@ -71,6 +57,20 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
||||||
isReadOnly.value = chatRoom.hasBeenLeft()
|
isReadOnly.value = chatRoom.hasBeenLeft()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onTextToSendChanged(value: String) {
|
||||||
|
sendMessageEnabled.value = value.isNotEmpty() || attachments.value?.isNotEmpty() ?: false
|
||||||
|
if (value.isNotEmpty()) {
|
||||||
|
if (attachFileEnabled.value == true && !corePreferences.allowMultipleFilesAndTextInSameMessage) {
|
||||||
|
attachFileEnabled.value = false
|
||||||
|
}
|
||||||
|
chatRoom.compose()
|
||||||
|
} else {
|
||||||
|
if (!corePreferences.allowMultipleFilesAndTextInSameMessage) {
|
||||||
|
attachFileEnabled.value = attachments.value?.isEmpty() ?: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun addAttachment(path: String) {
|
fun addAttachment(path: String) {
|
||||||
val list = arrayListOf<ChatMessageAttachmentViewModel>()
|
val list = arrayListOf<ChatMessageAttachmentViewModel>()
|
||||||
list.addAll(attachments.value.orEmpty())
|
list.addAll(attachments.value.orEmpty())
|
||||||
|
@ -79,7 +79,7 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
||||||
})
|
})
|
||||||
attachments.value = list
|
attachments.value = list
|
||||||
|
|
||||||
sendMessageEnabled.value = textToSend.isNotEmpty() || list.isNotEmpty()
|
sendMessageEnabled.value = textToSend.value.orEmpty().isNotEmpty() || list.isNotEmpty()
|
||||||
if (!corePreferences.allowMultipleFilesAndTextInSameMessage) {
|
if (!corePreferences.allowMultipleFilesAndTextInSameMessage) {
|
||||||
attachFileEnabled.value = false
|
attachFileEnabled.value = false
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
||||||
list.remove(attachment)
|
list.remove(attachment)
|
||||||
attachments.value = list
|
attachments.value = list
|
||||||
|
|
||||||
sendMessageEnabled.value = textToSend.isNotEmpty() || list.isNotEmpty()
|
sendMessageEnabled.value = textToSend.value.orEmpty().isNotEmpty() || list.isNotEmpty()
|
||||||
if (!corePreferences.allowMultipleFilesAndTextInSameMessage) {
|
if (!corePreferences.allowMultipleFilesAndTextInSameMessage) {
|
||||||
attachFileEnabled.value = list.isEmpty()
|
attachFileEnabled.value = list.isEmpty()
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,8 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
||||||
val isBasicChatRoom: Boolean = chatRoom.hasCapability(ChatRoomCapabilities.Basic.toInt())
|
val isBasicChatRoom: Boolean = chatRoom.hasCapability(ChatRoomCapabilities.Basic.toInt())
|
||||||
val message: ChatMessage = chatRoom.createEmptyMessage()
|
val message: ChatMessage = chatRoom.createEmptyMessage()
|
||||||
|
|
||||||
if (textToSend.isNotEmpty()) {
|
if (textToSend.value.orEmpty().isNotEmpty()) {
|
||||||
message.addTextContent(textToSend)
|
message.addTextContent(textToSend.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (attachment in attachments.value.orEmpty()) {
|
for (attachment in attachments.value.orEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue