Skip to content

Commit b180824

Browse files
committed
Prevent unnecessary refreshview calls
1 parent c7b7522 commit b180824

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
9999

100100
private boolean onOrientationChanged = false;
101101
private boolean populateForCurrentLocation = false;
102+
private boolean isNetworkErrorOccured = false;
102103

103104
@Override
104105
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -126,7 +127,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
126127
super.onViewCreated(view, savedInstanceState);
127128
if (savedInstanceState != null) {
128129
onOrientationChanged = true;
129-
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
130+
Log.d("deneme","onViewCreated");
131+
//refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
130132
}
131133
}
132134

@@ -218,17 +220,22 @@ public void prepareViewsForSheetPosition(int bottomSheetState) {
218220

219221
@Override
220222
public void onLocationChangedSignificantly(LatLng latLng) {
223+
Log.d("deneme","onLocationChangedSignificantly");
221224
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
222225
}
223226

224227
@Override
225228
public void onLocationChangedSlightly(LatLng latLng) {
226-
refreshView(LOCATION_SLIGHTLY_CHANGED);
229+
Log.d("deneme","onLocationChangedSlightly");
230+
231+
refreshView(LOCATION_SLIGHTLY_CHANGED);
227232
}
228233

229234

230235
@Override
231236
public void onLocationChangedMedium(LatLng latLng) {
237+
Log.d("deneme","onLocationChangedMedium");
238+
232239
// For nearby map actions, there are no differences between 500 meter location change (aka medium change) and slight change
233240
refreshView(LOCATION_SLIGHTLY_CHANGED);
234241
}
@@ -237,6 +244,7 @@ public void onLocationChangedMedium(LatLng latLng) {
237244
public void onWikidataEditSuccessful() {
238245
// Do not refresh nearby map if we are checking other areas with search this area button
239246
if (!nearbyMapFragment.searchThisAreaModeOn) {
247+
Log.d("deneme","onWikidateEditSuccesful");
240248
refreshView(MAP_UPDATED);
241249
}
242250
}
@@ -247,6 +255,7 @@ public void onWikidataEditSuccessful() {
247255
* @param locationChangeType defines if location shanged significantly or slightly
248256
*/
249257
public void refreshView(LocationServiceManager.LocationChangeType locationChangeType) {
258+
Log.d("deneme","refreshView");
250259
Timber.d("Refreshing nearby places");
251260
if (lockNearbyView) {
252261
return;
@@ -298,6 +307,7 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange
298307
bundle.clear();
299308
bundle.putString("CurLatLng", gsonCurLatLng);
300309

310+
Log.d("deneme","popuate places is called from here");
301311
placesDisposable = Observable.fromCallable(() -> nearbyController
302312
.loadAttractionsFromLocation(curLatLng, curLatLng, false, true))
303313
.subscribeOn(Schedulers.io())
@@ -331,7 +341,7 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange
331341
* @param customLatLng Custom area which we will search around
332342
*/
333343
public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) {
334-
344+
Log.d("deneme","refreshViewForCutomLocatiom");
335345
if (customLatLng == null) {
336346
// If null, return
337347
return;
@@ -360,6 +370,7 @@ public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshFor
360370
* @param nearbyPlacesInfo This variable has place list information and distances.
361371
*/
362372
private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
373+
Log.d("deneme","populatePlacesFromCustomLocation");
363374
//NearbyMapFragment nearbyMapFragment = getMapFragment();
364375
if (nearbyMapFragment != null) {
365376
nearbyMapFragment.searchThisAreaButtonProgressBar.setVisibility(View.GONE);
@@ -376,6 +387,8 @@ private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo
376387
}
377388

378389
private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
390+
Log.d("deneme","populatePlaces");
391+
379392
Timber.d("Populating nearby places");
380393
List<Place> placeList = nearbyPlacesInfo.placeList;
381394
LatLng[] boundaryCoordinates = nearbyPlacesInfo.boundaryCoordinates;
@@ -428,6 +441,9 @@ private void lockNearbyView(boolean lock) {
428441
}
429442

430443
private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
444+
Log.d("deneme","update Map fragment"+" updateViaButton:"+updateViaButton+", isSlightUpdate:"+isSlightUpdate);
445+
Log.d("deneme","update Map fragment status"+" checking around:"+nearbyMapFragment.checkingAround+", searchThisAreaModeOn:"+nearbyMapFragment.searchThisAreaModeOn+", onOrientationChanged:"+onOrientationChanged);
446+
431447
if (nearbyMapFragment.checkingAround) {
432448
return;
433449
}
@@ -446,11 +462,15 @@ private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate,
446462
* If we are close to nearby places boundaries, we need a significant update to
447463
* get new nearby places. Check order is south, north, west, east
448464
* */
449-
if (nearbyMapFragment.boundaryCoordinates != null && !nearbyMapFragment.searchThisAreaModeOn
450-
&& (curLatLng.getLatitude() <= nearbyMapFragment.boundaryCoordinates[0].getLatitude()
451-
|| curLatLng.getLatitude() >= nearbyMapFragment.boundaryCoordinates[1].getLatitude()
452-
|| curLatLng.getLongitude() <= nearbyMapFragment.boundaryCoordinates[2].getLongitude()
453-
|| curLatLng.getLongitude() >= nearbyMapFragment.boundaryCoordinates[3].getLongitude())) {
465+
if (nearbyMapFragment.boundaryCoordinates != null
466+
&& !nearbyMapFragment.checkingAround
467+
&& !nearbyMapFragment.searchThisAreaModeOn
468+
&& !onOrientationChanged
469+
&& (curLatLng.getLatitude() < nearbyMapFragment.boundaryCoordinates[0].getLatitude()
470+
|| curLatLng.getLatitude() > nearbyMapFragment.boundaryCoordinates[1].getLatitude()
471+
|| curLatLng.getLongitude() < nearbyMapFragment.boundaryCoordinates[2].getLongitude()
472+
|| curLatLng.getLongitude() > nearbyMapFragment.boundaryCoordinates[3].getLongitude())) {
473+
Log.d("deneme","boundary is working");
454474
// populate places
455475
placesDisposable = Observable.fromCallable(() -> nearbyController
456476
.loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton))
@@ -637,6 +657,7 @@ private void checkLocationPermission() {
637657
Timber.d("Checking location permission");
638658
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
639659
if (locationManager.isLocationPermissionGranted()) {
660+
Log.d("deneme","Check location permission if");
640661
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
641662
} else {
642663
// Should we show an explanation?
@@ -663,6 +684,7 @@ private void checkLocationPermission() {
663684
}
664685
}
665686
} else {
687+
Log.d("deneme","Check location permission else");
666688
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
667689
}
668690
}
@@ -681,9 +703,16 @@ private void addNetworkBroadcastReceiver() {
681703
public void onReceive(Context context, Intent intent) {
682704
if (snackbar != null) {
683705
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
684-
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
706+
Log.d("deneme","NetworkUtils.isInternetConnectionEstablished(getActivity())");
707+
if (isNetworkErrorOccured) {
708+
Log.d("deneme","NetworkUtils.isInternetConnectionEstablished(getActivity())");
709+
Log.d("deneme","isNetworkErrorOccured refreshed");
710+
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
711+
isNetworkErrorOccured = false;
712+
}
685713
snackbar.dismiss();
686714
} else {
715+
isNetworkErrorOccured = true;
687716
snackbar.show();
688717
}
689718
}

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ public void onResume() {
10111011
searchThisAreaModeOn = false;
10121012
checkingAround = false;
10131013
searchedAroundCurrentLocation = true;
1014+
boundaryCoordinates = null;
10141015
initViews();
10151016
setListeners();
10161017
transparentView.setClickable(false);

0 commit comments

Comments
 (0)