Skip to content

Commit

Permalink
Issue 5835 nearby (commons-app#5843)
Browse files Browse the repository at this point in the history
* NearbyParentFragment.java:
OnScroll - removed distance threshold, delay search by 800ms, discard multiple OnScroll within 800ms.
OnDestroy - destroy any queued OnScroll events

* NearbyParentFragment.java:
loadPlacesDataAsync - set batchSize from 50 back to original 3

* comment

---------

Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
  • Loading branch information
tristan81 and nicolas-raoul authored Oct 2, 2024
1 parent 3d49b1f commit d0e64d7
Showing 1 changed file with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.text.Html;
Expand Down Expand Up @@ -149,7 +150,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
WikidataEditListener.WikidataP18EditListener, LocationUpdateListener,
LocationPermissionCallback, BottomSheetAdapter.ItemClickListener {


FragmentNearbyParentBinding binding;

@Inject
Expand All @@ -171,6 +171,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
SystemThemeUtils systemThemeUtils;
@Inject
CommonPlaceClickActions commonPlaceClickActions;

private LocationPermissionsHelper locationPermissionsHelper;
private NearbyFilterSearchRecyclerViewAdapter nearbyFilterSearchRecyclerViewAdapter;
private BottomSheetBehavior bottomSheetListBehavior;
Expand Down Expand Up @@ -208,6 +209,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
private Place nearestPlace;
private volatile boolean stopQuery;

private boolean isSearchInProgress = false;
private final Handler searchHandler = new Handler();
private Runnable searchRunnable;
private static final long SCROLL_DELAY = 800; // Delay for debounce of onscroll, in milliseconds.

private List<Place> updatedPlacesList;
private LatLng updatedLatLng;
private boolean searchable;
Expand Down Expand Up @@ -419,28 +425,27 @@ public boolean longPressHelper(GeoPoint p) {
binding.map.addMapListener(new MapListener() {
@Override
public boolean onScroll(ScrollEvent event) {
if (lastMapFocus != null) {
Location mylocation = new Location("");
Location dest_location = new Location("");
dest_location.setLatitude(binding.map.getMapCenter().getLatitude());
dest_location.setLongitude(binding.map.getMapCenter().getLongitude());
mylocation.setLatitude(lastMapFocus.getLatitude());
mylocation.setLongitude(lastMapFocus.getLongitude());
Float distance = mylocation.distanceTo(dest_location);//in meters
if (lastMapFocus != null) {
if (isNetworkConnectionEstablished() && (event.getX() > 0
|| event.getY() > 0)) {
if (distance > 2000.0) {
searchable = true;

// Remove any pending search runnables
searchHandler.removeCallbacks(searchRunnable);

// Set a runnable to call the Search after a delay
searchRunnable = new Runnable() {
@Override
public void run() {
if (!isSearchInProgress) {
isSearchInProgress = true; // search executing flag
// Start Search
try {
presenter.searchInTheArea();
} else {
searchable = false;
} finally {
isSearchInProgress = false;
}
}
} else {
searchable = false;
}
}
};
// post runnable with configured SCROLL_DELAY
searchHandler.postDelayed(searchRunnable, SCROLL_DELAY);

return true;
}
Expand Down Expand Up @@ -680,6 +685,7 @@ public void onPause() {
@Override
public void onDestroyView() {
super.onDestroyView();
searchHandler.removeCallbacks(searchRunnable);
presenter.removeNearbyPreferences(applicationKvStore);
}

Expand Down Expand Up @@ -1027,7 +1033,7 @@ public void listOptionMenuItemClicked() {

@Override
public void populatePlaces(final LatLng currentLatLng) {
IGeoPoint screenTopRight = binding.map.getProjection()
IGeoPoint screenTopRight = binding.map.getProjection()
.fromPixels(binding.map.getWidth(), 0);
IGeoPoint screenBottomLeft = binding.map.getProjection()
.fromPixels(0, binding.map.getHeight());
Expand Down Expand Up @@ -1931,8 +1937,8 @@ private void highlightNearestPlace(Place nearestPlace) {
return (R.drawable.ic_clear_black_24dp);
}else if (place.name == "") {
return (isBookmarked ?
R.drawable.ic_custom_map_marker_grey_bookmarked :
R.drawable.ic_custom_map_marker_grey);
R.drawable.ic_custom_map_marker_grey_bookmarked :
R.drawable.ic_custom_map_marker_grey);
} else {
return (isBookmarked ?
R.drawable.ic_custom_map_marker_red_bookmarked :
Expand Down Expand Up @@ -2499,5 +2505,4 @@ public void onLearnMoreClicked() {
intent.setData(Uri.parse(WLM_URL));
startActivity(intent);
}

}

0 comments on commit d0e64d7

Please sign in to comment.