clear reply ui when sending attachment as reply

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2025-07-31 15:59:32 +02:00
parent 6ce475dd72
commit 7c37514612
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 53 additions and 31 deletions

View File

@ -2340,7 +2340,7 @@ class ChatActivity :
BuildConfig.APPLICATION_ID,
File(file.absolutePath)
)
chatViewModel.uploadFile(
uploadFile(
fileUri = shareUri.toString(),
isVoiceMessage = false,
caption = "",
@ -2531,7 +2531,7 @@ class ChatActivity :
private fun uploadFiles(files: MutableList<String>, caption: String = "") {
for (i in 0 until files.size) {
if (i == files.size - 1) {
chatViewModel.uploadFile(
uploadFile(
fileUri = files[i],
isVoiceMessage = false,
caption = caption,
@ -2540,7 +2540,7 @@ class ChatActivity :
displayName = currentConversation?.displayName!!
)
} else {
chatViewModel.uploadFile(
uploadFile(
fileUri = files[i],
isVoiceMessage = false,
caption = "",
@ -3880,7 +3880,7 @@ class ChatActivity :
val type = message.getCalculateMessageType()
when (type) {
ChatMessage.MessageType.VOICE_MESSAGE -> {
chatViewModel.uploadFile(
uploadFile(
shareUri.toString(),
true,
roomToken = roomToken,
@ -3896,7 +3896,7 @@ class ChatActivity :
if (null != shareUri) {
try {
context.contentResolver.openInputStream(shareUri)?.close()
chatViewModel.uploadFile(
uploadFile(
fileUri = shareUri.toString(),
isVoiceMessage = false,
caption = caption!!,
@ -3908,7 +3908,7 @@ class ChatActivity :
} catch (e: Exception) {
Log.w(TAG, "File corresponding to the uri does not exist $shareUri", e)
downloadFileToCache(message, false) {
chatViewModel.uploadFile(
uploadFile(
fileUri = shareUri.toString(),
isVoiceMessage = false,
caption = caption!!,
@ -4329,6 +4329,33 @@ class ChatActivity :
)
}
fun uploadFile(
fileUri: String,
isVoiceMessage: Boolean,
caption: String = "",
roomToken: String = "",
replyToMessageId: Int? = null,
displayName: String
) {
chatViewModel.uploadFile(
fileUri,
isVoiceMessage,
caption,
roomToken,
replyToMessageId,
displayName
)
cancelReply()
}
fun cancelReply() {
messageInputViewModel.reply(null)
chatViewModel.messageDraft.quotedMessageText = null
chatViewModel.messageDraft.quotedDisplayName = null
chatViewModel.messageDraft.quotedImageUrl = null
chatViewModel.messageDraft.quotedJsonId = null
}
companion object {
val TAG = ChatActivity::class.simpleName
private const val CONTENT_TYPE_CALL_STARTED: Byte = 1

View File

@ -182,8 +182,12 @@ class MessageInputFragment : Fragment() {
chatActivity.chatViewModel.messageDraft.quotedDisplayName = message.actorDisplayName
chatActivity.chatViewModel.messageDraft.quotedImageUrl = message.imageUrl
chatActivity.chatViewModel.messageDraft.quotedJsonId = message.jsonMessageId
replyToMessage(message.text, message.actorDisplayName, message.imageUrl, message.jsonMessageId)
}
replyToMessage(
message.text,
message.actorDisplayName,
message.imageUrl
)
} ?: clearReplyUi()
}
chatActivity.messageInputViewModel.getEditChatMessage.observe(viewLifecycleOwner) { message ->
@ -314,8 +318,7 @@ class MessageInputFragment : Fragment() {
replyToMessage(
chatActivity.chatViewModel.messageDraft.quotedMessageText,
chatActivity.chatViewModel.messageDraft.quotedDisplayName,
chatActivity.chatViewModel.messageDraft.quotedImageUrl,
chatActivity.chatViewModel.messageDraft.quotedJsonId ?: 0
chatActivity.chatViewModel.messageDraft.quotedImageUrl
)
}
}
@ -468,6 +471,10 @@ class MessageInputFragment : Fragment() {
binding.fragmentCallStarted.callStartedSecondaryText.visibility = if (collapsed) View.VISIBLE else View.GONE
setDropDown(collapsed)
}
binding.fragmentMessageInputView.findViewById<ImageButton>(R.id.cancelReplyButton)?.setOnClickListener {
cancelReply()
}
}
private fun setDropDown(collapsed: Boolean) {
@ -719,12 +726,7 @@ class MessageInputFragment : Fragment() {
}
}
private fun replyToMessage(
quotedMessageText: String?,
quotedActorDisplayName: String?,
quotedImageUrl: String?,
quotedJsonId: Int
) {
private fun replyToMessage(quotedMessageText: String?, quotedActorDisplayName: String?, quotedImageUrl: String?) {
Log.d(TAG, "Reply")
val view = binding.fragmentMessageInputView
view.findViewById<ImageButton>(R.id.cancelReplyButton)?.visibility =
@ -955,10 +957,6 @@ class MessageInputFragment : Fragment() {
private fun themeMessageInputView() {
binding.fragmentMessageInputView.button?.let { viewThemeUtils.platform.colorImageView(it, ColorRole.PRIMARY) }
binding.fragmentMessageInputView.findViewById<ImageButton>(R.id.cancelReplyButton)?.setOnClickListener {
cancelReply()
}
binding.fragmentMessageInputView.findViewById<ImageButton>(R.id.cancelReplyButton)?.let {
viewThemeUtils.platform
.themeImageButton(it)
@ -1015,18 +1013,14 @@ class MessageInputFragment : Fragment() {
}
private fun cancelReply() {
// TODO set id in viewmodel to null
val quote = binding.fragmentMessageInputView
.findViewById<RelativeLayout>(R.id.quotedChatMessageView)
quote.visibility = View.GONE
quote.tag = null
binding.fragmentMessageInputView.findViewById<ImageButton>(R.id.attachmentButton)?.visibility = View.VISIBLE
chatActivity.messageInputViewModel.reply(null)
chatActivity.cancelReply()
clearReplyUi()
}
chatActivity.chatViewModel.messageDraft.quotedMessageText = null
chatActivity.chatViewModel.messageDraft.quotedDisplayName = null
chatActivity.chatViewModel.messageDraft.quotedImageUrl = null
chatActivity.chatViewModel.messageDraft.quotedJsonId = null
private fun clearReplyUi() {
val quote = binding.fragmentMessageInputView.findViewById<RelativeLayout>(R.id.quotedChatMessageView)
quote.visibility = View.GONE
binding.fragmentMessageInputView.findViewById<ImageButton>(R.id.attachmentButton)?.visibility = View.VISIBLE
}
private fun isInReplyState(): Boolean {

View File

@ -445,6 +445,7 @@ class OfflineFirstChatRepository @Inject constructor(
return loadFromServer
}
@Suppress("LongParameterList")
private fun getFieldMap(
lookIntoFuture: Boolean,
timeout: Int,