Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix same location update calls #65

Merged
merged 2 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public UpdateRequest(LocationManager locationManager, LocationListener locationL
this.locationListener = locationListener;
}

public boolean isRequiredImmediately() {
return minTime == 0;
}

public void run(String provider, long minTime, float minDistance) {
this.provider = provider;
this.minTime = minTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,14 @@ public void onLocationChanged(Location location) {
// no need to switch or call fail
getSourceProvider().getProviderSwitchTask().stop();

// Remove update requests if it is running for immediate request
if (getSourceProvider().getUpdateRequest().isRequiredImmediately() || !getConfiguration().keepTracking()) {
getSourceProvider().removeLocationUpdates(this);
}

if (getConfiguration().keepTracking()) {
requestUpdateLocation(getConfiguration().defaultProviderConfiguration().requiredTimeInterval(),
getConfiguration().defaultProviderConfiguration().requiredDistanceInterval(), false);
} else {
getSourceProvider().removeLocationUpdates(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,19 @@ public void onLocationChangedShouldStopSwitchTask() {
verify(continuousTask).stop();
}

@Test
public void onLocationChangedShouldRemoveUpdatesWhenRequiredImmediately() {
when(locationConfiguration.keepTracking()).thenReturn(true);
when(updateRequest.isRequiredImmediately()).thenReturn(true);

defaultLocationProvider.onLocationChanged(DUMMY_LOCATION);

verify(defaultLocationSource).removeLocationUpdates(defaultLocationProvider);
}

@Test
public void onLocationChangedShouldRemoveUpdatesWhenKeepTrackingIsFalse() {
when(updateRequest.isRequiredImmediately()).thenReturn(false);
when(locationConfiguration.keepTracking()).thenReturn(false);

defaultLocationProvider.onLocationChanged(DUMMY_LOCATION);
Expand Down