mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-03 16: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 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -494,10 +494,12 @@ class NearbyParentFragmentPresenter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
override fun handleMapScrolled(scope: LifecycleCoroutineScope?) {
|
override fun handleMapScrolled(scope: LifecycleCoroutineScope?, isNetworkAvailable: Boolean) {
|
||||||
scope ?: return
|
scope ?: return
|
||||||
|
|
||||||
placeSearchJob?.cancel()
|
placeSearchJob?.cancel()
|
||||||
|
localPlaceSearchJob?.cancel()
|
||||||
|
if (isNetworkAvailable) {
|
||||||
placeSearchJob = scope.launch(Dispatchers.Main) {
|
placeSearchJob = scope.launch(Dispatchers.Main) {
|
||||||
delay(SCROLL_DELAY)
|
delay(SCROLL_DELAY)
|
||||||
if (!isSearchInProgress) {
|
if (!isSearchInProgress) {
|
||||||
|
|
@ -510,13 +512,13 @@ class NearbyParentFragmentPresenter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
localPlaceSearchJob?.cancel()
|
|
||||||
localPlaceSearchJob = scope.launch {
|
localPlaceSearchJob = scope.launch {
|
||||||
delay(LOCAL_SCROLL_DELAY)
|
delay(LOCAL_SCROLL_DELAY)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the supplied markerPlaceGroups to `NearbyController` and nearby list fragment,
|
* Sends the supplied markerPlaceGroups to `NearbyController` and nearby list fragment,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue