mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
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:
parent
fa7c1a763f
commit
bf14fa90a2
4 changed files with 8 additions and 10 deletions
|
@ -225,6 +225,7 @@ class VoiceMessageHelper @Inject constructor(
|
|||
}
|
||||
else -> {
|
||||
playbackTracker.stopPlayback(id = id, rememberPlaybackTime = false)
|
||||
stopPlaybackTimer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,6 +289,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
|||
private fun renderRecordingWaveform(amplitudeList: List<Int>) {
|
||||
views.voicePlaybackWaveform.apply {
|
||||
post {
|
||||
// TODO We could avoid recreating the whole view here and just call update() with the new value(s).
|
||||
recreate()
|
||||
amplitudeList.forEach { amplitude ->
|
||||
update(amplitude)
|
||||
|
|
|
@ -110,7 +110,7 @@ class VoiceMessagePlaybackTracker @Inject constructor() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
var RECORDING_ID = "RECORDING_ID"
|
||||
const val RECORDING_ID = "RECORDING_ID"
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
|
|
|
@ -88,14 +88,14 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
|
|||
voiceMessagePlaybackTracker.track(attributes.informationData.eventId, object : VoiceMessagePlaybackTracker.Listener {
|
||||
override fun onUpdate(state: VoiceMessagePlaybackTracker.Listener.State) {
|
||||
when (state) {
|
||||
is VoiceMessagePlaybackTracker.Listener.State.Idle -> handleIdleState(holder, state)
|
||||
is VoiceMessagePlaybackTracker.Listener.State.Playing -> handlePlayingState(holder, state)
|
||||
is VoiceMessagePlaybackTracker.Listener.State.Idle -> renderIdleState(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)
|
||||
if (state.playbackTime > 0) {
|
||||
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)
|
||||
if (state.playbackTime > 0) {
|
||||
holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime)
|
||||
} else {
|
||||
holder.voicePlaybackTime.text = formatPlaybackTime(duration)
|
||||
}
|
||||
holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime)
|
||||
}
|
||||
|
||||
private fun formatPlaybackTime(time: Int) = DateUtils.formatElapsedTime((time / 1000).toLong())
|
||||
|
|
Loading…
Reference in a new issue