File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
app/src/main/java/com/kylecorry/trailsensecore/infrastructure/time Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package com.kylecorry.trailsensecore.infrastructure.time
2
2
3
3
import android.os.Handler
4
4
import android.os.Looper
5
+ import android.os.SystemClock
5
6
import java.time.Duration
6
7
7
8
class Intervalometer (private val runnable : Runnable ) {
@@ -23,13 +24,17 @@ class Intervalometer(private val runnable: Runnable) {
23
24
runnable.run ()
24
25
val nextRunnable = intervalRunnable
25
26
if (nextRunnable != null ) {
26
- handler.postDelayed (nextRunnable, periodMillis)
27
+ handler.postAtTime (nextRunnable, SystemClock .uptimeMillis() + periodMillis)
27
28
}
28
29
}
29
30
30
31
intervalRunnable = r
31
32
32
- handler.postDelayed(r, initialDelayMillis)
33
+ if (initialDelayMillis == 0L ) {
34
+ handler.post(r)
35
+ } else {
36
+ handler.postAtTime(r, SystemClock .uptimeMillis() + initialDelayMillis)
37
+ }
33
38
}
34
39
35
40
fun interval (period : Duration , initialDelay : Duration = Duration .ZERO ) {
@@ -42,7 +47,11 @@ class Intervalometer(private val runnable: Runnable) {
42
47
}
43
48
44
49
running = true
45
- handler.postDelayed(runnable, delayMillis)
50
+ if (delayMillis == 0L ){
51
+ handler.post(runnable)
52
+ } else {
53
+ handler.postAtTime(runnable, SystemClock .uptimeMillis() + delayMillis)
54
+ }
46
55
}
47
56
48
57
fun once (delay : Duration ) {
You can’t perform that action at this time.
0 commit comments