Skip to content

Commit 88eae2b

Browse files
committed
NAVAND-899: introduce MapboxNavigation#moveRoutesFromPreviewToNavigator
1 parent 618c615 commit 88eae2b

6 files changed

Lines changed: 57 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ This release depends on, and has been tested with, the following Mapbox dependen
4646

4747
- Added `DecodeUtils#clearCache` to allow trigger route geometry cache clearing in order to reduce memory usage.
4848
- Started clearing route geometry cache when no routes (neither routes used for Active Guidance nor previewed ones) are available.
49+
- Added `DecodeUtils#clearCache` to allow trigger route geometry cache clearing in order to reduce memory usage. [#6617](https://github.com/mapbox/mapbox-navigation-android/pull/6617)
50+
- Started clearing route geometry cache when no routes (neither routes used for Active Guidance nor previewed ones) are available. [#6617](https://github.com/mapbox/mapbox-navigation-android/pull/6617)
51+
- Added convenience `MapboxNavigation#moveRoutesFromPreviewToNavigator` method to simplify transition from Routes Preview state to Active Guidance state. [#6617](https://github.com/mapbox/mapbox-navigation-android/pull/6617)
4952

5053
## Mapbox Navigation SDK 2.9.1 - 11 November, 2022
5154
### Changelog

libnavigation-base/src/main/java/com/mapbox/navigation/base/utils/DecodeUtils.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ object DecodeUtils {
122122
return stepsGeometryDecodeCache.getOrDecode(legStep.geometry(), precision)
123123
}
124124

125+
/**
126+
* Clears the caches that were filled by invoking
127+
* [stepGeometryToPoints], [completeGeometryToPoints], etc.
128+
*/
125129
@JvmStatic
126130
fun clearCache() {
127131
synchronized(stepsGeometryDecodeCache) {

libnavigation-core/api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ package com.mapbox.navigation.core {
3333
method public Integer? getZLevel();
3434
method public boolean isDestroyed();
3535
method public boolean isRunningForegroundService();
36+
method @com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI @kotlin.jvm.Throws(exceptionClasses=IllegalArgumentException::class) public void moveRoutesFromPreviewToNavigator() throws java.lang.IllegalArgumentException;
3637
method public void navigateNextRouteLeg(com.mapbox.navigation.core.trip.session.LegIndexUpdatedCallback callback);
3738
method public void onDestroy();
3839
method @com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public void onEVDataUpdated(java.util.Map<java.lang.String,java.lang.String> data);

libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,27 @@ class MapboxNavigation @VisibleForTesting internal constructor(
896896
routesPreviewController.changeRoutesPreviewPrimaryRoute(newPrimaryRoute)
897897
}
898898

899+
/**
900+
* Convenience method that takes previewed routes and sets them to Navigator,
901+
* clearing the previewed routes afterwards.
902+
* Equivalent to:
903+
* ```
904+
* mapboxNavigation.setNavigationRoutes(mapboxNavigation.getRoutesPreview()!!.routesList)
905+
* mapboxNavigation.setRoutesPreview(emptyList())
906+
* ```
907+
* @throws IllegalArgumentException when previewed routes are empty.
908+
*/
909+
@Throws(IllegalArgumentException::class)
910+
@ExperimentalPreviewMapboxNavigationAPI
911+
fun moveRoutesFromPreviewToNavigator() {
912+
val preview = getRoutesPreview()
913+
requireNotNull(preview) {
914+
"Can't move routes from preview to navigator as no previewed routes are available"
915+
}
916+
setNavigationRoutes(preview.routesList)
917+
setRoutesPreview(emptyList())
918+
}
919+
899920
/***
900921
* Registers [RoutesPreviewObserver] to be notified when routes preview state changes.
901922
* [observer] is immediately called with current preview state

libnavigation-core/src/test/java/com/mapbox/navigation/core/MapboxNavigationTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.mapbox.navigation.core.internal.extensions.registerHistoryRecordingSt
2121
import com.mapbox.navigation.core.internal.extensions.unregisterHistoryRecordingStateChangeObserver
2222
import com.mapbox.navigation.core.internal.telemetry.NavigationCustomEventType
2323
import com.mapbox.navigation.core.navigator.CacheHandleWrapper
24+
import com.mapbox.navigation.core.preview.RoutesPreview
2425
import com.mapbox.navigation.core.reroute.NavigationRerouteController
2526
import com.mapbox.navigation.core.reroute.RerouteController
2627
import com.mapbox.navigation.core.reroute.RerouteState
@@ -1768,4 +1769,28 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() {
17681769
evDataHolder.updateData(data)
17691770
}
17701771
}
1772+
1773+
@Test(expected = IllegalArgumentException::class)
1774+
fun moveRoutesFromPreviewToNavigatorNoPreviewedRoutes() {
1775+
createMapboxNavigation()
1776+
every { routesPreviewController.getRoutesPreview() } returns null
1777+
1778+
mapboxNavigation.moveRoutesFromPreviewToNavigator()
1779+
}
1780+
1781+
@Test
1782+
fun moveRoutesFromPreviewToNavigatorHasPreviewedRoutes() = coroutineRule.runBlockingTest {
1783+
val routes = listOf<NavigationRoute>(mockk())
1784+
createMapboxNavigation()
1785+
every {
1786+
routesPreviewController.getRoutesPreview()
1787+
} returns RoutesPreview(routes, emptyList(), listOf(mockk()), 0)
1788+
1789+
mapboxNavigation.moveRoutesFromPreviewToNavigator()
1790+
1791+
coVerifyOrder {
1792+
tripSession.setRoutes(routes, any())
1793+
routesPreviewController.previewNavigationRoutes(emptyList())
1794+
}
1795+
}
17711796
}

qa-test-app/src/main/java/com/mapbox/navigation/qa_test_app/view/RoutesPreviewActivity.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,16 +485,15 @@ class RoutesPreviewActivity : AppCompatActivity() {
485485
visibility = View.VISIBLE
486486
setOnClickListener {
487487
visibility = View.GONE
488-
setRouteAndStartNavigation(mapboxNavigation.getRoutesPreview()!!.routesList)
489-
mapboxNavigation.setRoutesPreview(emptyList())
488+
setRouteAndStartNavigation()
490489
}
491490
}
492491
mapboxNavigation.setRoutesPreview(routes)
493492
}
494493

495-
private fun setRouteAndStartNavigation(route: List<NavigationRoute>) {
494+
private fun setRouteAndStartNavigation() {
496495
// set route
497-
mapboxNavigation.setNavigationRoutes(route)
496+
mapboxNavigation.moveRoutesFromPreviewToNavigator()
498497

499498
// show UI elements
500499
binding.soundButton.visibility = View.VISIBLE

0 commit comments

Comments
 (0)