Transform TickListener to fun interface
This commit is contained in:
parent
d89ef6988b
commit
392fe6fa32
|
@ -103,15 +103,13 @@ class VideoViewHolder constructor(itemView: View) :
|
|||
views.videoView.setOnPreparedListener {
|
||||
stopTimer()
|
||||
countUpTimer = CountUpTimer(100).also {
|
||||
it.tickListener = object : CountUpTimer.TickListener {
|
||||
override fun onTick(milliseconds: Long) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ class CountUpTimer(private val intervalInMs: Long = 1_000) {
|
|||
coroutineScope.cancel()
|
||||
}
|
||||
|
||||
interface TickListener {
|
||||
fun interface TickListener {
|
||||
fun onTick(milliseconds: Long)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,15 +167,13 @@ class WebRtcCall(
|
|||
private var screenSender: RtpSender? = null
|
||||
|
||||
private val timer = CountUpTimer(1000L).apply {
|
||||
tickListener = object : CountUpTimer.TickListener {
|
||||
override fun onTick(milliseconds: Long) {
|
||||
tickListener = CountUpTimer.TickListener { milliseconds ->
|
||||
val formattedDuration = formatDuration(Duration.ofMillis(milliseconds))
|
||||
listeners.forEach {
|
||||
tryOrNull { it.onTick(formattedDuration) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var inviteTimeout: Deferred<Unit>? = null
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -189,12 +189,10 @@ 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) {
|
||||
tickListener = CountUpTimer.TickListener { milliseconds ->
|
||||
val isLocked = startFromLocked || lastKnownState is RecordingUiState.Locked
|
||||
onRecordingTick(isLocked, milliseconds + startMs)
|
||||
}
|
||||
}
|
||||
resume()
|
||||
}
|
||||
onRecordingTick(startFromLocked, milliseconds = startMs)
|
||||
|
|
|
@ -79,11 +79,9 @@ abstract class LiveLocationUserItem : VectorEpoxyModel<LiveLocationUserItem.Hold
|
|||
}
|
||||
}
|
||||
|
||||
holder.timer.tickListener = object : CountUpTimer.TickListener {
|
||||
override fun onTick(milliseconds: Long) {
|
||||
holder.timer.tickListener = CountUpTimer.TickListener {
|
||||
holder.itemLastUpdatedAtTextView.text = getFormattedLastUpdatedAt(locationUpdateTimeMillis)
|
||||
}
|
||||
}
|
||||
holder.timer.resume()
|
||||
|
||||
holder.view.setOnClickListener { callback?.onUserSelected(matrixItem.id) }
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue