Fix rendering issue of time when playing in the timeline - still buggy

And fix timer not cancelled properly when at the end of the playback
This commit is contained in:
Benoit Marty 2021-07-13 15:15:07 +02:00
parent fa7c1a763f
commit bf14fa90a2
4 changed files with 8 additions and 10 deletions

View file

@ -225,6 +225,7 @@ class VoiceMessageHelper @Inject constructor(
} }
else -> { else -> {
playbackTracker.stopPlayback(id = id, rememberPlaybackTime = false) playbackTracker.stopPlayback(id = id, rememberPlaybackTime = false)
stopPlaybackTimer()
} }
} }
} }

View file

@ -289,6 +289,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
private fun renderRecordingWaveform(amplitudeList: List<Int>) { private fun renderRecordingWaveform(amplitudeList: List<Int>) {
views.voicePlaybackWaveform.apply { views.voicePlaybackWaveform.apply {
post { post {
// TODO We could avoid recreating the whole view here and just call update() with the new value(s).
recreate() recreate()
amplitudeList.forEach { amplitude -> amplitudeList.forEach { amplitude ->
update(amplitude) update(amplitude)

View file

@ -110,7 +110,7 @@ class VoiceMessagePlaybackTracker @Inject constructor() {
} }
companion object { companion object {
var RECORDING_ID = "RECORDING_ID" const val RECORDING_ID = "RECORDING_ID"
} }
interface Listener { interface Listener {

View file

@ -88,14 +88,14 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
voiceMessagePlaybackTracker.track(attributes.informationData.eventId, object : VoiceMessagePlaybackTracker.Listener { voiceMessagePlaybackTracker.track(attributes.informationData.eventId, object : VoiceMessagePlaybackTracker.Listener {
override fun onUpdate(state: VoiceMessagePlaybackTracker.Listener.State) { override fun onUpdate(state: VoiceMessagePlaybackTracker.Listener.State) {
when (state) { when (state) {
is VoiceMessagePlaybackTracker.Listener.State.Idle -> handleIdleState(holder, state) is VoiceMessagePlaybackTracker.Listener.State.Idle -> renderIdleState(holder, state)
is VoiceMessagePlaybackTracker.Listener.State.Playing -> handlePlayingState(holder, state) is VoiceMessagePlaybackTracker.Listener.State.Playing -> renderPlayingState(holder, state)
} }
} }
}) })
} }
private fun handleIdleState(holder: Holder, state: VoiceMessagePlaybackTracker.Listener.State.Idle) { private fun renderIdleState(holder: Holder, state: VoiceMessagePlaybackTracker.Listener.State.Idle) {
holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_play) holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_play)
if (state.playbackTime > 0) { if (state.playbackTime > 0) {
holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime) holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime)
@ -104,13 +104,9 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
} }
} }
private fun handlePlayingState(holder: Holder, state: VoiceMessagePlaybackTracker.Listener.State.Playing) { private fun renderPlayingState(holder: Holder, state: VoiceMessagePlaybackTracker.Listener.State.Playing) {
holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_pause) holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_pause)
if (state.playbackTime > 0) { holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime)
holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime)
} else {
holder.voicePlaybackTime.text = formatPlaybackTime(duration)
}
} }
private fun formatPlaybackTime(time: Int) = DateUtils.formatElapsedTime((time / 1000).toLong()) private fun formatPlaybackTime(time: Int) = DateUtils.formatElapsedTime((time / 1000).toLong())