Nearby: add getScreenTopRight/BottomLeft and refactor old code

This commit is contained in:
savsch 2024-12-26 13:55:51 +05:30
parent 984a8fabd1
commit ecaa296918
3 changed files with 46 additions and 32 deletions

View file

@ -91,6 +91,10 @@ public interface NearbyParentFragmentContract {
LatLng getMapFocus(); LatLng getMapFocus();
LatLng getScreenTopRight();
LatLng getScreenBottomLeft();
boolean isAdvancedQueryFragmentVisible(); boolean isAdvancedQueryFragmentVisible();
void showHideAdvancedQueryFragment(boolean shouldShow); void showHideAdvancedQueryFragment(boolean shouldShow);
@ -130,6 +134,6 @@ public interface NearbyParentFragmentContract {
void toggleBookmarkedStatus(Place place); void toggleBookmarkedStatus(Place place);
void handleMapScrolled(LifecycleCoroutineScope scope); void handleMapScrolled(LifecycleCoroutineScope scope, boolean isNetworkAvailable);
} }
} }

View file

@ -472,7 +472,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
binding.map.addMapListener(new MapListener() { binding.map.addMapListener(new MapListener() {
@Override @Override
public boolean onScroll(ScrollEvent event) { public boolean onScroll(ScrollEvent event) {
presenter.handleMapScrolled(scope); presenter.handleMapScrolled(scope, !isNetworkErrorOccurred);
return true; return true;
} }
@ -1055,15 +1055,27 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} }
@Override @Override
public void populatePlaces(final LatLng currentLatLng) { public LatLng getScreenTopRight() {
IGeoPoint screenTopRight = binding.map.getProjection() final IGeoPoint screenTopRight = binding.map.getProjection()
.fromPixels(binding.map.getWidth(), 0); .fromPixels(binding.map.getWidth(), 0);
IGeoPoint screenBottomLeft = binding.map.getProjection() return new LatLng(
.fromPixels(0, binding.map.getHeight());
LatLng screenTopRightLatLng = new LatLng(
screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0);
LatLng screenBottomLeftLatLng = new LatLng(
screenTopRight.getLatitude(), screenTopRight.getLongitude(), 0); screenTopRight.getLatitude(), screenTopRight.getLongitude(), 0);
}
@Override
public LatLng getScreenBottomLeft() {
final IGeoPoint screenBottomLeft = binding.map.getProjection()
.fromPixels(0, binding.map.getHeight());
return new LatLng(
screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0);
}
@Override
public void populatePlaces(final LatLng currentLatLng) {
// these two variables have historically been assigned values the opposite of what their
// names imply, and quite some existing code depends on this fact
LatLng screenTopRightLatLng = getScreenBottomLeft();
LatLng screenBottomLeftLatLng = getScreenTopRight();
// When the nearby fragment is opened immediately upon app launch, the {screenTopRightLatLng} // When the nearby fragment is opened immediately upon app launch, the {screenTopRightLatLng}
// and {screenBottomLeftLatLng} variables return {LatLng(0.0,0.0)} as output. // and {screenBottomLeftLatLng} variables return {LatLng(0.0,0.0)} as output.
@ -1116,14 +1128,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
populatePlaces(currentLatLng); populatePlaces(currentLatLng);
return; return;
} }
IGeoPoint screenTopRight = binding.map.getProjection() // these two variables have historically been assigned values the opposite of what their
.fromPixels(binding.map.getWidth(), 0); // names imply, and quite some existing code depends on this fact
IGeoPoint screenBottomLeft = binding.map.getProjection() final LatLng screenTopRightLatLng = getScreenBottomLeft();
.fromPixels(0, binding.map.getHeight()); final LatLng screenBottomLeftLatLng = getScreenTopRight();
LatLng screenTopRightLatLng = new LatLng(
screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0);
LatLng screenBottomLeftLatLng = new LatLng(
screenTopRight.getLatitude(), screenTopRight.getLongitude(), 0);
if (currentLatLng.equals(lastFocusLocation) || lastFocusLocation == null if (currentLatLng.equals(lastFocusLocation) || lastFocusLocation == null
|| recenterToUserLocation) { // Means we are checking around current location || recenterToUserLocation) { // Means we are checking around current location

View file

@ -494,27 +494,29 @@ class NearbyParentFragmentPresenter
} }
@Override @Override
override fun handleMapScrolled(scope: LifecycleCoroutineScope?) { override fun handleMapScrolled(scope: LifecycleCoroutineScope?, isNetworkAvailable: Boolean) {
scope ?: return scope ?: return
placeSearchJob?.cancel() placeSearchJob?.cancel()
placeSearchJob = scope.launch(Dispatchers.Main) { localPlaceSearchJob?.cancel()
delay(SCROLL_DELAY) if (isNetworkAvailable) {
if (!isSearchInProgress) { placeSearchJob = scope.launch(Dispatchers.Main) {
isSearchInProgress = true; // search executing flag delay(SCROLL_DELAY)
// Start Search if (!isSearchInProgress) {
try { isSearchInProgress = true; // search executing flag
searchInTheArea(); // Start Search
} finally { try {
isSearchInProgress = false; searchInTheArea();
} finally {
isSearchInProgress = false;
}
} }
} }
} } else {
localPlaceSearchJob = scope.launch {
localPlaceSearchJob?.cancel() delay(LOCAL_SCROLL_DELAY)
localPlaceSearchJob = scope.launch {
delay(LOCAL_SCROLL_DELAY)
}
} }
} }