mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-01 15:23:54 +01:00
Nearby: add getScreenTopRight/BottomLeft and refactor old code
This commit is contained in:
parent
984a8fabd1
commit
ecaa296918
3 changed files with 46 additions and 32 deletions
|
|
@ -91,6 +91,10 @@ public interface NearbyParentFragmentContract {
|
|||
|
||||
LatLng getMapFocus();
|
||||
|
||||
LatLng getScreenTopRight();
|
||||
|
||||
LatLng getScreenBottomLeft();
|
||||
|
||||
boolean isAdvancedQueryFragmentVisible();
|
||||
|
||||
void showHideAdvancedQueryFragment(boolean shouldShow);
|
||||
|
|
@ -130,6 +134,6 @@ public interface NearbyParentFragmentContract {
|
|||
|
||||
void toggleBookmarkedStatus(Place place);
|
||||
|
||||
void handleMapScrolled(LifecycleCoroutineScope scope);
|
||||
void handleMapScrolled(LifecycleCoroutineScope scope, boolean isNetworkAvailable);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -472,7 +472,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
binding.map.addMapListener(new MapListener() {
|
||||
@Override
|
||||
public boolean onScroll(ScrollEvent event) {
|
||||
presenter.handleMapScrolled(scope);
|
||||
presenter.handleMapScrolled(scope, !isNetworkErrorOccurred);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1055,15 +1055,27 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void populatePlaces(final LatLng currentLatLng) {
|
||||
IGeoPoint screenTopRight = binding.map.getProjection()
|
||||
public LatLng getScreenTopRight() {
|
||||
final IGeoPoint screenTopRight = binding.map.getProjection()
|
||||
.fromPixels(binding.map.getWidth(), 0);
|
||||
IGeoPoint screenBottomLeft = binding.map.getProjection()
|
||||
.fromPixels(0, binding.map.getHeight());
|
||||
LatLng screenTopRightLatLng = new LatLng(
|
||||
screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0);
|
||||
LatLng screenBottomLeftLatLng = new LatLng(
|
||||
return new LatLng(
|
||||
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}
|
||||
// and {screenBottomLeftLatLng} variables return {LatLng(0.0,0.0)} as output.
|
||||
|
|
@ -1116,14 +1128,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
populatePlaces(currentLatLng);
|
||||
return;
|
||||
}
|
||||
IGeoPoint screenTopRight = binding.map.getProjection()
|
||||
.fromPixels(binding.map.getWidth(), 0);
|
||||
IGeoPoint screenBottomLeft = binding.map.getProjection()
|
||||
.fromPixels(0, binding.map.getHeight());
|
||||
LatLng screenTopRightLatLng = new LatLng(
|
||||
screenBottomLeft.getLatitude(), screenBottomLeft.getLongitude(), 0);
|
||||
LatLng screenBottomLeftLatLng = new LatLng(
|
||||
screenTopRight.getLatitude(), screenTopRight.getLongitude(), 0);
|
||||
// these two variables have historically been assigned values the opposite of what their
|
||||
// names imply, and quite some existing code depends on this fact
|
||||
final LatLng screenTopRightLatLng = getScreenBottomLeft();
|
||||
final LatLng screenBottomLeftLatLng = getScreenTopRight();
|
||||
|
||||
if (currentLatLng.equals(lastFocusLocation) || lastFocusLocation == null
|
||||
|| recenterToUserLocation) { // Means we are checking around current location
|
||||
|
|
|
|||
|
|
@ -494,27 +494,29 @@ class NearbyParentFragmentPresenter
|
|||
}
|
||||
|
||||
@Override
|
||||
override fun handleMapScrolled(scope: LifecycleCoroutineScope?) {
|
||||
override fun handleMapScrolled(scope: LifecycleCoroutineScope?, isNetworkAvailable: Boolean) {
|
||||
scope ?: return
|
||||
|
||||
placeSearchJob?.cancel()
|
||||
placeSearchJob = scope.launch(Dispatchers.Main) {
|
||||
delay(SCROLL_DELAY)
|
||||
if (!isSearchInProgress) {
|
||||
isSearchInProgress = true; // search executing flag
|
||||
// Start Search
|
||||
try {
|
||||
searchInTheArea();
|
||||
} finally {
|
||||
isSearchInProgress = false;
|
||||
localPlaceSearchJob?.cancel()
|
||||
if (isNetworkAvailable) {
|
||||
placeSearchJob = scope.launch(Dispatchers.Main) {
|
||||
delay(SCROLL_DELAY)
|
||||
if (!isSearchInProgress) {
|
||||
isSearchInProgress = true; // search executing flag
|
||||
// Start Search
|
||||
try {
|
||||
searchInTheArea();
|
||||
} finally {
|
||||
isSearchInProgress = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
localPlaceSearchJob?.cancel()
|
||||
localPlaceSearchJob = scope.launch {
|
||||
delay(LOCAL_SCROLL_DELAY)
|
||||
} else {
|
||||
localPlaceSearchJob = scope.launch {
|
||||
delay(LOCAL_SCROLL_DELAY)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue