Skip to content

Conversation

@kmadsen
Copy link
Contributor

@kmadsen kmadsen commented Sep 23, 2022

Description

Addressing #6141

This needs to be done before this one #6371

Migrating CarRouteRequest to use MapboxNavigationObserver

@kmadsen kmadsen added the Android Auto Bugs, improvements and feature requests on Android Auto. label Sep 23, 2022
@kmadsen kmadsen requested a review from a team as a code owner September 23, 2022 01:35
@kmadsen kmadsen force-pushed the km-migrate-CarRouteRequest branch from 8bcb928 to 6962b9b Compare September 23, 2022 01:46
@codecov
Copy link

codecov bot commented Sep 23, 2022

Codecov Report

Merging #6372 (185dd0e) into main (df05b41) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##               main    #6372   +/-   ##
=========================================
  Coverage     68.95%   68.95%           
  Complexity     4579     4579           
=========================================
  Files           691      691           
  Lines         27382    27382           
  Branches       3191     3191           
=========================================
  Hits          18881    18881           
  Misses         7262     7262           
  Partials       1239     1239           

*/
fun request(placeRecord: PlaceRecord, callback: CarRouteRequestCallback) {
currentRequestId?.let { mapboxNavigation.cancelRouteRequest(it) }
val mapboxNavigation = this.mapboxNavigation ?: return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use !! here?

Copy link
Contributor Author

@kmadsen kmadsen Sep 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this a lot, and established an opinion. I agree with you that there should be a signal that the request did not happen. But I'm hesitant with crashing here. Considering that this is just one new type of many possible failures. I think the error should be sent to CarRouteRequestCallback. So for now it's sending it to onNoRoutesFound

Copy link
Contributor Author

@kmadsen kmadsen Sep 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguable that this is a developer error so it should crash. But there are other developer errors that will not crash, for example if the interceptor provides impossible parameters.

Also you may want to request routes from things that are not lifecycle aware. The CarRouteRequest is lifecycle aware so the caller does not have to be 🤔

object SomeUtility {
--snip--
  fun goToNextDestination(placeRecord) {
    MapboxNavigationApp.getObserver(CarRouteRequest::class).request(placeRecord, callback)
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then the reason why it's good to always have a callback respond. Is because otherwise people will build "infinite spinners"

// simplified version of the callback to illustrate the point.
// stopLoading would not be called if the `CarRouteRequest` is detached.
spinner.startLoading()
MapboxNavigationApp.getObserver(CarRouteRequest::class).request(placeRecord) {
  spinner.stopLoading()
}

@kmadsen kmadsen force-pushed the km-migrate-CarRouteRequest branch from 6962b9b to fe95912 Compare September 23, 2022 18:14
@kmadsen kmadsen force-pushed the km-migrate-CarRouteRequest branch from fe95912 to d6bae3b Compare September 23, 2022 21:02
@kmadsen kmadsen enabled auto-merge (squash) September 23, 2022 21:41
@kmadsen kmadsen merged commit 420d326 into main Sep 23, 2022
@kmadsen kmadsen deleted the km-migrate-CarRouteRequest branch September 23, 2022 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android Auto Bugs, improvements and feature requests on Android Auto.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants