Skip to content

Commit

Permalink
Fix OffRoute engine cleared before service shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder authored and Guardiola31337 committed Aug 3, 2018
1 parent 844999d commit d363cc6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.services.android.navigation.ui.v5.camera.DynamicCamera;
import com.mapbox.services.android.navigation.ui.v5.feedback.FeedbackItem;
import com.mapbox.services.android.navigation.ui.v5.instruction.BannerInstructionModel;
import com.mapbox.services.android.navigation.ui.v5.instruction.InstructionModel;
Expand All @@ -35,6 +36,7 @@
import com.mapbox.services.android.navigation.v5.navigation.MapboxNavigationOptions;
import com.mapbox.services.android.navigation.v5.navigation.NavigationEventListener;
import com.mapbox.services.android.navigation.v5.navigation.NavigationTimeFormat;
import com.mapbox.services.android.navigation.v5.navigation.camera.Camera;
import com.mapbox.services.android.navigation.v5.navigation.metrics.FeedbackEvent;
import com.mapbox.services.android.navigation.v5.offroute.OffRouteListener;
import com.mapbox.services.android.navigation.v5.route.FasterRouteListener;
Expand Down Expand Up @@ -97,6 +99,11 @@ public void onDestroy(boolean isChangingConfigurations) {
deactivateInstructionPlayer();
endNavigation();
}
Camera cameraEngine = navigation.getCameraEngine();
boolean isDynamicCamera = cameraEngine instanceof DynamicCamera;
if (isDynamicCamera) {
((DynamicCamera) cameraEngine).clearMap();
}
navigationViewEventDispatcher = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public void forceResetZoomLevel() {
forceUpdateZoom = true;
}

public void clearMap() {
mapboxMap = null;
}

/**
* Creates a tilt value based on the distance remaining for the current {@link LegStep}.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public void onDestroy() {
removeProgressChangeListener(null);
removeMilestoneEventListener(null);
removeNavigationEventListener(null);
navigationEngineFactory.clearEngines();
}

// Public APIs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ void updateCameraEngine(Camera cameraEngine) {
this.cameraEngine = cameraEngine;
}

void clearEngines() {
offRouteEngine = null;
fasterRouteEngine = null;
snapEngine = null;
cameraEngine = null;
}

private void initializeDefaultEngines() {
cameraEngine = new SimpleCamera();
snapEngine = new SnapToRoute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.junit.Test;

import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;

public class NavigationEngineFactoryTest {

Expand Down Expand Up @@ -35,42 +34,6 @@ public void onInitialization_defaultFasterRouteEngineIsCreated() {
assertNotNull(provider.retrieveFasterRouteEngine());
}

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

provider.clearEngines();

assertNull(provider.retrieveCameraEngine());
}

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

provider.clearEngines();

assertNull(provider.retrieveOffRouteEngine());
}

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

provider.clearEngines();

assertNull(provider.retrieveSnapEngine());
}

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

provider.clearEngines();

assertNull(provider.retrieveFasterRouteEngine());
}

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

0 comments on commit d363cc6

Please sign in to comment.