Skip to content

Commit 2399e5b

Browse files
committed
NAVAND-979: rename predownloadTrigger into prefetcher
1 parent 556af30 commit 2399e5b

7 files changed

Lines changed: 31 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Mapbox welcomes participation and contributions from everyone.
2929
- Introduced `NavigationViewListener.onSpeedInfoClicked` that would be triggered when `MapboxSpeedInfoView` is clicked upon. [#6770](https://github.com/mapbox/mapbox-navigation-android/pull/6770)
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
- 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)
32+
- 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)
3233
- Enabled voice instructions predownloading for those who use `MapboxAudioGuidance`. [#6771](https://github.com/mapbox/mapbox-navigation-android/pull/6771)
3334
- 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)
3435

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
@@ -169,7 +169,7 @@ internal constructor(
169169

170170
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
171171
private fun MapboxNavigation.audioGuidanceVoice(): Flow<MapboxAudioGuidanceVoice> {
172-
var trigger: VoiceInstructionsDownloadTrigger? = null
172+
var trigger: VoiceInstructionsPrefetcher? = null
173173
return combine(
174174
mapboxVoiceInstructions.voiceLanguage(),
175175
configOwner!!.language(),
@@ -180,7 +180,7 @@ internal constructor(
180180
trigger?.onDetached(this)
181181
audioGuidanceServices.mapboxAudioGuidanceVoice(this, language).also {
182182
audioGuidanceVoice = it
183-
trigger = VoiceInstructionsDownloadTrigger(it.mapboxSpeechApi).also { trigger ->
183+
trigger = VoiceInstructionsPrefetcher(it.mapboxSpeechApi).also { trigger ->
184184
trigger.onAttached(this)
185185
}
186186
}

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/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
}

0 commit comments

Comments
 (0)