Skip to content

Commit

Permalink
Be more precise if the timer is paused and resume.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Jul 13, 2021
1 parent 83bf48d commit c69bc12
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions vector/src/main/java/im/vector/app/core/utils/CountUpTimer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package im.vector.app.core.utils

import io.reactivex.Observable
import timber.log.Timber
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicLong
Expand All @@ -26,11 +27,12 @@ class CountUpTimer(private val intervalInMs: Long) {
private val elapsedTime: AtomicLong = AtomicLong()
private val resumed: AtomicBoolean = AtomicBoolean(false)

private val disposable = Observable.interval(intervalInMs, TimeUnit.MILLISECONDS)
private val disposable = Observable.interval(intervalInMs / 10, TimeUnit.MILLISECONDS)
.filter { resumed.get() }
.doOnNext { elapsedTime.addAndGet(intervalInMs) }
.map { elapsedTime.addAndGet(intervalInMs / 10) }
.filter { it % intervalInMs == 0L }
.subscribe {
tickListener?.onTick(elapsedTime.get())
tickListener?.onTick(it)
}

var tickListener: TickListener? = null
Expand Down

0 comments on commit c69bc12

Please sign in to comment.