From cd0bddaa715072fb3ba0c7ffac0d1ab7ff554a82 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Wed, 30 Oct 2024 23:18:31 +0400 Subject: [PATCH] Add fixes for SimulatedLocationProvider 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. --- .../src/main/java/com/stadiamaps/ferrostar/core/Location.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/core/src/main/java/com/stadiamaps/ferrostar/core/Location.kt b/android/core/src/main/java/com/stadiamaps/ferrostar/core/Location.kt index 827eaa97..d085d40b 100644 --- a/android/core/src/main/java/com/stadiamaps/ferrostar/core/Location.kt +++ b/android/core/src/main/java/com/stadiamaps/ferrostar/core/Location.kt @@ -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() } } } @@ -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() } } }