Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions android/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ android {
testOptions {
targetSdk 36
}
lint {
targetSdk 36
}
testOptions {
targetSdk 36
}
}

dependencies {
Expand Down Expand Up @@ -69,6 +63,7 @@ dependencies {
// ValhallaCoreTest.kt
androidTestImplementation libs.okhttp.mock
androidTestImplementation libs.kotlinx.coroutines.test
androidTestImplementation libs.turbine
androidTestImplementation libs.androidx.test.junit
androidTestImplementation libs.androidx.test.espresso
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stadiamaps.ferrostar.core

import com.stadiamaps.ferrostar.core.http.OkHttpClientProvider.Companion.toOkHttpClientProvider
import com.stadiamaps.ferrostar.core.location.SimulatedLocationProvider
import com.stadiamaps.ferrostar.core.service.ForegroundServiceManager
import java.time.Instant
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -453,14 +454,6 @@ class FerrostarCoreTest {
)),
)

locationProvider.lastLocation =
UserLocation(
coordinates = GeographicCoordinate(0.0, 0.0),
horizontalAccuracy = 6.0,
courseOverGround = null,
timestamp = Instant.now(),
speed = null,
)
core.startNavigation(
routes.first(),
NavigationControllerConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package com.stadiamaps.ferrostar.core

import com.stadiamaps.ferrostar.core.http.OkHttpClientProvider.Companion.toOkHttpClientProvider
import com.stadiamaps.ferrostar.core.location.SimulatedLocationProvider
import java.time.Instant
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.test.runTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ package com.stadiamaps.ferrostar.core

import androidx.annotation.VisibleForTesting
import com.stadiamaps.ferrostar.core.http.HttpClientProvider
import com.stadiamaps.ferrostar.core.location.NavigationLocationProviding
import com.stadiamaps.ferrostar.core.location.toAndroidLocation
import com.stadiamaps.ferrostar.core.location.toUserLocation
import com.stadiamaps.ferrostar.core.service.ForegroundServiceManager
import java.time.Instant
import java.util.concurrent.Executors
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import uniffi.ferrostar.GeographicCoordinate
import uniffi.ferrostar.Heading
import uniffi.ferrostar.NavState
import uniffi.ferrostar.NavigationControllerConfig
import uniffi.ferrostar.NavigationSession
Expand Down Expand Up @@ -62,12 +64,12 @@ fun NavigationState.isNavigating(): Boolean =
class FerrostarCore(
val routeProvider: RouteProvider,
val httpClient: HttpClientProvider,
val locationProvider: LocationProvider,
val locationProvider: NavigationLocationProviding,
val foregroundServiceManager: ForegroundServiceManager? = null,
navigationControllerConfig: NavigationControllerConfig,
val sessionBuilder: FerrostarSessionBuilder =
FerrostarSessionBuilder(navigationControllerConfig),
) : LocationUpdateListener {
) {
companion object {
private const val TAG = "FerrostarCore"
}
Expand Down Expand Up @@ -128,8 +130,8 @@ class FerrostarCore(
var isCalculatingNewRoute: Boolean = false
private set

private val _executor = Executors.newSingleThreadScheduledExecutor()
private val _scope = CoroutineScope(Dispatchers.IO)
private var _locationJob: Job? = null

private var _navigationSession: NavigationSession? = null
private val _navState: MutableStateFlow<NavState?> = MutableStateFlow(null)
Expand All @@ -155,7 +157,7 @@ class FerrostarCore(
constructor(
wellKnownRouteProvider: WellKnownRouteProvider,
httpClient: HttpClientProvider,
locationProvider: LocationProvider,
locationProvider: NavigationLocationProviding,
navigationControllerConfig: NavigationControllerConfig,
foregroundServiceManager: ForegroundServiceManager? = null,
) : this(
Expand All @@ -168,7 +170,7 @@ class FerrostarCore(
constructor(
routeAdapter: RouteAdapter,
httpClient: HttpClientProvider,
locationProvider: LocationProvider,
locationProvider: NavigationLocationProviding,
navigationControllerConfig: NavigationControllerConfig,
foregroundServiceManager: ForegroundServiceManager? = null,
) : this(
Expand All @@ -181,7 +183,7 @@ class FerrostarCore(
constructor(
customRouteProvider: CustomRouteProvider,
httpClient: HttpClientProvider,
locationProvider: LocationProvider,
locationProvider: NavigationLocationProviding,
navigationControllerConfig: NavigationControllerConfig,
foregroundServiceManager: ForegroundServiceManager? = null,
) : this(
Expand Down Expand Up @@ -248,8 +250,7 @@ class FerrostarCore(
_navigationSession = navigationSession

val startingLocation =
locationProvider.lastLocation
?: UserLocation(route.geometry.first(), 0.0, null, Instant.now(), null)
_lastLocation ?: UserLocation(route.geometry.first(), 0.0, null, Instant.now(), null)

val initialNavState = navigationSession.getInitialState(startingLocation)
val newState = NavigationState(tripState = initialNavState.tripState, route.geometry, false)
Expand All @@ -258,7 +259,9 @@ class FerrostarCore(
_navState.value = initialNavState
_state.value = newState

locationProvider.addListener(this, _executor)
_locationJob = _scope.launch {
locationProvider.locationUpdates().collect { location -> onLocationUpdated(location.toUserLocation()) }
}
}

/**
Expand All @@ -280,16 +283,17 @@ class FerrostarCore(
_navigationSession = navigationSession

val startingLocation =
locationProvider.lastLocation
?: UserLocation(route.geometry.first(), 0.0, null, Instant.now(), null)
_lastLocation ?: UserLocation(route.geometry.first(), 0.0, null, Instant.now(), null)

val newState = NavigationState(tripState = navState.tripState, route.geometry, false)
handleStateUpdate(navState, startingLocation)

_navState.value = navState
_state.value = newState

locationProvider.addListener(this, _executor)
_locationJob = _scope.launch {
locationProvider.locationUpdates().collect { location -> onLocationUpdated(location.toUserLocation()) }
}
}

/**
Expand All @@ -310,8 +314,7 @@ class FerrostarCore(
_navigationSession = navigationSession

val startingLocation =
locationProvider.lastLocation
?: UserLocation(route.geometry.first(), 0.0, null, Instant.now(), null)
_lastLocation ?: UserLocation(route.geometry.first(), 0.0, null, Instant.now(), null)

_queuedUtteranceIds.clear()
spokenInstructionObserver?.stopAndClearQueue()
Expand Down Expand Up @@ -342,11 +345,10 @@ class FerrostarCore(
}
}

fun stopNavigation(stopLocationUpdates: Boolean = true) {
fun stopNavigation() {
foregroundServiceManager?.stopService()
if (stopLocationUpdates) {
locationProvider.removeListener(this)
}
_locationJob?.cancel()
_locationJob = null
_navigationSession?.destroy()
_navigationSession = null
_state.value = NavigationState()
Expand Down Expand Up @@ -435,7 +437,7 @@ class FerrostarCore(
} ?: true // Default to true if no prior automatic recalculation
}

override fun onLocationUpdated(location: UserLocation) {
private fun onLocationUpdated(location: UserLocation) {
_lastLocation = location
val session = _navigationSession

Expand All @@ -453,9 +455,6 @@ class FerrostarCore(
}
}

override fun onHeadingUpdated(heading: Heading) {
// TODO: Publish new heading to flow
}
}

/**
Expand Down
Loading
Loading