Fixes playback button state not tracking after onPause

This commit is contained in:
ericdecanini 2022-03-28 13:52:47 +02:00
parent 931c0e9826
commit fa56a5efa9
4 changed files with 16 additions and 3 deletions

View file

@ -1265,7 +1265,7 @@ class TimelineFragment @Inject constructor(
override fun onPause() {
super.onPause()
notificationDrawerManager.setCurrentRoom(null)
audioMessagePlaybackTracker.untrack(AudioMessagePlaybackTracker.RECORDING_ID)
audioMessagePlaybackTracker.pauseAllPlaybacks()
if (withState(messageComposerViewModel) { it.isVoiceRecording } && requireActivity().isChangingConfigurations) {
// we're rotating, maintain any active recordings

View file

@ -881,7 +881,6 @@ class MessageComposerViewModel @AssistedInject constructor(
private fun handleEntersBackground(composerText: String) {
// Always stop all voice actions. It may be playing in timeline or active recording
val playingAudioContent = voiceMessageHelper.stopAllVoiceActions(deleteRecord = false)
voiceMessageHelper.clearTracker()
val isVoiceRecording = com.airbnb.mvrx.withState(this) { it.isVoiceRecording }
if (isVoiceRecording) {

View file

@ -50,6 +50,12 @@ class AudioMessagePlaybackTracker @Inject constructor() {
listeners.remove(id)
}
fun pauseAllPlaybacks() {
listeners.keys.forEach { key ->
pausePlayback(key)
}
}
fun makeAllPlaybacksIdle() {
listeners.keys.forEach { key ->
setState(key, Listener.State.Idle)

View file

@ -18,6 +18,7 @@ package im.vector.app.features.home.room.detail.timeline.item
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.Paint
import android.text.format.DateUtils
import android.view.ViewGroup
import android.widget.ImageButton
@ -27,6 +28,7 @@ import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.onClick
import im.vector.app.features.home.room.detail.timeline.helper.AudioMessagePlaybackTracker
import im.vector.app.features.home.room.detail.timeline.helper.ContentDownloadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder
@ -64,8 +66,8 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
override fun bind(holder: Holder) {
super.bind(holder)
renderSendState(holder.rootLayout, null)
bindFilenameViewAttributes(holder)
bindUploadState(holder)
holder.filenameView.text = filename
applyLayoutTint(holder)
holder.audioPlaybackControlButton.setOnClickListener { playbackControlButtonClickListener?.invoke(it) }
renderStateBasedOnAudioPlayback(holder)
@ -91,6 +93,12 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
holder.mainLayout.backgroundTintList = ColorStateList.valueOf(backgroundTint)
}
private fun bindFilenameViewAttributes(holder: Holder) {
holder.filenameView.text = filename
holder.filenameView.onClick(attributes.itemClickListener)
holder.filenameView.paintFlags = (holder.filenameView.paintFlags or Paint.UNDERLINE_TEXT_FLAG)
}
private fun renderStateBasedOnAudioPlayback(holder: Holder) {
audioMessagePlaybackTracker.track(attributes.informationData.eventId, object : AudioMessagePlaybackTracker.Listener {
override fun onUpdate(state: AudioMessagePlaybackTracker.Listener.State) {