From 423b9215c4730fe694af786e1324d6e9e33569ca Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 31 Jan 2024 18:25:39 +0100 Subject: [PATCH 1/5] Store the `formattedText` to the draft, to be able to restore the formatting. #7466 --- .../home/room/detail/composer/MessageComposerFragment.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt index 338a635818..de6208c7a2 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt @@ -47,6 +47,7 @@ import com.vanniktech.emoji.EmojiPopup import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R import im.vector.app.core.error.fatalError +import im.vector.app.core.extensions.orEmpty import im.vector.app.core.extensions.registerStartForActivityResult import im.vector.app.core.extensions.showKeyboard import im.vector.app.core.glide.GlideApp @@ -255,7 +256,7 @@ class MessageComposerFragment : VectorBaseFragment(), A it.isRecordingVoiceBroadcast && !requireActivity().isChangingConfigurations -> timelineViewModel.handle(VoiceBroadcastAction.Recording.Pause) else -> { timelineViewModel.handle(VoiceBroadcastAction.Listening.Pause) - messageComposerViewModel.handle(MessageComposerAction.OnEntersBackground(composer.text.toString())) + messageComposerViewModel.handle(MessageComposerAction.OnEntersBackground(composer.formattedText ?: composer.text.orEmpty().toString())) } } } From 6a30a2ed323cc6d54c903ccf17a2e9f59f28e3b6 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 31 Jan 2024 18:18:36 +0100 Subject: [PATCH 2/5] Keep the current message formatting when switching between composer mode (Regular, Reply, etc.) --- .../home/room/detail/composer/MessageComposerFragment.kt | 2 +- .../home/room/detail/composer/MessageComposerViewModel.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt index de6208c7a2..038f009d22 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt @@ -404,7 +404,7 @@ class MessageComposerFragment : VectorBaseFragment(), A } override fun onTextChanged(text: CharSequence) { - messageComposerViewModel.handle(MessageComposerAction.OnTextChanged(text)) + messageComposerViewModel.handle(MessageComposerAction.OnTextChanged(composer.formattedText ?: text)) } override fun onFullScreenModeChanged() = withState(messageComposerViewModel) { state -> diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index 648c88b4d2..fbf943855e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -151,7 +151,7 @@ class MessageComposerViewModel @AssistedInject constructor( private fun handleOnTextChanged(action: MessageComposerAction.OnTextChanged) { val needsSendButtonVisibilityUpdate = currentComposerText.isBlank() != action.text.isBlank() - currentComposerText = SpannableString(action.text) + currentComposerText = action.text if (needsSendButtonVisibilityUpdate) { updateIsSendButtonVisibility(true) } From 054af4d6a382b9d87f5965d09e5876d2bbd69406 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 31 Jan 2024 18:31:56 +0100 Subject: [PATCH 3/5] changelog --- changelog.d/7466.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7466.bugfix diff --git a/changelog.d/7466.bugfix b/changelog.d/7466.bugfix new file mode 100644 index 0000000000..bcca741d27 --- /dev/null +++ b/changelog.d/7466.bugfix @@ -0,0 +1 @@ +Restore formatting when restoring a draft. Also keep formatting when switching composer mode. From a17c75a7dacdf9dbc3bec67d62af3fe033fc0820 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 31 Jan 2024 18:49:19 +0100 Subject: [PATCH 4/5] Remove unused import --- .../home/room/detail/composer/MessageComposerViewModel.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index fbf943855e..21747ceea6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -16,7 +16,6 @@ package im.vector.app.features.home.room.detail.composer -import android.text.SpannableString import androidx.lifecycle.asFlow import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.withState From 2395d72c93da67871c5a2d4ed61d8f93978481c0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 27 May 2024 10:35:02 +0200 Subject: [PATCH 5/5] Fix regression on send button visibility. --- .../home/room/detail/composer/MessageComposerViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index 21747ceea6..648c88b4d2 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -16,6 +16,7 @@ package im.vector.app.features.home.room.detail.composer +import android.text.SpannableString import androidx.lifecycle.asFlow import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.withState @@ -150,7 +151,7 @@ class MessageComposerViewModel @AssistedInject constructor( private fun handleOnTextChanged(action: MessageComposerAction.OnTextChanged) { val needsSendButtonVisibilityUpdate = currentComposerText.isBlank() != action.text.isBlank() - currentComposerText = action.text + currentComposerText = SpannableString(action.text) if (needsSendButtonVisibilityUpdate) { updateIsSendButtonVisibility(true) }