diff --git a/android/core/src/main/java/com/stadiamaps/ferrostar/core/NavigationViewModel.kt b/android/core/src/main/java/com/stadiamaps/ferrostar/core/NavigationViewModel.kt index f1c0e364..718fe658 100644 --- a/android/core/src/main/java/com/stadiamaps/ferrostar/core/NavigationViewModel.kt +++ b/android/core/src/main/java/com/stadiamaps/ferrostar/core/NavigationViewModel.kt @@ -19,6 +19,7 @@ import uniffi.ferrostar.UserLocation import uniffi.ferrostar.VisualInstruction data class NavigationUiState( + val location: UserLocation?, val snappedLocation: UserLocation?, val heading: Float?, val routeGeometry: List, @@ -33,10 +34,12 @@ data class NavigationUiState( fun fromFerrostar( coreState: NavigationState, isMuted: Boolean?, - userLocation: UserLocation? + location: UserLocation?, + snappedLocation: UserLocation? ): NavigationUiState = NavigationUiState( - snappedLocation = userLocation, + snappedLocation = snappedLocation, + location = location, // TODO: Heading/course over ground heading = null, routeGeometry = coreState.routeGeometry, @@ -60,22 +63,22 @@ interface NavigationViewModel { class DefaultNavigationViewModel( private val ferrostarCore: FerrostarCore, private val spokenInstructionObserver: SpokenInstructionObserver? = null, - locationProvider: LocationProvider + private val locationProvider: LocationProvider ) : ViewModel(), NavigationViewModel { - private var lastLocation: UserLocation? = locationProvider.lastLocation + private var snappedLocation: UserLocation? = locationProvider.lastLocation override val uiState = ferrostarCore.state .map { coreState -> - lastLocation = + val location = locationProvider.lastLocation + snappedLocation = when (coreState.tripState) { is TripState.Navigating -> coreState.tripState.snappedUserLocation is TripState.Complete, TripState.Idle -> locationProvider.lastLocation } - - uiState(coreState, spokenInstructionObserver?.isMuted, lastLocation) + uiState(coreState, spokenInstructionObserver?.isMuted, location, snappedLocation) // This awkward dance is required because Kotlin doesn't have a way to map over // StateFlows // without converting to a generic Flow in the process. @@ -85,7 +88,7 @@ class DefaultNavigationViewModel( started = SharingStarted.WhileSubscribed(), initialValue = uiState( - ferrostarCore.state.value, spokenInstructionObserver?.isMuted, lastLocation)) + ferrostarCore.state.value, spokenInstructionObserver?.isMuted, locationProvider.lastLocation, locationProvider.lastLocation)) override fun stopNavigation() { ferrostarCore.stopNavigation() @@ -99,6 +102,6 @@ class DefaultNavigationViewModel( spokenInstructionObserver.isMuted = !spokenInstructionObserver.isMuted } - private fun uiState(coreState: NavigationState, isMuted: Boolean?, location: UserLocation?) = - NavigationUiState.fromFerrostar(coreState, isMuted, location) + private fun uiState(coreState: NavigationState, isMuted: Boolean?, location: UserLocation?, snappedLocation: UserLocation?) = + NavigationUiState.fromFerrostar(coreState, isMuted, location, snappedLocation) } diff --git a/android/core/src/main/java/com/stadiamaps/ferrostar/core/mock/MockNavigationState.kt b/android/core/src/main/java/com/stadiamaps/ferrostar/core/mock/MockNavigationState.kt index 116612d8..68b1d992 100644 --- a/android/core/src/main/java/com/stadiamaps/ferrostar/core/mock/MockNavigationState.kt +++ b/android/core/src/main/java/com/stadiamaps/ferrostar/core/mock/MockNavigationState.kt @@ -60,7 +60,7 @@ fun NavigationState.Companion.pedestrianExample(): NavigationState { } fun NavigationUiState.Companion.pedestrianExample(): NavigationUiState = - fromFerrostar(NavigationState.pedestrianExample(), false, UserLocation.pedestrianExample()) + fromFerrostar(NavigationState.pedestrianExample(), false, UserLocation.pedestrianExample(), UserLocation.pedestrianExample()) class MockNavigationViewModel(override val uiState: StateFlow) : ViewModel(), NavigationViewModel {