[merge-fixup] Fix our send button behaviour

Change-Id: I119132f0423bf4884e37e4b9f9e5cd204949b269
This commit is contained in:
SpiritCroc 2021-10-11 10:38:40 +02:00
parent dffc0c1d65
commit ba2ed623c2
4 changed files with 19 additions and 9 deletions

View file

@ -19,6 +19,7 @@ package im.vector.app.features.home.room.detail
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.Typeface
@ -474,11 +475,17 @@ class RoomDetailFragment @Inject constructor(
}
private fun handleSendButtonVisibilityChanged(event: TextComposerViewEvents.AnimateSendButtonVisibility) {
val sendButtonColor = ThemeUtils.getColor(views.composerLayout.context, if (event.isActive) R.attr.colorAccent else R.attr.vctr_content_tertiary)
views.composerLayout.views.sendButton.imageTintList = ColorStateList.valueOf(sendButtonColor)
if (event.isVisible) {
views.voiceMessageRecorderView.isVisible = false
views.composerLayout.views.sendButton.alpha = 0f
views.composerLayout.views.sendButton.isVisible = true
views.composerLayout.views.sendButton.animate().alpha(1f).setDuration(150).start()
if (views.composerLayout.views.sendButton.isVisible) {
views.composerLayout.views.sendButton.alpha = 1f
} else {
views.composerLayout.views.sendButton.alpha = 0f
views.composerLayout.views.sendButton.isVisible = true
views.composerLayout.views.sendButton.animate().alpha(1f).setDuration(150).start()
}
} else {
views.composerLayout.views.sendButton.isInvisible = true
views.voiceMessageRecorderView.alpha = 0f
@ -1426,7 +1433,7 @@ class RoomDetailFragment @Inject constructor(
lazyLoadedViews.inviteView(false)?.isVisible = false
if (mainState.tombstoneEvent == null) {
views.composerLayout.isInvisible = !textComposerState.isComposerVisible
views.voiceMessageRecorderView.isVisible = !textComposerState.isSendButtonVisible && vectorPreferences.useVoiceMessage()
views.voiceMessageRecorderView.isVisible = !textComposerState.isSendButtonVisible
views.composerLayout.views.sendButton.isInvisible = !textComposerState.isSendButtonVisible
views.composerLayout.setRoomEncrypted(summary.isEncrypted)
// views.composerLayout.alwaysShowSendButton = !vectorPreferences.useVoiceMessage()

View file

@ -22,7 +22,7 @@ import im.vector.app.features.command.Command
sealed class TextComposerViewEvents : VectorViewEvents {
data class AnimateSendButtonVisibility(val isVisible: Boolean) : TextComposerViewEvents()
data class AnimateSendButtonVisibility(val isVisible: Boolean, val isActive: Boolean) : TextComposerViewEvents()
data class ShowMessage(val message: String) : TextComposerViewEvents()

View file

@ -112,11 +112,13 @@ class TextComposerViewModel @AssistedInject constructor(
}
private fun updateIsSendButtonVisibility(triggerAnimation: Boolean) = setState {
val isSendButtonVisible = isComposerVisible && (sendMode !is SendMode.REGULAR || currentComposerText.isNotBlank())
if (this.isSendButtonVisible != isSendButtonVisible && triggerAnimation) {
_viewEvents.post(TextComposerViewEvents.AnimateSendButtonVisibility(isSendButtonVisible))
val upstreamShowsSendButton = (isComposerVisible && (sendMode !is SendMode.REGULAR || currentComposerText.isNotBlank()))
val isSendButtonVisible = upstreamShowsSendButton || !vectorPreferences.useVoiceMessage()
val isSendButtonActive = currentComposerText.isNotBlank()
if ((this.isSendButtonVisible != isSendButtonVisible || this.isSendButtonActive != isSendButtonActive) && triggerAnimation) {
_viewEvents.post(TextComposerViewEvents.AnimateSendButtonVisibility(isSendButtonVisible, isSendButtonActive))
}
copy(isSendButtonVisible = isSendButtonVisible)
copy(isSendButtonVisible = isSendButtonVisible, isSendButtonActive = isSendButtonActive)
}
private fun handleEnterRegularMode(action: TextComposerAction.EnterRegularMode) = setState {

View file

@ -45,6 +45,7 @@ data class TextComposerViewState(
val roomId: String,
val canSendMessage: Boolean = true,
val isVoiceRecording: Boolean = false,
val isSendButtonActive: Boolean = false,
val isSendButtonVisible: Boolean = false,
val sendMode: SendMode = SendMode.REGULAR("", false)
) : MvRxState {