Skip to content

Commit 0a465cc

Browse files
committed
NAVAND-979: rename predownloadTrigger into prefetcher
1 parent bdda630 commit 0a465cc

File tree

10 files changed

+42
-41
lines changed

10 files changed

+42
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Mapbox welcomes participation and contributions from everyone.
3030
- Each newly instantiated MapboxRouteArrowView class will initialize the layers with the provided options on the first render call. Previously this would only be done if the layers hadn't already been initialized. [#6466](https://github.com/mapbox/mapbox-navigation-android/pull/6466)
3131
- Fixed an issue where the first voice instruction might have been played twice. [#6766](https://github.com/mapbox/mapbox-navigation-android/pull/6766)
3232
- Introduced `VoiceInstructionsDownloadTrigger` `MapboxSpeechAPI#generatePredownloaded` to use predownloaded voice instructions instead of downloading them on demand. Example usage can be found in the examples directory ( see `MapboxVoiceActivity`). [#6771](https://github.com/mapbox/mapbox-navigation-android/pull/6771)
33+
- Introduced `VoiceInstructionsPrefetcher` `MapboxSpeechAPI#generatePredownloaded` to use predownloaded voice instructions instead of downloading them on demand. Example usage can be found in the examples directory ( see `MapboxVoiceActivity`). [#6771](https://github.com/mapbox/mapbox-navigation-android/pull/6771)
3334
- Enabled voice instructions predownloading for those who use `MapboxAudioGuidance`. [#6771](https://github.com/mapbox/mapbox-navigation-android/pull/6771)
3435
- Fixed an issue where with low connectivity voice instruction might have been played too late for those who use `MapboxAudioGuidance`. If you use `MapboxSpeechAPI` directly, switch to voice instructions predownloading as described above if you encounter said issue. [#6771](https://github.com/mapbox/mapbox-navigation-android/pull/6771)
3536

examples/src/main/java/com/mapbox/navigation/examples/core/MapboxVoiceActivity.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import com.mapbox.navigation.ui.utils.internal.resource.ResourceLoadRequest
6161
import com.mapbox.navigation.ui.utils.internal.resource.ResourceLoaderFactory
6262
import com.mapbox.navigation.ui.voice.api.MapboxSpeechApi
6363
import com.mapbox.navigation.ui.voice.api.MapboxVoiceInstructionsPlayer
64-
import com.mapbox.navigation.ui.voice.api.VoiceInstructionsDownloadTrigger
64+
import com.mapbox.navigation.ui.voice.api.VoiceInstructionsPrefetcher
6565
import com.mapbox.navigation.ui.voice.model.SpeechAnnouncement
6666
import com.mapbox.navigation.ui.voice.model.SpeechError
6767
import com.mapbox.navigation.ui.voice.model.SpeechValue
@@ -204,8 +204,8 @@ class MapboxVoiceActivity : AppCompatActivity(), OnMapLongClickListener {
204204
}
205205

206206
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
207-
private val voiceInstructionsDownloadTrigger by lazy {
208-
VoiceInstructionsDownloadTrigger(speechApi)
207+
private val voiceInstructionsPrefetcher by lazy {
208+
VoiceInstructionsPrefetcher(speechApi)
209209
}
210210

211211
private val voiceInstructionsObserver =
@@ -397,7 +397,7 @@ class MapboxVoiceActivity : AppCompatActivity(), OnMapLongClickListener {
397397
if (::mapboxNavigation.isInitialized) {
398398
mapboxNavigation.registerRoutesObserver(routesObserver)
399399
mapboxNavigation.registerLocationObserver(locationObserver)
400-
voiceInstructionsDownloadTrigger.onAttached(mapboxNavigation)
400+
voiceInstructionsPrefetcher.onAttached(mapboxNavigation)
401401
mapboxNavigation.registerRouteProgressObserver(routeProgressObserver)
402402
mapboxNavigation.registerRouteProgressObserver(replayProgressObserver)
403403
mapboxNavigation.registerVoiceInstructionsObserver(voiceInstructionsObserver)
@@ -410,7 +410,7 @@ class MapboxVoiceActivity : AppCompatActivity(), OnMapLongClickListener {
410410
super.onStop()
411411
ResourceLoaderFactory.getInstance().unregisterObserver(resourceLoadObserver)
412412
mapboxNavigation.unregisterRoutesObserver(routesObserver)
413-
voiceInstructionsDownloadTrigger.onDetached(mapboxNavigation)
413+
voiceInstructionsPrefetcher.onDetached(mapboxNavigation)
414414
mapboxNavigation.unregisterLocationObserver(locationObserver)
415415
mapboxNavigation.unregisterRouteProgressObserver(routeProgressObserver)
416416
mapboxNavigation.unregisterRouteProgressObserver(replayProgressObserver)
@@ -425,7 +425,7 @@ class MapboxVoiceActivity : AppCompatActivity(), OnMapLongClickListener {
425425
mapboxReplayer.finish()
426426
mapboxNavigation.onDestroy()
427427
speechApi.cancel()
428-
voiceInstructionsDownloadTrigger.destroy()
428+
voiceInstructionsPrefetcher.destroy()
429429
voiceInstructionsPlayer.shutdown()
430430
}
431431

libnavui-voice/api/current.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,26 @@ package com.mapbox.navigation.ui.voice.api {
8585
method @kotlin.jvm.Throws(exceptionClasses=IllegalArgumentException::class) public void volume(com.mapbox.navigation.ui.voice.model.SpeechVolume state) throws java.lang.IllegalArgumentException;
8686
}
8787

88-
@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public final class VoiceInstructionsDownloadTrigger implements com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver {
89-
ctor public VoiceInstructionsDownloadTrigger(com.mapbox.navigation.ui.voice.api.MapboxSpeechApi speechApi);
90-
ctor public VoiceInstructionsDownloadTrigger(int observableTime, double timePercentageToTriggerAfter, com.mapbox.navigation.ui.voice.api.MapboxSpeechApi speechApi);
88+
public abstract sealed class VoiceInstructionsPlayerAttributes {
89+
method protected abstract kotlin.jvm.functions.Function1<android.media.AudioFocusRequest.Builder,kotlin.Unit> configureAudioFocusRequestBuilder(com.mapbox.navigation.ui.voice.model.AudioFocusOwner owner);
90+
method protected abstract kotlin.jvm.functions.Function1<android.media.MediaPlayer,kotlin.Unit> configureMediaPlayer();
91+
method protected abstract kotlin.jvm.functions.Function2<android.speech.tts.TextToSpeech,android.os.Bundle,kotlin.Unit> configureTextToSpeech();
92+
method public abstract com.mapbox.navigation.ui.voice.options.VoiceInstructionsPlayerOptions getOptions();
93+
property public abstract com.mapbox.navigation.ui.voice.options.VoiceInstructionsPlayerOptions options;
94+
}
95+
96+
@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public final class VoiceInstructionsPrefetcher implements com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver {
97+
ctor public VoiceInstructionsPrefetcher(com.mapbox.navigation.ui.voice.api.MapboxSpeechApi speechApi);
98+
ctor public VoiceInstructionsPrefetcher(int observableTime, double timePercentageToTriggerAfter, com.mapbox.navigation.ui.voice.api.MapboxSpeechApi speechApi);
9199
method public void destroy();
92100
method public void onAttached(com.mapbox.navigation.core.MapboxNavigation mapboxNavigation);
93101
method public void onDetached(com.mapbox.navigation.core.MapboxNavigation mapboxNavigation);
94-
field public static final com.mapbox.navigation.ui.voice.api.VoiceInstructionsDownloadTrigger.Companion Companion;
102+
field public static final com.mapbox.navigation.ui.voice.api.VoiceInstructionsPrefetcher.Companion Companion;
95103
field public static final int DEFAULT_OBSERVABLE_TIME_SECONDS = 180; // 0xb4
96104
field public static final double DEFAULT_TIME_PERCENTAGE_TO_TRIGGER_AFTER = 0.5;
97105
}
98106

99-
public static final class VoiceInstructionsDownloadTrigger.Companion {
100-
}
101-
102-
public abstract sealed class VoiceInstructionsPlayerAttributes {
103-
method protected abstract kotlin.jvm.functions.Function1<android.media.AudioFocusRequest.Builder,kotlin.Unit> configureAudioFocusRequestBuilder(com.mapbox.navigation.ui.voice.model.AudioFocusOwner owner);
104-
method protected abstract kotlin.jvm.functions.Function1<android.media.MediaPlayer,kotlin.Unit> configureMediaPlayer();
105-
method protected abstract kotlin.jvm.functions.Function2<android.speech.tts.TextToSpeech,android.os.Bundle,kotlin.Unit> configureTextToSpeech();
106-
method public abstract com.mapbox.navigation.ui.voice.options.VoiceInstructionsPlayerOptions getOptions();
107-
property public abstract com.mapbox.navigation.ui.voice.options.VoiceInstructionsPlayerOptions options;
107+
public static final class VoiceInstructionsPrefetcher.Companion {
108108
}
109109

110110
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ internal constructor(
165165

166166
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
167167
private fun MapboxNavigation.audioGuidanceVoice(): Flow<MapboxAudioGuidanceVoice> {
168-
var trigger: VoiceInstructionsDownloadTrigger? = null
168+
var trigger: VoiceInstructionsPrefetcher? = null
169169
return combine(
170170
mapboxVoiceInstructions.voiceLanguage(),
171171
configOwner!!.language(),
@@ -176,7 +176,7 @@ internal constructor(
176176
trigger?.onDetached(this)
177177
audioGuidanceServices.mapboxAudioGuidanceVoice(this, language).also {
178178
audioGuidanceVoice = it
179-
trigger = VoiceInstructionsDownloadTrigger(it.mapboxSpeechApi).also { trigger ->
179+
trigger = VoiceInstructionsPrefetcher(it.mapboxSpeechApi).also { trigger ->
180180
trigger.onAttached(this)
181181
}
182182
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MapboxSpeechApi @JvmOverloads constructor(
4242
* voice instruction [SpeechAnnouncement] including the synthesized speech mp3 file
4343
* from Mapbox's API Voice.
4444
* NOTE: this method will try downloading an mp3 file from server. If you use voice instructions
45-
* predownloading (see [VoiceInstructionsDownloadTrigger]), invoke [generatePredownloaded]
45+
* predownloading (see [VoiceInstructionsPrefetcher]), invoke [generatePredownloaded]
4646
* instead of this method in your [VoiceInstructionsObserver].
4747
* @param voiceInstruction VoiceInstructions object representing [VoiceInstructions]
4848
* @param consumer is a [SpeechValue] including the announcement to be played when the
@@ -65,7 +65,7 @@ class MapboxSpeechApi @JvmOverloads constructor(
6565
* from Mapbox's API Voice.
6666
* NOTE: this method will NOT try downloading an mp3 file from server. It will either use
6767
* an already predownloaded file or an onboard speech synthesizer. Only invoke this method
68-
* if you use voice instructions predownloading (see [VoiceInstructionsDownloadTrigger]),
68+
* if you use voice instructions predownloading (see [VoiceInstructionsPrefetcher]),
6969
* otherwise invoke [generatePredownloaded] in your [VoiceInstructionsObserver].
7070
* @param voiceInstruction VoiceInstructions object representing [VoiceInstructions]
7171
* @param consumer is a [SpeechValue] including the announcement to be played when the

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import com.mapbox.navigation.utils.internal.ifNonNull
2020
* or invoke [onAttached] and [onDetached] manually if you are not using [MapboxNavigationApp].
2121
*/
2222
@ExperimentalPreviewMapboxNavigationAPI
23-
class VoiceInstructionsDownloadTrigger internal constructor(
23+
class VoiceInstructionsPrefetcher internal constructor(
2424
private val observableTime: Int,
2525
private val timePercentageToTriggerAfter: Double,
2626
private val speechApi: MapboxSpeechApi,
@@ -29,7 +29,7 @@ class VoiceInstructionsDownloadTrigger internal constructor(
2929
) : MapboxNavigationObserver {
3030

3131
/**
32-
* Creates [VoiceInstructionsDownloadTrigger] with default
32+
* Creates [VoiceInstructionsPrefetcher] with default
3333
* observableTime and timePercentageToTriggerAfter.
3434
* See [DEFAULT_OBSERVABLE_TIME_SECONDS] and [DEFAULT_TIME_PERCENTAGE_TO_TRIGGER_AFTER].
3535
*
@@ -42,7 +42,7 @@ class VoiceInstructionsDownloadTrigger internal constructor(
4242
)
4343

4444
/**
45-
* Creates [VoiceInstructionsDownloadTrigger] with custom
45+
* Creates [VoiceInstructionsPrefetcher] with custom
4646
* observableTime and timePercentageToTriggerAfter.
4747
*
4848
* @param observableTime voice instructions will be predownloaded for `observableTime` seconds

libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/TestMapboxAudioGuidanceServices.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TestMapboxAudioGuidanceServices(
3636

3737
private val mapboxSpeechApi = mockk<MapboxSpeechApi>(relaxed = true)
3838

39-
private val mapboxAudioGuidanceVoice = mockk<MapboxAudioGuidanceVoice> {
39+
val mapboxAudioGuidanceVoice = mockk<MapboxAudioGuidanceVoice> {
4040
coEvery { speak(any()) } coAnswers {
4141
val voiceInstructions = firstArg<VoiceInstructions?>()
4242
val speechAnnouncement: SpeechAnnouncement? = voiceInstructions?.let {

libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/api/MapboxVoiceApiTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ import java.io.InputStream
2222
internal class MapboxVoiceApiTest {
2323

2424
private lateinit var sut: MapboxVoiceApi
25-
private lateinit var mockSpeechLoder: MapboxSpeechLoader
25+
private lateinit var mockSpeechLoader: MapboxSpeechLoader
2626
private lateinit var mockSpeechFileProvider: MapboxSpeechFileProvider
2727

2828
@Before
2929
fun setUp() {
30-
mockSpeechLoder = mockk(relaxed = true)
30+
mockSpeechLoader = mockk(relaxed = true)
3131
mockSpeechFileProvider = mockk(relaxed = true)
3232

33-
sut = MapboxVoiceApi(mockSpeechLoder, mockSpeechFileProvider)
33+
sut = MapboxVoiceApi(mockSpeechLoader, mockSpeechFileProvider)
3434
}
3535

3636
@Test
3737
fun `retrieveVoiceFile should download audio data using MapboxSpeechProvider`() = runBlocking {
3838
val voiceInstructions = Fixtures.ssmlInstructions()
39-
coEvery { mockSpeechLoder.load(any(), any()) } returns ExpectedFactory.createError(Error())
39+
coEvery { mockSpeechLoader.load(any(), any()) } returns ExpectedFactory.createError(Error())
4040

4141
sut.retrieveVoiceFile(voiceInstructions, true)
4242

43-
coVerify { mockSpeechLoder.load(voiceInstructions, true) }
43+
coVerify { mockSpeechLoader.load(voiceInstructions, true) }
4444
}
4545

4646
@Test
@@ -49,7 +49,7 @@ internal class MapboxVoiceApiTest {
4949
val voiceInstructions = Fixtures.ssmlInstructions()
5050
val blob = byteArrayOf(11, 22)
5151
val blobInputStream = slot<InputStream>()
52-
coEvery { mockSpeechLoder.load(any(), false) } returns ExpectedFactory.createValue(blob)
52+
coEvery { mockSpeechLoader.load(any(), false) } returns ExpectedFactory.createValue(blob)
5353
coEvery {
5454
mockSpeechFileProvider.generateVoiceFileFrom(capture(blobInputStream))
5555
} returns File("ignored")
@@ -65,7 +65,7 @@ internal class MapboxVoiceApiTest {
6565
val voiceInstructions = Fixtures.ssmlInstructions()
6666
val blob = byteArrayOf(11, 22)
6767
val file = File("saved-audio-file")
68-
coEvery { mockSpeechLoder.load(any(), true) } returns ExpectedFactory.createValue(blob)
68+
coEvery { mockSpeechLoader.load(any(), true) } returns ExpectedFactory.createValue(blob)
6969
coEvery { mockSpeechFileProvider.generateVoiceFileFrom(any()) } returns file
7070

7171
val result = sut.retrieveVoiceFile(voiceInstructions, true)
@@ -78,7 +78,7 @@ internal class MapboxVoiceApiTest {
7878
runBlocking {
7979
val voiceInstructions = Fixtures.emptyInstructions()
8080
coEvery {
81-
mockSpeechLoder.load(any(), false)
81+
mockSpeechLoader.load(any(), false)
8282
} returns ExpectedFactory.createError(Error())
8383
coEvery { mockSpeechFileProvider.generateVoiceFileFrom(any()) } throws Error()
8484

@@ -144,6 +144,6 @@ internal class MapboxVoiceApiTest {
144144
fun `destroy cancels speech loader`() {
145145
sut.destroy()
146146

147-
verify { mockSpeechLoder.cancel() }
147+
verify { mockSpeechLoader.cancel() }
148148
}
149149
}

libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/api/VoiceInstructionsDownloadTriggerTest.kt renamed to libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/api/VoiceInstructionsPrefetcherTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.junit.Before
2424
import org.junit.Test
2525

2626
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
27-
class VoiceInstructionsDownloadTriggerTest {
27+
class VoiceInstructionsPrefetcherTest {
2828

2929
private val observableTime = 100
3030
private val timePercentageToTriggerAfter = 0.5
@@ -42,7 +42,7 @@ class VoiceInstructionsDownloadTriggerTest {
4242
VoiceInstructions.builder().announcement("ann2").build()
4343
)
4444
private val currentTimeSeconds = 9988L
45-
private val sut = VoiceInstructionsDownloadTrigger(
45+
private val sut = VoiceInstructionsPrefetcher(
4646
observableTime,
4747
timePercentageToTriggerAfter,
4848
speechAPI,
@@ -387,12 +387,12 @@ class VoiceInstructionsDownloadTriggerTest {
387387
private fun validLegProgress(
388388
stepProgress: RouteStepProgress? = validStepProgress()
389389
): RouteLegProgress = mockk {
390-
every { legIndex } returns this@VoiceInstructionsDownloadTriggerTest.legIndex
390+
every { legIndex } returns this@VoiceInstructionsPrefetcherTest.legIndex
391391
every { currentStepProgress } returns stepProgress
392392
}
393393

394394
private fun validStepProgress(): RouteStepProgress = mockk {
395-
every { stepIndex } returns this@VoiceInstructionsDownloadTriggerTest.stepIndex
395+
every { stepIndex } returns this@VoiceInstructionsPrefetcherTest.stepIndex
396396
every { distanceRemaining } returns stepDistanceRemaining
397397
every { durationRemaining } returns stepDurationRemaining
398398
}

libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/internal/impl/MapboxAudioGuidanceVoiceTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class MapboxAudioGuidanceVoiceTest {
106106

107107
@Test
108108
fun destroy() {
109-
carAppAudioGuidanceVoice.destroy()
109+
sut.destroy()
110110

111111
verify { speechApi.destroy() }
112112
}

0 commit comments

Comments
 (0)