Skip to content

Commit

Permalink
Check for changing config only if activity is finishing
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Jan 16, 2018
1 parent 745ce4a commit 4f16ba9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class NavigationActivity extends AppCompatActivity implements OnNavigationReadyCallback, NavigationListener {

private NavigationView navigationView;
private boolean isConfigurationChange;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -31,6 +32,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
navigationView = findViewById(R.id.navigationView);
navigationView.onCreate(savedInstanceState);
navigationView.getNavigationAsync(this);
isConfigurationChange = savedInstanceState != null;
}

@Override
Expand Down Expand Up @@ -69,8 +71,10 @@ protected void onDestroy() {
public void onNavigationReady() {
NavigationViewOptions.Builder options = NavigationViewOptions.builder();
options.navigationListener(this);
extractRoute(options);
extractCoordinates(options);
if (!isConfigurationChange) {
extractRoute(options);
extractCoordinates(options);
}
extractConfiguration(options);
navigationView.startNavigation(options.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ public void endNavigation() {
context.unbindService(this);
isBound = false;
navigationEventDispatcher.onNavigationEvent(false);
navigationTelemetry.endSession();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ public void onActivityPaused(Activity activity) {

@Override
public void onActivityDestroyed(Activity activity) {
if (activity.isChangingConfigurations()) {
NavigationTelemetry.getInstance().onConfigurationChange();
}
if (activity.isFinishing()) {
NavigationTelemetry.getInstance().endSession(activity.isChangingConfigurations());
activity.getApplication().unregisterActivityLifecycleCallbacks(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ void initialize(@NonNull Context context, @NonNull String accessToken,

validateAccessToken(accessToken);

// Setup the listeners
initEventDispatcherListeners(navigation);

MapboxNavigationOptions options = navigation.options();
// Set sdkIdentifier based on if from UI or not
String sdkIdentifier = updateSdkIdentifier(options);
Expand All @@ -168,6 +165,8 @@ void initialize(@NonNull Context context, @NonNull String accessToken,

isInitialized = true;
}
// Setup the listeners
initEventDispatcherListeners(navigation);
}

/**
Expand Down Expand Up @@ -200,16 +199,16 @@ void startSession(DirectionsRoute directionsRoute) {
.mockLocation(metricLocation.getLocation().getProvider().equals(MOCK_PROVIDER))
.rerouteCount(0)
.build();
} else {
isConfigurationChange = false;
}
isConfigurationChange = false;
}

/**
* Flushes any remaining events from the reroute / feedback queue and fires
* a cancel event indicating a terminated session.
*/
void endSession() {
void endSession(boolean isConfigurationChange) {
this.isConfigurationChange = isConfigurationChange;
if (!isConfigurationChange) {
if (navigationSessionState.startTimestamp() != null) {
flushEventQueues();
Expand Down Expand Up @@ -274,10 +273,6 @@ void updateLocationEngine(LocationEngine locationEngine) {
}
}

void onConfigurationChange() {
isConfigurationChange = true;
}

/**
* Creates a new {@link FeedbackEvent} and adds it to the queue
* of events to be sent.
Expand Down

0 comments on commit 4f16ba9

Please sign in to comment.