VoiceMessageEvents -> VoiceMessageEvent
This commit is contained in:
parent
9e25db97f7
commit
4f44edf6af
6 changed files with 30 additions and 30 deletions
|
|
@ -53,7 +53,7 @@ import io.element.android.libraries.designsystem.theme.components.IconButton
|
||||||
import io.element.android.libraries.designsystem.theme.components.Text
|
import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
import io.element.android.libraries.ui.utils.time.isTalkbackActive
|
import io.element.android.libraries.ui.utils.time.isTalkbackActive
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageEvents
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageEvent
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageState
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageState
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageStateProvider
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageStateProvider
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
@ -66,7 +66,7 @@ fun TimelineItemVoiceView(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
fun playPause() {
|
fun playPause() {
|
||||||
state.eventSink(VoiceMessageEvents.PlayPause)
|
state.eventSink(VoiceMessageEvent.PlayPause)
|
||||||
}
|
}
|
||||||
|
|
||||||
val a11y = stringResource(CommonStrings.common_voice_message)
|
val a11y = stringResource(CommonStrings.common_voice_message)
|
||||||
|
|
@ -118,7 +118,7 @@ fun TimelineItemVoiceView(
|
||||||
) {
|
) {
|
||||||
PlaybackSpeedButton(
|
PlaybackSpeedButton(
|
||||||
speed = state.playbackSpeed,
|
speed = state.playbackSpeed,
|
||||||
onClick = { state.eventSink(VoiceMessageEvents.ChangePlaybackSpeed) },
|
onClick = { state.eventSink(VoiceMessageEvent.ChangePlaybackSpeed) },
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = state.time,
|
text = state.time,
|
||||||
|
|
@ -137,7 +137,7 @@ fun TimelineItemVoiceView(
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.height(34.dp),
|
.height(34.dp),
|
||||||
seekEnabled = !isTalkbackActive(),
|
seekEnabled = !isTalkbackActive(),
|
||||||
onSeek = { state.eventSink(VoiceMessageEvents.Seek(it)) },
|
onSeek = { state.eventSink(VoiceMessageEvent.Seek(it)) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ import io.element.android.libraries.designsystem.theme.components.Text
|
||||||
import io.element.android.libraries.mediaviewer.impl.model.MediaItem
|
import io.element.android.libraries.mediaviewer.impl.model.MediaItem
|
||||||
import io.element.android.libraries.mediaviewer.impl.model.aMediaItemVoice
|
import io.element.android.libraries.mediaviewer.impl.model.aMediaItemVoice
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageEvents
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageEvent
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageState
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageState
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageStateProvider
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageStateProvider
|
||||||
import io.element.android.libraries.voiceplayer.api.aVoiceMessageState
|
import io.element.android.libraries.voiceplayer.api.aVoiceMessageState
|
||||||
|
|
@ -94,7 +94,7 @@ private fun VoiceInfoRow(
|
||||||
onLongClick: () -> Unit,
|
onLongClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
fun playPause() {
|
fun playPause() {
|
||||||
state.eventSink(VoiceMessageEvents.PlayPause)
|
state.eventSink(VoiceMessageEvent.PlayPause)
|
||||||
}
|
}
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
|
|
@ -128,7 +128,7 @@ private fun VoiceInfoRow(
|
||||||
) {
|
) {
|
||||||
PlaybackSpeedButton(
|
PlaybackSpeedButton(
|
||||||
speed = state.playbackSpeed,
|
speed = state.playbackSpeed,
|
||||||
onClick = { state.eventSink(VoiceMessageEvents.ChangePlaybackSpeed) },
|
onClick = { state.eventSink(VoiceMessageEvent.ChangePlaybackSpeed) },
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = if (state.progress > 0f) state.time else voice.mediaInfo.duration ?: state.time,
|
text = if (state.progress > 0f) state.time else voice.mediaInfo.duration ?: state.time,
|
||||||
|
|
@ -147,7 +147,7 @@ private fun VoiceInfoRow(
|
||||||
playbackProgress = state.progress,
|
playbackProgress = state.progress,
|
||||||
waveform = voice.mediaInfo.waveform.orEmpty().toImmutableList(),
|
waveform = voice.mediaInfo.waveform.orEmpty().toImmutableList(),
|
||||||
onSeek = {
|
onSeek = {
|
||||||
state.eventSink(VoiceMessageEvents.Seek(it))
|
state.eventSink(VoiceMessageEvent.Seek(it))
|
||||||
},
|
},
|
||||||
seekEnabled = true,
|
seekEnabled = true,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
package io.element.android.libraries.voiceplayer.api
|
package io.element.android.libraries.voiceplayer.api
|
||||||
|
|
||||||
sealed interface VoiceMessageEvents {
|
sealed interface VoiceMessageEvent {
|
||||||
data object PlayPause : VoiceMessageEvents
|
data object PlayPause : VoiceMessageEvent
|
||||||
data class Seek(val percentage: Float) : VoiceMessageEvents
|
data class Seek(val percentage: Float) : VoiceMessageEvent
|
||||||
data object ChangePlaybackSpeed : VoiceMessageEvents
|
data object ChangePlaybackSpeed : VoiceMessageEvent
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ data class VoiceMessageState(
|
||||||
val time: String,
|
val time: String,
|
||||||
val showCursor: Boolean,
|
val showCursor: Boolean,
|
||||||
val playbackSpeed: Float,
|
val playbackSpeed: Float,
|
||||||
val eventSink: (event: VoiceMessageEvents) -> Unit,
|
val eventSink: (event: VoiceMessageEvent) -> Unit,
|
||||||
) {
|
) {
|
||||||
enum class Button {
|
enum class Button {
|
||||||
Play,
|
Play,
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import io.element.android.libraries.core.extensions.flatMap
|
||||||
import io.element.android.libraries.core.extensions.runCatchingExceptions
|
import io.element.android.libraries.core.extensions.runCatchingExceptions
|
||||||
import io.element.android.libraries.matrix.api.core.EventId
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.ui.utils.time.formatShort
|
import io.element.android.libraries.ui.utils.time.formatShort
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageEvents
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageEvent
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageException
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageException
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageState
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageState
|
||||||
import io.element.android.services.analytics.api.AnalyticsService
|
import io.element.android.services.analytics.api.AnalyticsService
|
||||||
|
|
@ -87,9 +87,9 @@ class VoiceMessagePresenter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleEvent(event: VoiceMessageEvents) {
|
fun handleEvent(event: VoiceMessageEvent) {
|
||||||
when (event) {
|
when (event) {
|
||||||
is VoiceMessageEvents.PlayPause -> {
|
is VoiceMessageEvent.PlayPause -> {
|
||||||
if (playerState.isPlaying) {
|
if (playerState.isPlaying) {
|
||||||
player.pause()
|
player.pause()
|
||||||
} else if (playerState.isReady) {
|
} else if (playerState.isReady) {
|
||||||
|
|
@ -111,10 +111,10 @@ class VoiceMessagePresenter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is VoiceMessageEvents.Seek -> {
|
is VoiceMessageEvent.Seek -> {
|
||||||
player.seekTo((event.percentage * duration).toLong())
|
player.seekTo((event.percentage * duration).toLong())
|
||||||
}
|
}
|
||||||
is VoiceMessageEvents.ChangePlaybackSpeed -> {
|
is VoiceMessageEvent.ChangePlaybackSpeed -> {
|
||||||
playbackSpeedIndex.intValue = (playbackSpeedIndex.intValue + 1) % VoicePlayerConfig.availablePlaybackSpeeds.size
|
playbackSpeedIndex.intValue = (playbackSpeedIndex.intValue + 1) % VoicePlayerConfig.availablePlaybackSpeeds.size
|
||||||
player.setPlaybackSpeed(VoicePlayerConfig.availablePlaybackSpeeds[playbackSpeedIndex.intValue])
|
player.setPlaybackSpeed(VoicePlayerConfig.availablePlaybackSpeeds[playbackSpeedIndex.intValue])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import io.element.android.libraries.core.mimetype.MimeTypes
|
||||||
import io.element.android.libraries.matrix.api.core.EventId
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.matrix.api.media.MediaSource
|
import io.element.android.libraries.matrix.api.media.MediaSource
|
||||||
import io.element.android.libraries.mediaplayer.test.FakeMediaPlayer
|
import io.element.android.libraries.mediaplayer.test.FakeMediaPlayer
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageEvents
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageEvent
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageException
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageException
|
||||||
import io.element.android.libraries.voiceplayer.api.VoiceMessageState
|
import io.element.android.libraries.voiceplayer.api.VoiceMessageState
|
||||||
import io.element.android.services.analytics.api.AnalyticsService
|
import io.element.android.services.analytics.api.AnalyticsService
|
||||||
|
|
@ -51,7 +51,7 @@ class VoiceMessagePresenterTest {
|
||||||
assertThat(it.time).isEqualTo("0:02")
|
assertThat(it.time).isEqualTo("0:02")
|
||||||
}
|
}
|
||||||
|
|
||||||
initialState.eventSink(VoiceMessageEvents.PlayPause)
|
initialState.eventSink(VoiceMessageEvent.PlayPause)
|
||||||
|
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Downloading)
|
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Downloading)
|
||||||
|
|
@ -87,7 +87,7 @@ class VoiceMessagePresenterTest {
|
||||||
assertThat(it.time).isEqualTo("0:02")
|
assertThat(it.time).isEqualTo("0:02")
|
||||||
}
|
}
|
||||||
|
|
||||||
initialState.eventSink(VoiceMessageEvents.PlayPause)
|
initialState.eventSink(VoiceMessageEvent.PlayPause)
|
||||||
|
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Downloading)
|
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Downloading)
|
||||||
|
|
@ -121,7 +121,7 @@ class VoiceMessagePresenterTest {
|
||||||
assertThat(it.time).isEqualTo("0:02")
|
assertThat(it.time).isEqualTo("0:02")
|
||||||
}
|
}
|
||||||
|
|
||||||
initialState.eventSink(VoiceMessageEvents.PlayPause)
|
initialState.eventSink(VoiceMessageEvent.PlayPause)
|
||||||
skipItems(2) // skip downloading states
|
skipItems(2) // skip downloading states
|
||||||
|
|
||||||
val playingState = awaitItem().also {
|
val playingState = awaitItem().also {
|
||||||
|
|
@ -130,7 +130,7 @@ class VoiceMessagePresenterTest {
|
||||||
assertThat(it.time).isEqualTo("0:01")
|
assertThat(it.time).isEqualTo("0:01")
|
||||||
}
|
}
|
||||||
|
|
||||||
playingState.eventSink(VoiceMessageEvents.PlayPause)
|
playingState.eventSink(VoiceMessageEvent.PlayPause)
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Play)
|
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Play)
|
||||||
assertThat(it.progress).isEqualTo(0.5f)
|
assertThat(it.progress).isEqualTo(0.5f)
|
||||||
|
|
@ -166,7 +166,7 @@ class VoiceMessagePresenterTest {
|
||||||
assertThat(it.time).isEqualTo("0:10")
|
assertThat(it.time).isEqualTo("0:10")
|
||||||
}
|
}
|
||||||
|
|
||||||
initialState.eventSink(VoiceMessageEvents.Seek(0.5f))
|
initialState.eventSink(VoiceMessageEvent.Seek(0.5f))
|
||||||
|
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Play)
|
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Play)
|
||||||
|
|
@ -188,7 +188,7 @@ class VoiceMessagePresenterTest {
|
||||||
assertThat(it.time).isEqualTo("0:10")
|
assertThat(it.time).isEqualTo("0:10")
|
||||||
}
|
}
|
||||||
|
|
||||||
initialState.eventSink(VoiceMessageEvents.PlayPause)
|
initialState.eventSink(VoiceMessageEvent.PlayPause)
|
||||||
|
|
||||||
skipItems(2) // skip downloading states
|
skipItems(2) // skip downloading states
|
||||||
|
|
||||||
|
|
@ -196,7 +196,7 @@ class VoiceMessagePresenterTest {
|
||||||
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Pause)
|
assertThat(it.button).isEqualTo(VoiceMessageState.Button.Pause)
|
||||||
assertThat(it.progress).isEqualTo(0.1f)
|
assertThat(it.progress).isEqualTo(0.1f)
|
||||||
assertThat(it.time).isEqualTo("0:01")
|
assertThat(it.time).isEqualTo("0:01")
|
||||||
it.eventSink(VoiceMessageEvents.Seek(0.5f))
|
it.eventSink(VoiceMessageEvent.Seek(0.5f))
|
||||||
}
|
}
|
||||||
|
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
|
|
@ -215,19 +215,19 @@ class VoiceMessagePresenterTest {
|
||||||
presenter.test {
|
presenter.test {
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
assertThat(it.playbackSpeed).isEqualTo(1.0f)
|
assertThat(it.playbackSpeed).isEqualTo(1.0f)
|
||||||
it.eventSink(VoiceMessageEvents.ChangePlaybackSpeed)
|
it.eventSink(VoiceMessageEvent.ChangePlaybackSpeed)
|
||||||
}
|
}
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
assertThat(it.playbackSpeed).isEqualTo(1.5f)
|
assertThat(it.playbackSpeed).isEqualTo(1.5f)
|
||||||
it.eventSink(VoiceMessageEvents.ChangePlaybackSpeed)
|
it.eventSink(VoiceMessageEvent.ChangePlaybackSpeed)
|
||||||
}
|
}
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
assertThat(it.playbackSpeed).isEqualTo(2.0f)
|
assertThat(it.playbackSpeed).isEqualTo(2.0f)
|
||||||
it.eventSink(VoiceMessageEvents.ChangePlaybackSpeed)
|
it.eventSink(VoiceMessageEvent.ChangePlaybackSpeed)
|
||||||
}
|
}
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
assertThat(it.playbackSpeed).isEqualTo(0.5f)
|
assertThat(it.playbackSpeed).isEqualTo(0.5f)
|
||||||
it.eventSink(VoiceMessageEvents.ChangePlaybackSpeed)
|
it.eventSink(VoiceMessageEvent.ChangePlaybackSpeed)
|
||||||
}
|
}
|
||||||
awaitItem().also {
|
awaitItem().also {
|
||||||
assertThat(it.playbackSpeed).isEqualTo(1.0f)
|
assertThat(it.playbackSpeed).isEqualTo(1.0f)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue