From 6adf4878f7cda2bc3560bbea9ecc8f135fe74f33 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 29 Mar 2022 17:40:00 +0200 Subject: [PATCH] Fixes bugs related to audio message duration being set incorrectly between activity states --- .../app/features/home/room/detail/TimelineFragment.kt | 1 + .../detail/timeline/helper/AudioMessagePlaybackTracker.kt | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) 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 db86b5a55d..4907f99d25 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 @@ -900,6 +900,7 @@ class TimelineFragment @Inject constructor( } override fun onDestroyView() { + audioMessagePlaybackTracker.makeAllPlaybacksIdle() lazyLoadedViews.unBind() timelineEventController.callback = null timelineEventController.removeModelBuildListener(modelBuildListener) 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 546b76bebd..fb000d7b70 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 @@ -93,9 +93,11 @@ class AudioMessagePlaybackTracker @Inject constructor() { } fun pausePlayback(id: String) { - val currentPlaybackTime = getPlaybackTime(id) - val currentPercentage = getPercentage(id) - setState(id, Listener.State.Paused(currentPlaybackTime, currentPercentage)) + if (getPlaybackState(id) is Listener.State.Playing) { + val currentPlaybackTime = getPlaybackTime(id) + val currentPercentage = getPercentage(id) + setState(id, Listener.State.Paused(currentPlaybackTime, currentPercentage)) + } } fun stopPlayback(id: String) {