diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index 703696173e..a5c1b8a544 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index 976489eec3..eb7d87c371 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -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) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/AudioMessagePlaybackTracker.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/AudioMessagePlaybackTracker.kt index 7404735e28..546b76bebd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/AudioMessagePlaybackTracker.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/AudioMessagePlaybackTracker.kt @@ -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) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageAudioItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageAudioItem.kt index bf248a27e8..243aa8c6a4 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageAudioItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageAudioItem.kt @@ -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() { 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() { 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) {