Skip to content

Commit 6916cb5

Browse files
committed
NAVAND-552: use elapsed time to check prefetching interval
1 parent 9942395 commit 6916cb5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
package com.mapbox.navigation.utils.internal
22

3+
import android.os.SystemClock
34
import java.util.concurrent.TimeUnit
45

56
interface Time {
7+
68
fun nanoTime(): Long
9+
710
fun millis(): Long
8-
fun seconds(): Long
911

12+
fun seconds(): Long
1013
object SystemImpl : Time {
1114
override fun nanoTime(): Long = System.nanoTime()
1215

1316
override fun millis(): Long = System.currentTimeMillis()
1417

1518
override fun seconds(): Long = TimeUnit.MILLISECONDS.toSeconds(millis())
1619
}
20+
21+
object SystemClockImpl : Time {
22+
override fun nanoTime(): Long = SystemClock.elapsedRealtimeNanos()
23+
24+
override fun millis(): Long = SystemClock.elapsedRealtime()
25+
26+
override fun seconds(): Long = TimeUnit.MILLISECONDS.toSeconds(seconds())
27+
}
1728
}

libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/api/VoiceInstructionsPrefetcher.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class VoiceInstructionsPrefetcher internal constructor(
2626
private val timePercentageToTriggerAfter: Double,
2727
private val nextVoiceInstructionsProvider: NextVoiceInstructionsProvider =
2828
TimeBasedNextVoiceInstructionsProvider(observableTime),
29-
private val timeProvider: Time = Time.SystemImpl,
29+
private val timeProvider: Time = Time.SystemClockImpl,
3030
) : MapboxNavigationObserver {
3131

3232
/**

0 commit comments

Comments
 (0)