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

View File

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

View File

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

View File

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

View File

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

View File

@ -79,10 +79,8 @@ abstract class LiveLocationUserItem : VectorEpoxyModel<LiveLocationUserItem.Hold
}
}
holder.timer.tickListener = object : CountUpTimer.TickListener {
override fun onTick(milliseconds: Long) {
holder.itemLastUpdatedAtTextView.text = getFormattedLastUpdatedAt(locationUpdateTimeMillis)
}
holder.timer.tickListener = CountUpTimer.TickListener {
holder.itemLastUpdatedAtTextView.text = getFormattedLastUpdatedAt(locationUpdateTimeMillis)
}
holder.timer.resume()

View File

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