Add lock neabry method to unlisten nearby operations during updates

This commit is contained in:
neslihanturan 2019-05-17 18:38:22 +03:00
parent a8190bb8b1
commit f8e8d13b78
2 changed files with 26 additions and 0 deletions

View file

@ -20,5 +20,6 @@ public interface NearbyParentFragmentContract {
void onTabSelected(); void onTabSelected();
void initializeNearbyOperations(); void initializeNearbyOperations();
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType); void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType);
void lockNearby(boolean isNearbyLocked);
} }
} }

View file

@ -7,6 +7,7 @@ import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.location.LocationUpdateListener; import fr.free.nrw.commons.location.LocationUpdateListener;
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract; import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
import fr.free.nrw.commons.wikidata.WikidataEditListener; import fr.free.nrw.commons.wikidata.WikidataEditListener;
import timber.log.Timber;
public class NearbyParentFragmentPresenter public class NearbyParentFragmentPresenter
implements NearbyParentFragmentContract.UserActions, implements NearbyParentFragmentContract.UserActions,
@ -16,6 +17,7 @@ public class NearbyParentFragmentPresenter
LocationServiceManager locationManager; LocationServiceManager locationManager;
private NearbyParentFragmentContract.View nearbyParentFragmentView; private NearbyParentFragmentContract.View nearbyParentFragmentView;
private boolean isNearbyLocked;
public NearbyParentFragmentPresenter(NearbyParentFragmentContract.View nearbyParentFragmentView) { public NearbyParentFragmentPresenter(NearbyParentFragmentContract.View nearbyParentFragmentView) {
this.nearbyParentFragmentView = nearbyParentFragmentView; this.nearbyParentFragmentView = nearbyParentFragmentView;
@ -43,6 +45,23 @@ public class NearbyParentFragmentPresenter
} }
/**
* Nearby updates takes time, since they are network operations. During update time, we don't
* want to get any other calls from user. So locking nearby.
* @param isNearbyLocked true means lock, false means unlock
*/
@Override
public void lockNearby(boolean isNearbyLocked) {
this.isNearbyLocked = isNearbyLocked;
if (isNearbyLocked) {
locationManager.unregisterLocationManager();
locationManager.removeLocationListener(this);
} else {
nearbyParentFragmentView.registerLocationUpdates(locationManager);
locationManager.addLocationListener(this);
}
}
/** /**
* This method should be the single point to update Map and List. Triggered by location * This method should be the single point to update Map and List. Triggered by location
* changes * changes
@ -50,6 +69,12 @@ public class NearbyParentFragmentPresenter
*/ */
@Override @Override
public void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType) { public void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType) {
if (isNearbyLocked) {
Timber.d("Nearby is locked, so updateMapAndList returns");
return;
}
} }