Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public Place fetchPlace(String entityID){
* @return The list of saved places within the map's view.
*/
public List<Place> fetchPlaces(final LatLng mapBottomLeft, final LatLng mapTopRight) {

if (mapBottomLeft == null || mapTopRight == null) {
Timber.e("Map boundaries are null, returning empty list.");
return new ArrayList<>(); // returnn empty list instead of crashing
}

class Constraint {

final double latBegin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,21 @@ class NearbyParentFragmentPresenter
loadPlacesDataAyncJob?.cancel()
localPlaceSearchJob = scope.launch(Dispatchers.IO) {
delay(LOCAL_SCROLL_DELAY)

// fix:: retrieve and check map boundaries for nullability.
val mapBottomLeft = nearbyParentFragmentView.screenBottomLeft
val mapTopRight = nearbyParentFragmentView.screenTopRight

if (mapBottomLeft == null || mapTopRight == null) {
//gracefull exit:log the error and stop the process.
Timber.d("Map boundaries (screenBottomLeft or screenTopRight) are null, skipping local place search as map state is not ready.")
return@launch // exits the coroutine gracefully, preventing the crash.
}

val mapFocus = nearbyParentFragmentView.mapFocus
val markerPlaceGroups = placesRepository.fetchPlaces(
nearbyParentFragmentView.screenBottomLeft,
nearbyParentFragmentView.screenTopRight
mapBottomLeft, // pass the now-guaranteed non-null variable
mapTopRight
).sortedBy { it.getDistanceInDouble(mapFocus) }.take(NearbyController.MAX_RESULTS)
.map {
MarkerPlaceGroup(
Expand Down