Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -43,6 +43,9 @@ import javax.inject.Singleton
class ContributionController @Inject constructor(@param:Named("default_preferences") private val defaultKvStore: JsonKvStore) {
private var locationBeforeImageCapture: LatLng? = null
private var isInAppCameraUpload = false
// Flag to track if an internal upload is in progress.
var isInternalUploadInProgress = false

@JvmField
var locationPermissionCallback: LocationPermissionCallback? = null
private var locationPermissionsHelper: LocationPermissionsHelper? = null
Expand Down Expand Up @@ -350,6 +353,7 @@ class ContributionController @Inject constructor(@param:Named("default_preferenc
handleActivityResult.onHandleActivityResult(object : DefaultCallback() {
override fun onCanceled(source: FilePicker.ImageSource, type: Int) {
super.onCanceled(source, type)
isInternalUploadInProgress = false //resett flag on cancel
defaultKvStore.remove(PLACE_OBJECT)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class NearbyController extends MapController {

private final NearbyPlaces nearbyPlaces;
public static final int MAX_RESULTS = 1000;
// Flag to track if an internal upload flow is active.
public boolean isInternalUploadInProgress = false;
public static double currentLocationSearchRadius = 10.0; //in kilometers
public static LatLng currentLocation; // Users latest fetched location
public static LatLng latestSearchLocation; // Can be current and camera target on search this area button is used
Expand Down
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 @@ -1229,7 +1229,11 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
*
* @return a `LatLng` object denoting the location of the top right corner of the map.
*/
override fun getScreenTopRight(): LatLng {
override fun getScreenTopRight(): LatLng? {
if (binding?.map?.projection == null || binding!!.map.width == 0) {
Timber.e("Map projection or dimensions are invalid. Cannot calculate screenTopRight.")
return null
}
val screenTopRight = binding!!.map.projection
.fromPixels(binding!!.map.width, 0)
return LatLng(
Expand All @@ -1242,7 +1246,11 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
*
* @return a `LatLng` object denoting the location of the bottom left corner of the map.
*/
override fun getScreenBottomLeft(): LatLng {
override fun getScreenBottomLeft(): LatLng? {
if (binding?.map?.projection == null || binding!!.map.height == 0) {
Timber.e("Map projection or dimensions are invalid. Cannot calculate screenBottomLeft.")
return null
}
val screenBottomLeft = binding!!.map.projection
.fromPixels(0, binding!!.map.height)
return LatLng(
Expand All @@ -1264,7 +1272,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
// Note: This only happens when the nearby fragment is opened immediately upon app launch,
// otherwise {screenTopRightLatLng} and {screenBottomLeftLatLng} are used to determine
// the east and west corner LatLng.
if (screenTopRightLatLng.latitude == 0.0 && screenTopRightLatLng.longitude == 0.0 && screenBottomLeftLatLng.latitude == 0.0 && screenBottomLeftLatLng.longitude == 0.0) {
if (screenTopRightLatLng?.latitude == 0.0 && screenTopRightLatLng?.longitude == 0.0 && screenBottomLeftLatLng?.latitude == 0.0 && screenBottomLeftLatLng.longitude == 0.0) {
val delta = 0.009
val westCornerLat = currentLatLng.latitude - delta
val westCornerLong = currentLatLng.longitude - delta
Expand Down Expand Up @@ -1589,8 +1597,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),

private fun populatePlacesForCurrentLocation(
currentLatLng: LatLng?,
screenTopRight: LatLng,
screenBottomLeft: LatLng,
screenTopRight: LatLng?,
screenBottomLeft: LatLng?,
searchLatLng: LatLng,
customQuery: String?
) {
Expand Down Expand Up @@ -1642,8 +1650,8 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),

private fun populatePlacesForAnotherLocation(
currentLatLng: LatLng?,
screenTopRight: LatLng,
screenBottomLeft: LatLng,
screenTopRight: LatLng?,
screenBottomLeft: LatLng?,
searchLatLng: LatLng,
customQuery: String?
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ class NearbyParentFragmentPresenter
Timber.d("Skipping update of nearby places as location is unavailable")
return
}
//checks if an upload is in progress
if (nearbyController.isInternalUploadInProgress) {
//resets the flag and exit early to prevent unnecessary fetchPlaces call
nearbyController.isInternalUploadInProgress = false
Timber.d("Internal upload in progress, skipping map update")
return
}

if (isNearbyLocked) {
Timber.d("Nearby is locked, so updateMapAndList returns")
return
}

/**
* Significant changed - Markers and current location will be updated together
Expand Down Expand Up @@ -673,6 +685,17 @@ 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,
Expand Down