From 8cd0983088a9eb5504a0f871bb90e0c0bbe7f961 Mon Sep 17 00:00:00 2001 From: rapterjet2004 Date: Fri, 27 Sep 2024 09:20:11 -0500 Subject: [PATCH] WIP Editing Signed-off-by: rapterjet2004 --- .../messages/TemporaryMessageViewHolder.kt | 32 ++++++++++++++++++- .../com/nextcloud/talk/chat/ChatActivity.kt | 2 +- .../res/layout/item_temporary_message.xml | 6 ++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/TemporaryMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/TemporaryMessageViewHolder.kt index 2a2173460..1c6a4d824 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/TemporaryMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/TemporaryMessageViewHolder.kt @@ -7,6 +7,7 @@ package com.nextcloud.talk.adapters.messages +import android.content.Context import android.view.View import androidx.core.content.res.ResourcesCompat import androidx.core.view.ViewCompat @@ -30,7 +31,11 @@ class TemporaryMessageViewHolder(outgoingView: View, payload: Any) : @Inject lateinit var viewThemeUtils: ViewThemeUtils + @Inject + lateinit var context: Context + lateinit var temporaryMessageInterface: TemporaryMessageInterface + var isEditing = false override fun onBind(message: ChatMessage) { super.onBind(message) @@ -40,7 +45,32 @@ class TemporaryMessageViewHolder(outgoingView: View, payload: Any) : viewThemeUtils.platform.colorImageView(binding.tempMsgDelete, ColorRole.PRIMARY) binding.tempMsgEdit.setOnClickListener { - // TODO + isEditing = !isEditing + if (isEditing) { + binding.tempMsgEdit.setImageDrawable( + ResourcesCompat.getDrawable( + context.resources, + R.drawable.ic_check, + null + ) + ) + binding.messageEdit.visibility = View.VISIBLE + binding.messageEdit.setText(binding.messageText.text) + binding.messageText.visibility = View.GONE + } else { + binding.tempMsgEdit.setImageDrawable( + ResourcesCompat.getDrawable( + context.resources, + R.drawable.ic_edit, + null + ) + ) + binding.messageEdit.visibility = View.GONE + binding.messageText.visibility = View.VISIBLE + val newMessage = binding.messageEdit.text.toString() + message.message = newMessage + temporaryMessageInterface.editTemporaryMessage(message.tempMessageId, newMessage) + } } binding.tempMsgDelete.setOnClickListener { diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 54af54cb7..2f91c8158 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -3666,7 +3666,7 @@ class ChatActivity : } override fun editTemporaryMessage(id: Int, newMessage: String) { - // TODO("Not yet implemented") + // TODO update adapter item and call viewModel to persist data } override fun deleteTemporaryMessage(id: Int) { diff --git a/app/src/main/res/layout/item_temporary_message.xml b/app/src/main/res/layout/item_temporary_message.xml index 532ae7ab9..191af1ce1 100644 --- a/app/src/main/res/layout/item_temporary_message.xml +++ b/app/src/main/res/layout/item_temporary_message.xml @@ -65,6 +65,12 @@ android:textIsSelectable="false" tools:text="Talk to you later!" /> + +