Skip to content

Commit

Permalink
Remove navigation listeners before clearing NavigationEngineFactory (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Jul 23, 2018
1 parent 3a951eb commit 37349a9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
Expand Up @@ -94,8 +94,8 @@ public void onCreate() {
public void onDestroy(boolean isChangingConfigurations) {
if (!isChangingConfigurations) {
locationEngineConductor.onDestroy();
endNavigation();
deactivateInstructionPlayer();
endNavigation();
}
navigationViewEventDispatcher = null;
}
Expand Down
Expand Up @@ -206,14 +206,13 @@ private void disableLocationEngine() {
* also removes all listeners that have been attached.
*/
public void onDestroy() {
Timber.d("MapboxNavigation onDestroy.");
stopNavigation();
disableLocationEngine();
navigationEngineFactory.clearEngines();
removeNavigationEventListener(null);
removeOffRouteListener(null);
removeProgressChangeListener(null);
removeMilestoneEventListener(null);
removeOffRouteListener(null);
removeNavigationEventListener(null);
navigationEngineFactory.clearEngines();
}

// Public APIs
Expand Down
Expand Up @@ -25,6 +25,9 @@ OffRoute retrieveOffRouteEngine() {
}

void updateOffRouteEngine(OffRoute offRouteEngine) {
if (offRouteEngine == null) {
return;
}
this.offRouteEngine = offRouteEngine;
}

Expand All @@ -33,6 +36,9 @@ FasterRoute retrieveFasterRouteEngine() {
}

void updateFasterRouteEngine(FasterRoute fasterRouteEngine) {
if (fasterRouteEngine == null) {
return;
}
this.fasterRouteEngine = fasterRouteEngine;
}

Expand All @@ -41,6 +47,9 @@ Snap retrieveSnapEngine() {
}

void updateSnapEngine(Snap snapEngine) {
if (snapEngine == null) {
return;
}
this.snapEngine = snapEngine;
}

Expand All @@ -49,6 +58,9 @@ Camera retrieveCameraEngine() {
}

void updateCameraEngine(Camera cameraEngine) {
if (cameraEngine == null) {
return;
}
this.cameraEngine = cameraEngine;
}

Expand Down
Expand Up @@ -472,9 +472,9 @@ static boolean isUserOffRoute(NavigationLocationUpdate navigationLocationUpdate,
if (!options.enableOffRouteDetection()) {
return false;
}
Location location = navigationLocationUpdate.location();
OffRoute offRoute = navigationLocationUpdate.mapboxNavigation().getOffRouteEngine();
setOffRouteDetectorCallback(offRoute, callback);
Location location = navigationLocationUpdate.location();
return offRoute.isUserOffRoute(location, routeProgress, options);
}

Expand Down
Expand Up @@ -10,7 +10,6 @@
import com.mapbox.services.android.navigation.v5.milestone.VoiceInstructionMilestone;
import com.mapbox.services.android.navigation.v5.navigation.camera.SimpleCamera;
import com.mapbox.services.android.navigation.v5.offroute.OffRoute;
import com.mapbox.services.android.navigation.v5.offroute.OffRouteDetector;
import com.mapbox.services.android.navigation.v5.snap.Snap;
import com.mapbox.services.android.navigation.v5.snap.SnapToRoute;

Expand Down Expand Up @@ -246,7 +245,7 @@ public void setOffRouteEngine_doesReplaceDefaultEngine() throws Exception {
OffRoute offRoute = mock(OffRoute.class);
navigation.setOffRouteEngine(offRoute);

assertTrue(!(navigation.getOffRouteEngine() instanceof OffRouteDetector));
assertEquals(offRoute, navigation.getOffRouteEngine());
}

@Test
Expand All @@ -262,7 +261,7 @@ public void getCameraEngine_returnsNonNullEngine() throws Exception {
public void getCameraEngine_returnsSimpleCameraWhenNull() throws Exception {
MapboxNavigation navigation = buildMapboxNavigation();

navigation.setOffRouteEngine(null);
navigation.setCameraEngine(null);

assertTrue(navigation.getCameraEngine() instanceof SimpleCamera);
}
Expand Down
Expand Up @@ -70,4 +70,40 @@ public void clearEngines_fasterRouteEngineIsRemoved() {

assertNull(provider.retrieveFasterRouteEngine());
}

@Test
public void updateFasterRouteEngine_ignoresNull() {
NavigationEngineFactory provider = new NavigationEngineFactory();

provider.updateFasterRouteEngine(null);

assertNotNull(provider.retrieveFasterRouteEngine());
}

@Test
public void updateOffRouteEngine_ignoresNull() {
NavigationEngineFactory provider = new NavigationEngineFactory();

provider.updateOffRouteEngine(null);

assertNotNull(provider.retrieveOffRouteEngine());
}

@Test
public void updateCameraEngine_ignoresNull() {
NavigationEngineFactory provider = new NavigationEngineFactory();

provider.updateCameraEngine(null);

assertNotNull(provider.retrieveCameraEngine());
}

@Test
public void updateSnapEngine_ignoresNull() {
NavigationEngineFactory provider = new NavigationEngineFactory();

provider.updateSnapEngine(null);

assertNotNull(provider.retrieveSnapEngine());
}
}

0 comments on commit 37349a9

Please sign in to comment.