From 6283846108dac7bf6bb82a0683cf5293490fcab2 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 13 Jul 2021 15:54:09 +0200 Subject: [PATCH] Cleanup --- .../detail/composer/VoiceMessageHelper.kt | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt index 2c53140d4a..68a07225ed 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/VoiceMessageHelper.kt @@ -206,27 +206,21 @@ class VoiceMessageHelper @Inject constructor( playbackTimer = CountUpTimer().apply { tickListener = object : CountUpTimer.TickListener { override fun onTick(milliseconds: Long) { - onPlaybackTimerTick(id, false) + onPlaybackTimerTick(id) } } resume() } - onPlaybackTimerTick(id, true) + onPlaybackTimerTick(id) } - private fun onPlaybackTimerTick(id: String, firstCall: Boolean) { - when { - firstCall -> { - playbackTracker.updateCurrentPlaybackTime(id, 0) - } - mediaPlayer?.isPlaying.orFalse() -> { - val currentPosition = mediaPlayer?.currentPosition ?: 0 - playbackTracker.updateCurrentPlaybackTime(id, currentPosition) - } - else -> { - playbackTracker.stopPlayback(id) - stopPlaybackTimer() - } + private fun onPlaybackTimerTick(id: String) { + if (mediaPlayer?.isPlaying.orFalse()) { + val currentPosition = mediaPlayer?.currentPosition ?: 0 + playbackTracker.updateCurrentPlaybackTime(id, currentPosition) + } else { + playbackTracker.stopPlayback(id) + stopPlaybackTimer() } }