mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	NearbyParentFragment.java:
OnScroll - removed distance threshold, delay search by 800ms, discard multiple OnScroll within 800ms. OnDestroy - destroy any queued OnScroll events
This commit is contained in:
		
							parent
							
								
									16a1375800
								
							
						
					
					
						commit
						c397083980
					
				
					 1 changed files with 29 additions and 24 deletions
				
			
		|  | @ -27,6 +27,7 @@ import android.os.Build.VERSION; | ||||||
| import android.os.Build.VERSION_CODES; | import android.os.Build.VERSION_CODES; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.os.Environment; | import android.os.Environment; | ||||||
|  | import android.os.Handler; | ||||||
| import android.preference.PreferenceManager; | import android.preference.PreferenceManager; | ||||||
| import android.provider.Settings; | import android.provider.Settings; | ||||||
| import android.text.Html; | import android.text.Html; | ||||||
|  | @ -149,7 +150,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|     WikidataEditListener.WikidataP18EditListener, LocationUpdateListener, |     WikidataEditListener.WikidataP18EditListener, LocationUpdateListener, | ||||||
|     LocationPermissionCallback, BottomSheetAdapter.ItemClickListener { |     LocationPermissionCallback, BottomSheetAdapter.ItemClickListener { | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     FragmentNearbyParentBinding binding; |     FragmentNearbyParentBinding binding; | ||||||
| 
 | 
 | ||||||
|     @Inject |     @Inject | ||||||
|  | @ -171,6 +171,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|     SystemThemeUtils systemThemeUtils; |     SystemThemeUtils systemThemeUtils; | ||||||
|     @Inject |     @Inject | ||||||
|     CommonPlaceClickActions commonPlaceClickActions; |     CommonPlaceClickActions commonPlaceClickActions; | ||||||
|  | 
 | ||||||
|     private LocationPermissionsHelper locationPermissionsHelper; |     private LocationPermissionsHelper locationPermissionsHelper; | ||||||
|     private NearbyFilterSearchRecyclerViewAdapter nearbyFilterSearchRecyclerViewAdapter; |     private NearbyFilterSearchRecyclerViewAdapter nearbyFilterSearchRecyclerViewAdapter; | ||||||
|     private BottomSheetBehavior bottomSheetListBehavior; |     private BottomSheetBehavior bottomSheetListBehavior; | ||||||
|  | @ -208,6 +209,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|     private Place nearestPlace; |     private Place nearestPlace; | ||||||
|     private volatile boolean stopQuery; |     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 | ||||||
|  | 
 | ||||||
|     private List<Place> updatedPlacesList; |     private List<Place> updatedPlacesList; | ||||||
|     private LatLng updatedLatLng; |     private LatLng updatedLatLng; | ||||||
|     private boolean searchable; |     private boolean searchable; | ||||||
|  | @ -419,28 +425,27 @@ 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) { | ||||||
|                 if (lastMapFocus != null) { | 
 | ||||||
|                     Location mylocation = new Location(""); |                 // Remove any pending search runnables | ||||||
|                     Location dest_location = new Location(""); |                 searchHandler.removeCallbacks(searchRunnable); | ||||||
|                     dest_location.setLatitude(binding.map.getMapCenter().getLatitude()); | 
 | ||||||
|                     dest_location.setLongitude(binding.map.getMapCenter().getLongitude()); |                 // Set a runnable to call the Search after a delay | ||||||
|                     mylocation.setLatitude(lastMapFocus.getLatitude()); |                 searchRunnable = new Runnable() { | ||||||
|                     mylocation.setLongitude(lastMapFocus.getLongitude()); |                     @Override | ||||||
|                     Float distance = mylocation.distanceTo(dest_location);//in meters |                     public void run() { | ||||||
|                     if (lastMapFocus != null) { |                         if (!isSearchInProgress) { | ||||||
|                         if (isNetworkConnectionEstablished() && (event.getX() > 0 |                             isSearchInProgress = true; // search executing flag | ||||||
|                             || event.getY() > 0)) { |                             // Start Search | ||||||
|                             if (distance > 2000.0) { |                             try { | ||||||
|                                 searchable = true; |  | ||||||
|                                 presenter.searchInTheArea(); |                                 presenter.searchInTheArea(); | ||||||
|                             } else { |                             } finally { | ||||||
|                                 searchable = false; |                                 isSearchInProgress = false; | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     } else { |  | ||||||
|                         searchable = false; |  | ||||||
|                     } |                     } | ||||||
|                 } |                 }; | ||||||
|  |                 // post runnable with configured SCROLL_DELAY | ||||||
|  |                 searchHandler.postDelayed(searchRunnable, SCROLL_DELAY); | ||||||
| 
 | 
 | ||||||
|                 return true; |                 return true; | ||||||
|             } |             } | ||||||
|  | @ -680,6 +685,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|     @Override |     @Override | ||||||
|     public void onDestroyView() { |     public void onDestroyView() { | ||||||
|         super.onDestroyView(); |         super.onDestroyView(); | ||||||
|  |         searchHandler.removeCallbacks(searchRunnable); | ||||||
|         presenter.removeNearbyPreferences(applicationKvStore); |         presenter.removeNearbyPreferences(applicationKvStore); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -1027,7 +1033,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void populatePlaces(final LatLng currentLatLng) { |     public void populatePlaces(final LatLng currentLatLng) { | ||||||
|         IGeoPoint screenTopRight = binding.map.getProjection() |             IGeoPoint screenTopRight = binding.map.getProjection() | ||||||
|             .fromPixels(binding.map.getWidth(), 0); |             .fromPixels(binding.map.getWidth(), 0); | ||||||
|         IGeoPoint screenBottomLeft = binding.map.getProjection() |         IGeoPoint screenBottomLeft = binding.map.getProjection() | ||||||
|             .fromPixels(0, binding.map.getHeight()); |             .fromPixels(0, binding.map.getHeight()); | ||||||
|  | @ -1374,7 +1380,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
| 
 | 
 | ||||||
|         // Instead of loading all pins in a single SPARQL query, we query in batches. |         // Instead of loading all pins in a single SPARQL query, we query in batches. | ||||||
|         // This variable controls the number of pins queried per batch. |         // This variable controls the number of pins queried per batch. | ||||||
|         int batchSize = 3; |         int batchSize = 50; | ||||||
| 
 | 
 | ||||||
|         updatedLatLng = curLatLng; |         updatedLatLng = curLatLng; | ||||||
|         updatedPlacesList = new ArrayList<>(placeList); |         updatedPlacesList = new ArrayList<>(placeList); | ||||||
|  | @ -1931,8 +1937,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|             return (R.drawable.ic_clear_black_24dp); |             return (R.drawable.ic_clear_black_24dp); | ||||||
|         }else if (place.name == "") { |         }else if (place.name == "") { | ||||||
|             return (isBookmarked ? |             return (isBookmarked ? | ||||||
|                     R.drawable.ic_custom_map_marker_grey_bookmarked : |                 R.drawable.ic_custom_map_marker_grey_bookmarked : | ||||||
|                     R.drawable.ic_custom_map_marker_grey); |                 R.drawable.ic_custom_map_marker_grey); | ||||||
|         } else { |         } else { | ||||||
|             return (isBookmarked ? |             return (isBookmarked ? | ||||||
|                 R.drawable.ic_custom_map_marker_red_bookmarked : |                 R.drawable.ic_custom_map_marker_red_bookmarked : | ||||||
|  | @ -2499,5 +2505,4 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|         intent.setData(Uri.parse(WLM_URL)); |         intent.setData(Uri.parse(WLM_URL)); | ||||||
|         startActivity(intent); |         startActivity(intent); | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 tristan
						tristan