Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Respsect LocationRequest Parameters #146

Merged
merged 6 commits into from
Jan 6, 2017
Merged

Conversation

sarahsnow1
Copy link
Contributor

Overview

This PR adds support for respecting LocationRequest#getFastestInterval() and LocationRequest#getSmallestDisplacement() when deciding whether to notify listeners/pending intents/callbacks.

Proposed Changes

Now listeners/pending intents/callbacks are invoked if the elapsed time between location updates is greater than/equal to the fastest interval and the distance between the last location reported and the current location is greater than/equal to the smallest displacement in meters.

Closes #142

private Map<PendingIntent, LocationRequest> intentToLocationRequests;
private Map<LocationCallback, LocationRequest> callbackToLocationRequests;
private Map<LocationRequest, Long> requestToLastReportedTime;
private Map<LocationRequest, Location> requestToLastReportedLocation;
Copy link
Collaborator

@ecgreb ecgreb Jan 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace requestToLastReportedTime and requestToLastReportedLocation with a single private instance of ReportedChanges since that seems to encapsulate the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced

return new ReportedChanges(updatedRequestToReportedTime, updatedRequestToReportedLocation);
}

abstract class Notifier<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make Notifier an interface since there is no implementation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, changed to an interface

Copy link
Collaborator

@ecgreb ecgreb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall changes look good. A couple of small comments inline. Were you able to test these changes in a demo app?

I'm thinking we should test the following use cases to ensure correct behavior:

  1. Multiple location clients that each make a single location request with different fastest interval and smallest displacement values (similar to onLocationChanged is called from a LocationRequest of another fragment #142).

  2. We should also test a single client that makes multiple location requests with varying interval and displacement values.

Updates from a single client/request seem still to be working fine so no issues there.

}

abstract class Notifier<T> {
abstract void notify(LostApiClient client, T obj);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

I really like the use of generics to allows us to treat LocationListener, PendingIntent, and LocationCallback objects in a similar fashion when sending location updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

@sarahsnow1
Copy link
Contributor Author

Yep, I did test those things in a dummy app. I'll update our samples to include tests for these now.

private static final int LOCATION_PERMISSION_REQUEST = 1;

LostApiClient lostApiClient;
LostApiClient otherLostApiClient;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the single client example but there are still two clients here?

Given the multiple client activity/fragment example I think it would be more useful to test a single instance of the location client that makes multiple location requests here. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drp...fixed.

@ecgreb ecgreb merged commit 5cf7d66 into master Jan 6, 2017
@ecgreb ecgreb deleted the 142-respsect-request-params branch January 6, 2017 18:06
@ecgreb ecgreb removed the in progress label Jan 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants