Transform TickListener to fun interface

This commit is contained in:
Florian Renaud 2022-11-04 15:47:10 +01:00
parent d89ef6988b
commit 392fe6fa32
7 changed files with 19 additions and 39 deletions

View File

@ -103,15 +103,13 @@ class VideoViewHolder constructor(itemView: View) :
views.videoView.setOnPreparedListener { views.videoView.setOnPreparedListener {
stopTimer() stopTimer()
countUpTimer = CountUpTimer(100).also { countUpTimer = CountUpTimer(100).also {
it.tickListener = object : CountUpTimer.TickListener { it.tickListener = CountUpTimer.TickListener {
override fun onTick(milliseconds: Long) {
val duration = views.videoView.duration val duration = views.videoView.duration
val progress = views.videoView.currentPosition val progress = views.videoView.currentPosition
val isPlaying = views.videoView.isPlaying val isPlaying = views.videoView.isPlaying
// Log.v("FOO", "isPlaying $isPlaying $progress/$duration") // Log.v("FOO", "isPlaying $isPlaying $progress/$duration")
eventListener?.get()?.onEvent(AttachmentEvents.VideoEvent(isPlaying, progress, duration)) eventListener?.get()?.onEvent(AttachmentEvents.VideoEvent(isPlaying, progress, duration))
} }
}
it.resume() it.resume()
} }
} }

View File

@ -66,7 +66,7 @@ class CountUpTimer(private val intervalInMs: Long = 1_000) {
coroutineScope.cancel() coroutineScope.cancel()
} }
interface TickListener { fun interface TickListener {
fun onTick(milliseconds: Long) fun onTick(milliseconds: Long)
} }
} }

View File

@ -167,15 +167,13 @@ class WebRtcCall(
private var screenSender: RtpSender? = null private var screenSender: RtpSender? = null
private val timer = CountUpTimer(1000L).apply { private val timer = CountUpTimer(1000L).apply {
tickListener = object : CountUpTimer.TickListener { tickListener = CountUpTimer.TickListener { milliseconds ->
override fun onTick(milliseconds: Long) {
val formattedDuration = formatDuration(Duration.ofMillis(milliseconds)) val formattedDuration = formatDuration(Duration.ofMillis(milliseconds))
listeners.forEach { listeners.forEach {
tryOrNull { it.onTick(formattedDuration) } tryOrNull { it.onTick(formattedDuration) }
} }
} }
} }
}
private var inviteTimeout: Deferred<Unit>? = null private var inviteTimeout: Deferred<Unit>? = null

View File

@ -199,11 +199,7 @@ class AudioMessageHelper @Inject constructor(
private fun startRecordingAmplitudes() { private fun startRecordingAmplitudes() {
amplitudeTicker?.stop() amplitudeTicker?.stop()
amplitudeTicker = CountUpTimer(50).apply { amplitudeTicker = CountUpTimer(50).apply {
tickListener = object : CountUpTimer.TickListener { tickListener = CountUpTimer.TickListener { onAmplitudeTick() }
override fun onTick(milliseconds: Long) {
onAmplitudeTick()
}
}
resume() resume()
} }
} }
@ -234,11 +230,7 @@ class AudioMessageHelper @Inject constructor(
private fun startPlaybackTicker(id: String) { private fun startPlaybackTicker(id: String) {
playbackTicker?.stop() playbackTicker?.stop()
playbackTicker = CountUpTimer().apply { playbackTicker = CountUpTimer().apply {
tickListener = object : CountUpTimer.TickListener { tickListener = CountUpTimer.TickListener { onPlaybackTick(id) }
override fun onTick(milliseconds: Long) {
onPlaybackTick(id)
}
}
resume() resume()
} }
onPlaybackTick(id) onPlaybackTick(id)

View File

@ -189,12 +189,10 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
val startMs = ((clock.epochMillis() - startAt)).coerceAtLeast(0) val startMs = ((clock.epochMillis() - startAt)).coerceAtLeast(0)
recordingTicker?.stop() recordingTicker?.stop()
recordingTicker = CountUpTimer().apply { recordingTicker = CountUpTimer().apply {
tickListener = object : CountUpTimer.TickListener { tickListener = CountUpTimer.TickListener { milliseconds ->
override fun onTick(milliseconds: Long) {
val isLocked = startFromLocked || lastKnownState is RecordingUiState.Locked val isLocked = startFromLocked || lastKnownState is RecordingUiState.Locked
onRecordingTick(isLocked, milliseconds + startMs) onRecordingTick(isLocked, milliseconds + startMs)
} }
}
resume() resume()
} }
onRecordingTick(startFromLocked, milliseconds = startMs) onRecordingTick(startFromLocked, milliseconds = startMs)

View File

@ -79,11 +79,9 @@ abstract class LiveLocationUserItem : VectorEpoxyModel<LiveLocationUserItem.Hold
} }
} }
holder.timer.tickListener = object : CountUpTimer.TickListener { holder.timer.tickListener = CountUpTimer.TickListener {
override fun onTick(milliseconds: Long) {
holder.itemLastUpdatedAtTextView.text = getFormattedLastUpdatedAt(locationUpdateTimeMillis) holder.itemLastUpdatedAtTextView.text = getFormattedLastUpdatedAt(locationUpdateTimeMillis)
} }
}
holder.timer.resume() holder.timer.resume()
holder.view.setOnClickListener { callback?.onUserSelected(matrixItem.id) } holder.view.setOnClickListener { callback?.onUserSelected(matrixItem.id) }

View File

@ -362,11 +362,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
fun startPlaybackTicker(id: String) { fun startPlaybackTicker(id: String) {
playbackTicker?.stop() playbackTicker?.stop()
playbackTicker = CountUpTimer().apply { playbackTicker = CountUpTimer().apply {
tickListener = object : CountUpTimer.TickListener { tickListener = CountUpTimer.TickListener { onPlaybackTick(id) }
override fun onTick(milliseconds: Long) {
onPlaybackTick(id)
}
}
resume() resume()
} }
onPlaybackTick(id) onPlaybackTick(id)