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

Respsect LocationRequest Parameters - #146

Merged
ecgreb merged 6 commits into
masterfrom
142-respsect-request-params
Jan 6, 2017
Merged

ecgreb merged 6 commits into
masterfrom
142-respsect-request-params

Conversation

@sarahcodes100

Copy link
Copy Markdown
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;

@ecgreb ecgreb Jan 3, 2017 •

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@ecgreb ecgreb left a comment

Copy link
Copy Markdown
Collaborator

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 #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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

😄

@sarahcodes100

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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