Skip to content

Commit 2c086b3

Browse files
Updating nearby banner on slight location change (commons-app#5459)
1 parent cbf022d commit 2c086b3

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public class ContributionsFragment
118118

119119
private LatLng curLatLng;
120120

121-
private boolean firstLocationUpdate = true;
122121
private boolean isFragmentAttachedBefore = false;
123122
private View checkBoxView;
124123
private CheckBox checkBox;
@@ -453,7 +452,6 @@ public void onSaveInstanceState(Bundle outState) {
453452
public void onResume() {
454453
super.onResume();
455454
contributionsPresenter.onAttachView(this);
456-
firstLocationUpdate = true;
457455
locationManager.addLocationListener(this);
458456
nearbyNotificationCardView.permissionRequestButton.setOnClickListener(v -> {
459457
showNearbyCardPermissionRationale();
@@ -572,22 +570,17 @@ public void onDestroy() {
572570
@Override
573571
public void onLocationChangedSignificantly(LatLng latLng) {
574572
// Will be called if location changed more than 1000 meter
575-
// Do nothing on slight changes for using network efficiently
576-
firstLocationUpdate = false;
577573
updateClosestNearbyCardViewInfo();
578574
}
579575

580576
@Override
581577
public void onLocationChangedSlightly(LatLng latLng) {
582578
/* Update closest nearby notification card onLocationChangedSlightly
583-
If first time to update location after onResume, then no need to wait for significant
584-
location change. Any closest location is better than no location
585579
*/
586-
if (firstLocationUpdate) {
580+
try {
587581
updateClosestNearbyCardViewInfo();
588-
// Turn it to false, since it is not first location update anymore. To change closest location
589-
// notification, we need to wait for a significant location change.
590-
firstLocationUpdate = false;
582+
} catch (Exception e) {
583+
Timber.e(e);
591584
}
592585
}
593586

app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
public class LocationServiceManager implements LocationListener {
2222

2323
// Maybe these values can be improved for efficiency
24-
private static final long MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS = 2 * 60 * 100;
25-
private static final long MIN_LOCATION_UPDATE_REQUEST_DISTANCE_IN_METERS = 10;
24+
private static final long MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS = 10 * 100;
25+
private static final long MIN_LOCATION_UPDATE_REQUEST_DISTANCE_IN_METERS = 1;
2626

2727
private LocationManager locationManager;
2828
private Location lastLocation;

0 commit comments

Comments
 (0)