Skip to content

Commit

Permalink
Merge pull request #3816 from vector-im/feature/ons/fix_voice_message_ui
Browse files Browse the repository at this point in the history
Voice Message - UI Improvements
  • Loading branch information
onurays authored Aug 11, 2021
2 parents a538014 + a8f4b31 commit ec093e7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/3798.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Voice Message - UI Improvements
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,9 @@ class RoomDetailFragment @Inject constructor(
notificationDrawerManager.setCurrentRoom(roomDetailArgs.roomId)
roomDetailPendingActionStore.data?.let { handlePendingAction(it) }
roomDetailPendingActionStore.data = null

// Removed listeners should be set again
setupVoiceMessageView()
}

private fun handlePendingAction(roomDetailPendingAction: RoomDetailPendingAction) {
Expand Down Expand Up @@ -1318,7 +1321,6 @@ class RoomDetailFragment @Inject constructor(
if (text.isNotBlank()) {
// We collapse ASAP, if not there will be a slight annoying delay
views.composerLayout.collapse(true)
views.voiceMessageRecorderView.isVisible = vectorPreferences.labsUseVoiceMessage()
lockSendButton = true
roomDetailViewModel.handle(RoomDetailAction.SendMessage(text, vectorPreferences.isMarkdownEnabled()))
emojiPopup.dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.Context
import android.text.format.DateUtils
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
Expand Down Expand Up @@ -87,6 +88,15 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
initListeners()
}

override fun onVisibilityChanged(changedView: View, visibility: Int) {
super.onVisibilityChanged(changedView, visibility)
if (changedView == this && visibility == VISIBLE) {
views.voiceMessageMicButton.contentDescription = context.getString(R.string.a11y_start_voice_message)
} else {
views.voiceMessageMicButton.contentDescription = ""
}
}

fun initVoiceRecordingViews() {
recordingState = RecordingState.NONE

Expand Down Expand Up @@ -209,6 +219,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
}
RecordingState.CANCELLED -> {
hideRecordingViews(isCancelled = true)
vibrate(context)
}
RecordingState.LOCKED -> {
if (isRecordingStateChanged) { // Do not update views if it was already in locked state.
Expand All @@ -220,6 +231,9 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
}
RecordingState.STARTED -> {
showRecordingViews()
val translationAmount = distanceX.coerceAtMost(distanceToCancel)
views.voiceMessageMicButton.translationX = -translationAmount * rtlXMultiplier
views.voiceMessageSlideToCancel.translationX = -translationAmount / 2 * rtlXMultiplier
}
RecordingState.NONE -> Timber.d("VoiceMessageRecorderView shouldn't be in NONE state while moving.")
RecordingState.PLAYBACK -> Timber.d("VoiceMessageRecorderView shouldn't be in PLAYBACK state while moving.")
Expand All @@ -235,9 +249,9 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
if (recordingState == RecordingState.STARTED) {
// Determine if cancelling or locking for the first move action.
if (((currentX < firstX && rtlXMultiplier == 1) || (currentX > firstX && rtlXMultiplier == -1))
&& distanceX > distanceY) {
&& distanceX > distanceY && distanceX > lastDistanceX) {
recordingState = RecordingState.CANCELLING
} else if (currentY < firstY && distanceY > distanceX) {
} else if (currentY < firstY && distanceY > distanceX && distanceY > lastDistanceY) {
recordingState = RecordingState.LOCKING
}
} else if (recordingState == RecordingState.CANCELLING) {
Expand Down Expand Up @@ -507,12 +521,14 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
}
is VoiceMessagePlaybackTracker.Listener.State.Playing -> {
views.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_pause)
views.voicePlaybackControlButton.contentDescription = context.getString(R.string.a11y_pause_voice_message)
val formattedTimerText = DateUtils.formatElapsedTime((state.playbackTime / 1000).toLong())
views.voicePlaybackTime.text = formattedTimerText
}
is VoiceMessagePlaybackTracker.Listener.State.Paused,
is VoiceMessagePlaybackTracker.Listener.State.Idle -> {
views.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_play)
views.voicePlaybackControlButton.contentDescription = context.getString(R.string.a11y_play_voice_message)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
contentUploadStateTrackerBinder.bind(attributes.informationData.eventId, izLocalFile, holder.progressLayout)
} else {
holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_cross)
holder.voicePlaybackControlButton.contentDescription = holder.view.context.getString(R.string.error_voice_message_unable_to_play)
holder.progressLayout.isVisible = false
}

Expand Down Expand Up @@ -98,16 +99,19 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {

private fun renderIdleState(holder: Holder) {
holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_play)
holder.voicePlaybackControlButton.contentDescription = holder.view.context.getString(R.string.a11y_play_voice_message)
holder.voicePlaybackTime.text = formatPlaybackTime(duration)
}

private fun renderPlayingState(holder: Holder, state: VoiceMessagePlaybackTracker.Listener.State.Playing) {
holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_pause)
holder.voicePlaybackControlButton.contentDescription = holder.view.context.getString(R.string.a11y_pause_voice_message)
holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime)
}

private fun renderPausedState(holder: Holder, state: VoiceMessagePlaybackTracker.Listener.State.Paused) {
holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_play)
holder.voicePlaybackControlButton.contentDescription = holder.view.context.getString(R.string.a11y_play_voice_message)
holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime)
}

Expand Down

0 comments on commit ec093e7

Please sign in to comment.