Updating nearby banner on slight location change (#5459)

This commit is contained in:
Shashwat Kedia 2024-01-21 14:31:16 +05:30 committed by GitHub
parent cbf022d2f2
commit 2c086b3d79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 12 deletions

View file

@ -118,7 +118,6 @@ public class ContributionsFragment
private LatLng curLatLng;
private boolean firstLocationUpdate = true;
private boolean isFragmentAttachedBefore = false;
private View checkBoxView;
private CheckBox checkBox;
@ -453,7 +452,6 @@ public class ContributionsFragment
public void onResume() {
super.onResume();
contributionsPresenter.onAttachView(this);
firstLocationUpdate = true;
locationManager.addLocationListener(this);
nearbyNotificationCardView.permissionRequestButton.setOnClickListener(v -> {
showNearbyCardPermissionRationale();
@ -572,22 +570,17 @@ public class ContributionsFragment
@Override
public void onLocationChangedSignificantly(LatLng latLng) {
// Will be called if location changed more than 1000 meter
// Do nothing on slight changes for using network efficiently
firstLocationUpdate = false;
updateClosestNearbyCardViewInfo();
}
@Override
public void onLocationChangedSlightly(LatLng latLng) {
/* Update closest nearby notification card onLocationChangedSlightly
If first time to update location after onResume, then no need to wait for significant
location change. Any closest location is better than no location
*/
if (firstLocationUpdate) {
try {
updateClosestNearbyCardViewInfo();
// Turn it to false, since it is not first location update anymore. To change closest location
// notification, we need to wait for a significant location change.
firstLocationUpdate = false;
} catch (Exception e) {
Timber.e(e);
}
}

View file

@ -21,8 +21,8 @@ import timber.log.Timber;
public class LocationServiceManager implements LocationListener {
// Maybe these values can be improved for efficiency
private static final long MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS = 2 * 60 * 100;
private static final long MIN_LOCATION_UPDATE_REQUEST_DISTANCE_IN_METERS = 10;
private static final long MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS = 10 * 100;
private static final long MIN_LOCATION_UPDATE_REQUEST_DISTANCE_IN_METERS = 1;
private LocationManager locationManager;
private Location lastLocation;