Skip to content

Commit

Permalink
Add fixes for SimulatedLocationProvider
Browse files Browse the repository at this point in the history
Instead of determining whether or not to start the simulation based on
whether or not the job is null, instead, use the active state of the job
to determine whether or not to start the simulator. This allows the
SimulatedLocationProvider to be reused more than once, and also allows
for addListener to happen before setSimulatedRoute is called without
breaking the simulation.
  • Loading branch information
ahmedre committed Oct 30, 2024
1 parent 065a7d2 commit cd0bdda
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class SimulatedLocationProvider : LocationProvider {
override fun addListener(listener: LocationUpdateListener, executor: Executor) {
listeners.add(listener to executor)

if (simulationJob == null) {
if (simulationJob?.isActive != true) {
simulationJob = scope.launch { startSimulation() }
}
}
Expand All @@ -172,7 +172,7 @@ class SimulatedLocationProvider : LocationProvider {
simulationState = locationSimulationFromRoute(route, resampleDistance = 10.0)
lastLocation = simulationState?.currentLocation

if (listeners.isNotEmpty() && simulationJob == null) {
if (listeners.isNotEmpty() && simulationJob?.isActive != true) {
simulationJob = scope.launch { startSimulation() }
}
}
Expand Down

0 comments on commit cd0bdda

Please sign in to comment.