mapbox / mapbox-navigation-android

Mapbox Navigation SDK for Android
https://docs.mapbox.com/android/navigation/overview/
Other
620 stars 318 forks source link

[Android Auto] Make the search sdk an optional dependency #5786

Closed kmadsen closed 1 year ago

kmadsen commented 2 years ago

For the first developer release of androidauto-v0.1.0 we are including the search SDK. But a request has already been made to have search be optional within the SDK. This ticket is arguable, if it gains support we will do it but there are some risks to going with this approach. Runtime checks using reflection are always risky solutions.

This can be done by changing the search sdk dependency to compileOnly

- api(dependenciesList.mapboxSearchSdk)
+ compileOnly(dependenciesList.mapboxSearchSdk)

But this also requires runtime checks to ensure the classes exist. Before opening search or favorite options, the android auto sdk will need to check if the class exists.

kmadsen commented 1 year ago

This has been resolved by https://github.com/mapbox/mapbox-navigation-android/pull/6429.

Now you can swap in your own search screen.

mapboxScreenManager.prepareScreens(mapboxCarContext)
     .set(MapboxScreen.MAPBOX_SEARCH, MySearchScreenFactory())

// Now you use your own route preview screen
class MySearchScreenFactory : MapboxScreenFactory {
    override fun create(carContext: CarContext): Screen {
        return MySearchScreen(carContext)
    }
}

Or you can build your an entirely unique screen graph

fun MapboxCarContext.prepareScreens() = apply {
    val mapboxCarContext = this
    mapboxScreenManager.putAll(
        NEEDS_LOCATION_PERMISSION
            to NeedsLocationPermissionScreenFactory(),
        SETTINGS
            to SettingsScreenFactory(mapboxCarContext),
        FREE_DRIVE
            to FreeDriveScreenFactory(mapboxCarContext),
        MY_SEACH_SCREEN to MySearchScreenFactory()
...
    )
}
kmadsen commented 1 year ago

We do not plan on changing to compileOnly(dependenciesList.mapboxSearchSdk) unless there are requests

It is implementation and the search quota is guarded by Mapbox Access Tokens