mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Add smooth animation to voice messages play progress (#7698)
* Add linear animation to voice message playback progress Instead of animating the small `progress` value changes, calculate an animation for the range `maxProgress - progress`, with a linear interpolator so it's completely smooth. Previously, the progress was updated in 'steps' that were quite noticeable.
This commit is contained in:
+2
@@ -13,7 +13,9 @@ data class VoiceMessageState(
|
||||
val progress: Float,
|
||||
val time: String,
|
||||
val showCursor: Boolean,
|
||||
val isPlaying: Boolean,
|
||||
val playbackSpeed: Float,
|
||||
val durationMs: Long,
|
||||
val eventSink: (event: VoiceMessageEvent) -> Unit,
|
||||
) {
|
||||
enum class ButtonType {
|
||||
|
||||
+6
@@ -34,6 +34,8 @@ open class VoiceMessageStatePreviewParam : PreviewParameterProvider<VoiceMessage
|
||||
progress = 0.2f,
|
||||
time = "10:00",
|
||||
showCursor = true,
|
||||
isPlaying = true,
|
||||
durationMs = 0,
|
||||
),
|
||||
aVoiceMessageState(
|
||||
VoiceMessageState.ButtonType.Disabled,
|
||||
@@ -48,12 +50,16 @@ fun aVoiceMessageState(
|
||||
progress: Float = 0f,
|
||||
time: String = "1:00",
|
||||
showCursor: Boolean = false,
|
||||
isPlaying: Boolean = false,
|
||||
playbackSpeed: Float = 1.0f,
|
||||
durationMs: Long = 60_000,
|
||||
) = VoiceMessageState(
|
||||
buttonType = buttonType,
|
||||
progress = progress,
|
||||
time = time,
|
||||
showCursor = showCursor,
|
||||
isPlaying = isPlaying,
|
||||
playbackSpeed = playbackSpeed,
|
||||
durationMs = durationMs,
|
||||
eventSink = {},
|
||||
)
|
||||
|
||||
+2
@@ -135,7 +135,9 @@ class VoiceMessagePresenter(
|
||||
progress = progress,
|
||||
time = time,
|
||||
showCursor = showCursor,
|
||||
isPlaying = playerState.isPlaying,
|
||||
playbackSpeed = VoicePlayerConfig.availablePlaybackSpeeds[playbackSpeedIndex],
|
||||
durationMs = duration,
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
}
|
||||
|
||||
+2
@@ -34,6 +34,8 @@ class VoiceMessagePresenterTest {
|
||||
assertThat(it.buttonType).isEqualTo(VoiceMessageState.ButtonType.Play)
|
||||
assertThat(it.progress).isEqualTo(0f)
|
||||
assertThat(it.time).isEqualTo("1:01")
|
||||
assertThat(it.isPlaying).isFalse()
|
||||
assertThat(it.durationMs).isEqualTo(61_000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user