Skip to content

Commit a8c2e1a

Browse files
committed
NAVAND-713: simplify API
1 parent 22210f3 commit a8c2e1a

File tree

8 files changed

+40
-142
lines changed

8 files changed

+40
-142
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone.
55
## Unreleased
66
#### Features
77
- Added support for EV route refresh. [#6511](https://github.com/mapbox/mapbox-navigation-android/pull/6511)
8+
- Added `MapboxNavigation#onEVDataUpdated` method to be invoked by the end user to notify Navigation SDK of EV data changes so that it can be used in refresh requests. [#6511](https://github.com/mapbox/mapbox-navigation-android/pull/6511)
89
#### Bug fixes and improvements
910
- Improved experience in tunnels and reduced the likelihood of losing road edge matching candidates. [#6510](https://github.com/mapbox/mapbox-navigation-android/pull/6510)
1011
- Fixed an issue with `NavigationView` that caused road label position to not update in some cases. [#6508](https://github.com/mapbox/mapbox-navigation-android/pull/6508)

libnavigation-core/api/current.txt

+1-10
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ package com.mapbox.navigation.core {
1010
method public void onDeveloperMetadataChanged(com.mapbox.navigation.core.DeveloperMetadata metadata);
1111
}
1212

13-
@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public fun interface EVDataObserver {
14-
method public void onEVDataUpdated(java.util.Map<java.lang.String,java.lang.String> data);
15-
}
16-
17-
@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public interface EVDataUpdater {
18-
method public void registerEVDataObserver(com.mapbox.navigation.core.EVDataObserver observer);
19-
method public void unregisterEVDataObserver(com.mapbox.navigation.core.EVDataObserver observer);
20-
}
21-
2213
@UiThread public final class MapboxNavigation {
2314
ctor public MapboxNavigation(com.mapbox.navigation.base.options.NavigationOptions navigationOptions);
2415
method public void cancelRouteRequest(long requestId);
@@ -42,6 +33,7 @@ package com.mapbox.navigation.core {
4233
method public boolean isRunningForegroundService();
4334
method public void navigateNextRouteLeg(com.mapbox.navigation.core.trip.session.LegIndexUpdatedCallback callback);
4435
method public void onDestroy();
36+
method @com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public void onEVDataUpdated(java.util.Map<java.lang.String,java.lang.String> data);
4537
method public void postUserFeedback(String feedbackType, String description, @com.mapbox.navigation.core.telemetry.events.FeedbackEvent.Source String feedbackSource, String screenshot, String![]? feedbackSubType = emptyArray());
4638
method public void postUserFeedback(String feedbackType, String description, @com.mapbox.navigation.core.telemetry.events.FeedbackEvent.Source String feedbackSource, String screenshot);
4739
method @com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public void postUserFeedback(String feedbackType, String description, @com.mapbox.navigation.core.telemetry.events.FeedbackEvent.Source String feedbackSource, String screenshot, String![]? feedbackSubType = emptyArray(), com.mapbox.navigation.core.telemetry.events.FeedbackMetadata feedbackMetadata);
@@ -72,7 +64,6 @@ package com.mapbox.navigation.core {
7264
method public void resetTripSession();
7365
method public void setArrivalController(com.mapbox.navigation.core.arrival.ArrivalController? arrivalController = com.mapbox.navigation.core.arrival.AutoArrivalController());
7466
method public void setArrivalController();
75-
method @com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public void setEVDataUpdater(com.mapbox.navigation.core.EVDataUpdater? updater);
7667
method public void setNavigationRoutes(java.util.List<com.mapbox.navigation.base.route.NavigationRoute> routes, int initialLegIndex = 0, com.mapbox.navigation.core.RoutesSetCallback? callback = null);
7768
method public void setNavigationRoutes(java.util.List<com.mapbox.navigation.base.route.NavigationRoute> routes, int initialLegIndex = 0);
7869
method public void setNavigationRoutes(java.util.List<com.mapbox.navigation.base.route.NavigationRoute> routes);

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

-63
This file was deleted.

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

+26-8
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,6 @@ class MapboxNavigation @VisibleForTesting internal constructor(
10571057
reachabilityObserverId = null
10581058
}
10591059
routeRefreshController.unregisterAllRouteRefreshStateObservers()
1060-
routeRefreshRequestDataProvider.destroy()
10611060

10621061
isDestroyed = true
10631062
hasInstance = false
@@ -1667,16 +1666,35 @@ class MapboxNavigation @VisibleForTesting internal constructor(
16671666
}
16681667

16691668
/**
1670-
* Provide a [EVDataUpdater] that will notify Nav SDK of EV data updates
1671-
* to be used in route refresh requests.
1672-
* Set to null to stop providing updates.
1673-
* NOTE: after setting the updater to null the last saved state will be used in refresh requests.
1669+
* Invoke when any component of EV data is changed so that it can be used in refresh requests.
1670+
* Pass **only changed** components of EV data via [data].
1671+
* Example: if you previously invoked this method with the following map:
1672+
* ```
1673+
* mapOf(
1674+
* "ev_initial_charge" to "90",
1675+
* "energy_consumption_curve" to "0,300;20,120;40,150",
1676+
* "auxiliary_consumption" to "300"
1677+
* )
1678+
* ```
1679+
* and then the charge changes to 80, you can invoke this method with only
1680+
* ```
1681+
* mapOf("ev_initial_charge" to "80")
1682+
* ```
1683+
* as an argument. This way "ev_initial_charge" will be updated and the following parameters
1684+
* will be used from the previous invocation.
1685+
* If you want to remove a parameter, pass `null` for the corresponding key.
1686+
* Example: for the case above if you want to remove "auxiliary_consumption", invoke this method
1687+
* with
1688+
* ```
1689+
* mapOf("auxiliary_consumption" to null)
1690+
* ```
1691+
* as an argument.
16741692
*
1675-
* @param updater [EVDataUpdater] that will notify Nav SDK of EV data updates
1693+
* @param data Map describing the changed EV data
16761694
*/
16771695
@ExperimentalPreviewMapboxNavigationAPI
1678-
fun setEVDataUpdater(updater: EVDataUpdater?) {
1679-
routeRefreshRequestDataProvider.setEVDataUpdater(updater)
1696+
fun onEVDataUpdated(data: Map<String, String?>) {
1697+
routeRefreshRequestDataProvider.onEVDataUpdated(data)
16801698
}
16811699

16821700
private fun startSession(withTripService: Boolean, withReplayEnabled: Boolean) {

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ internal data class RouteProgressData(
1919
/**
2020
* Accumulates and provides route refresh model data from different sources.
2121
*/
22-
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
2322
@MainThread
2423
internal class RouteRefreshRequestDataProvider(
2524
private val evDataHolder: EVDataHolder = EVDataHolder()
@@ -28,7 +27,6 @@ internal class RouteRefreshRequestDataProvider(
2827
private val defaultRouteProgressData = RouteProgressData(0, 0, null)
2928
private var routeProgressData: RouteProgressData? = null
3029
private var continuation: CancellableContinuation<RouteProgressData>? = null
31-
private var evDataUpdater: EVDataUpdater? = null
3230

3331
/**
3432
* Returns either last saved value (if has one) or waits for the next update.
@@ -51,14 +49,8 @@ internal class RouteRefreshRequestDataProvider(
5149
routeProgressData = null
5250
}
5351

54-
fun destroy() {
55-
evDataUpdater?.unregisterEVDataObserver(evDataHolder)
56-
}
57-
58-
fun setEVDataUpdater(updater: EVDataUpdater?) {
59-
evDataUpdater?.unregisterEVDataObserver(evDataHolder)
60-
evDataUpdater = updater
61-
updater?.registerEVDataObserver(evDataHolder)
52+
fun onEVDataUpdated(data: Map<String, String?>) {
53+
evDataHolder.onEVDataUpdated(data)
6254
}
6355

6456
override fun onRouteProgressChanged(routeProgress: RouteProgress) {

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package com.mapbox.navigation.core.routerefresh
22

3-
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
4-
import com.mapbox.navigation.core.EVDataObserver
5-
6-
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
7-
internal class EVDataHolder : EVDataObserver {
3+
internal class EVDataHolder {
84

95
private val currentData = mutableMapOf<String, String>()
106

117
@Synchronized
12-
override fun onEVDataUpdated(data: Map<String, String?>) {
8+
fun onEVDataUpdated(data: Map<String, String?>) {
139
data.forEach { (key, value) ->
1410
if (value == null) {
1511
currentData.remove(key)

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

+4-15
Original file line numberDiff line numberDiff line change
@@ -1734,25 +1734,14 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() {
17341734
}
17351735

17361736
@Test
1737-
fun setEVDataUpdater() {
1738-
val updater = mockk<EVDataUpdater>(relaxed = true)
1737+
fun onEVDataChanged() {
1738+
val data = mapOf("aaa" to "bbb")
17391739
createMapboxNavigation()
17401740

1741-
mapboxNavigation.setEVDataUpdater(updater)
1741+
mapboxNavigation.onEVDataUpdated(data)
17421742

17431743
verify(exactly = 1) {
1744-
routeRefreshRequestDataProvider.setEVDataUpdater(updater)
1745-
}
1746-
}
1747-
1748-
@Test
1749-
fun onDestroyDestroysRouteRefreshRequestDataProvider() {
1750-
createMapboxNavigation()
1751-
1752-
mapboxNavigation.onDestroy()
1753-
1754-
verify(exactly = 1) {
1755-
routeRefreshRequestDataProvider.destroy()
1744+
routeRefreshRequestDataProvider.onEVDataUpdated(data)
17561745
}
17571746
}
17581747
}

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

+4-30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mapbox.navigation.core
22

3-
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
43
import com.mapbox.navigation.base.internal.RouteRefreshRequestData
54
import com.mapbox.navigation.base.trip.model.RouteProgress
65
import com.mapbox.navigation.core.routerefresh.EVDataHolder
@@ -207,36 +206,11 @@ class RouteRefreshRequestDataProviderTest {
207206
assertEquals(expected, provider.getRouteRefreshRequestDataOrWait())
208207
}
209208

210-
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
211209
@Test
212-
fun setEVDataUpdater() {
213-
val firstUpdater = mockk<EVDataUpdater>(relaxed = true)
214-
val secondUpdater = mockk<EVDataUpdater>(relaxed = true)
215-
provider.setEVDataUpdater(firstUpdater)
210+
fun onEVDataUpdated() {
211+
val data = mapOf("aaa" to "bbb")
212+
provider.onEVDataUpdated(data)
216213

217-
verify(exactly = 1) { firstUpdater.registerEVDataObserver(evDataHolder) }
218-
219-
provider.setEVDataUpdater(secondUpdater)
220-
221-
verify(exactly = 1) {
222-
firstUpdater.unregisterEVDataObserver(evDataHolder)
223-
secondUpdater.registerEVDataObserver(evDataHolder)
224-
}
225-
}
226-
227-
@Test
228-
fun destroyWithoutUpdater() {
229-
provider.destroy()
230-
}
231-
232-
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
233-
@Test
234-
fun destroyWithUpdater() {
235-
val updater = mockk<EVDataUpdater>(relaxed = true)
236-
provider.setEVDataUpdater(updater)
237-
238-
provider.destroy()
239-
240-
verify { updater.unregisterEVDataObserver(evDataHolder) }
214+
verify(exactly = 1) { evDataHolder.onEVDataUpdated(data) }
241215
}
242216
}

0 commit comments

Comments
 (0)