Make AudioMessagePlaybackTracker.Listener interface funny

This commit is contained in:
Florian Renaud 2022-11-07 11:46:30 +01:00
parent 226e2026a1
commit 6b57b1190c
4 changed files with 20 additions and 26 deletions

View file

@ -148,7 +148,7 @@ class AudioMessagePlaybackTracker @Inject constructor() {
const val RECORDING_ID = "RECORDING_ID"
}
interface Listener {
fun interface Listener {
fun onUpdate(state: State)

View file

@ -140,8 +140,7 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
}
private fun renderStateBasedOnAudioPlayback(holder: Holder) {
audioMessagePlaybackTracker.track(attributes.informationData.eventId, object : AudioMessagePlaybackTracker.Listener {
override fun onUpdate(state: AudioMessagePlaybackTracker.Listener.State) {
audioMessagePlaybackTracker.track(attributes.informationData.eventId) { state ->
when (state) {
is AudioMessagePlaybackTracker.Listener.State.Idle -> renderIdleState(holder)
is AudioMessagePlaybackTracker.Listener.State.Playing -> renderPlayingState(holder, state)
@ -149,7 +148,6 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
is AudioMessagePlaybackTracker.Listener.State.Recording -> Unit
}
}
})
}
private fun renderIdleState(holder: Holder) {

View file

@ -116,14 +116,12 @@ abstract class MessageVoiceBroadcastListeningItem : AbsMessageVoiceBroadcastItem
}
})
}
playbackTracker.track(voiceBroadcast.voiceBroadcastId, object : AudioMessagePlaybackTracker.Listener {
override fun onUpdate(state: State) {
renderBackwardForwardButtons(holder, state)
playbackTracker.track(voiceBroadcast.voiceBroadcastId) { playbackState ->
renderBackwardForwardButtons(holder, playbackState)
if (!isUserSeeking) {
holder.seekBar.progress = playbackTracker.getPlaybackTime(voiceBroadcast.voiceBroadcastId)
}
}
})
}
private fun renderBackwardForwardButtons(holder: Holder, playbackState: State) {

View file

@ -122,8 +122,7 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
true
}
audioMessagePlaybackTracker.track(attributes.informationData.eventId, object : AudioMessagePlaybackTracker.Listener {
override fun onUpdate(state: AudioMessagePlaybackTracker.Listener.State) {
audioMessagePlaybackTracker.track(attributes.informationData.eventId) { state ->
when (state) {
is AudioMessagePlaybackTracker.Listener.State.Idle -> renderIdleState(holder, waveformColorIdle, waveformColorPlayed)
is AudioMessagePlaybackTracker.Listener.State.Playing -> renderPlayingState(holder, state, waveformColorIdle, waveformColorPlayed)
@ -131,7 +130,6 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
is AudioMessagePlaybackTracker.Listener.State.Recording -> Unit
}
}
})
}
private fun getTouchedPositionPercentage(motionEvent: MotionEvent, view: View) = (motionEvent.x / view.width).coerceIn(0f, 1f)