From c8b52efcaa6e6d395784ed97c06939b44b84c190 Mon Sep 17 00:00:00 2001 From: Arya Khochare <91268931+Aryakoste@users.noreply.github.com> Date: Mon, 3 Nov 2025 12:37:38 +0530 Subject: [PATCH] Fix: Map position of Explore set correctly when navigating from Nearby (#6544) * fix: show in explorer in same position as nearby * fix: Show in explorer map position: added the removed comment * code rabbit changes --------- Co-authored-by: Nicolas Raoul --- .../nrw/commons/explore/ExploreFragment.kt | 16 ++++++++++++---- .../commons/explore/ExploreMapRootFragment.kt | 9 +++++---- .../commons/explore/map/ExploreMapFragment.kt | 19 ++++++++++++++----- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/explore/ExploreFragment.kt b/app/src/main/java/fr/free/nrw/commons/explore/ExploreFragment.kt index bc8f9cfaa..a5e23cc05 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/ExploreFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/explore/ExploreFragment.kt @@ -121,9 +121,15 @@ class ExploreFragment : CommonsDaggerSupportFragment() { // get fragment arguments if (arguments != null) { with (requireArguments()) { - prevZoom = getDouble("prev_zoom") - prevLatitude = getDouble("prev_latitude") - prevLongitude = getDouble("prev_longitude") + if (containsKey("prev_zoom")) { + prevZoom = getDouble("prev_zoom") + } + if (containsKey("prev_latitude")) { + prevLatitude = getDouble("prev_latitude") + } + if (containsKey("prev_longitude")) { + prevLongitude = getDouble("prev_longitude") + } } } } @@ -135,7 +141,9 @@ class ExploreFragment : CommonsDaggerSupportFragment() { * @return true if user navigated from Nearby map */ private val isCameFromNearbyMap: Boolean - get() = prevZoom != 0.0 || prevLatitude != 0.0 || prevLongitude != 0.0 + get() = (arguments?.containsKey("prev_zoom") == true + && arguments?.containsKey("prev_latitude") == true + && arguments?.containsKey("prev_longitude") == true) fun onBackPressed(): Boolean { if (binding!!.tabLayout.selectedTabPosition == 0) { diff --git a/app/src/main/java/fr/free/nrw/commons/explore/ExploreMapRootFragment.kt b/app/src/main/java/fr/free/nrw/commons/explore/ExploreMapRootFragment.kt index d405709a8..70388c07c 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/ExploreMapRootFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/explore/ExploreMapRootFragment.kt @@ -28,9 +28,10 @@ class ExploreMapRootFragment : CommonsDaggerSupportFragment, MediaDetailProvider constructor(bundle: Bundle) { // get fragment arguments val title = bundle.getString("categoryName") - val zoom = bundle.getDouble("prev_zoom") - val latitude = bundle.getDouble("prev_latitude") - val longitude = bundle.getDouble("prev_longitude") + + val zoom = if (bundle.containsKey("prev_zoom")) bundle.getDouble("prev_zoom") else 0.0 + val latitude = if (bundle.containsKey("prev_latitude")) bundle.getDouble("prev_latitude") else 0.0 + val longitude = if (bundle.containsKey("prev_longitude")) bundle.getDouble("prev_longitude") else 0.0 mapFragment = ExploreMapFragment() val featuredArguments = bundleOf( @@ -38,7 +39,7 @@ class ExploreMapRootFragment : CommonsDaggerSupportFragment, MediaDetailProvider ) // if we came from 'Show in Explore' in Nearby, pass on zoom and center - if (zoom != 0.0 || latitude != 0.0 || longitude != 0.0) { + if (bundle.containsKey("prev_zoom") || bundle.containsKey("prev_latitude") || bundle.containsKey("prev_longitude")) { featuredArguments.putDouble("prev_zoom", zoom) featuredArguments.putDouble("prev_latitude", latitude) featuredArguments.putDouble("prev_longitude", longitude) diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt index a1bae09fb..93cbdb040 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt @@ -102,6 +102,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi private var prevLatitude = 0.0 private var prevLongitude = 0.0 private var recentlyCameFromNearbyMap = false + private var shouldPerformMapReadyActionsOnResume = false private var presenter: ExploreMapPresenter? = null private var binding: FragmentExploreMapBinding? = null var mediaList: MutableList? = null @@ -281,6 +282,10 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi requireActivity().registerReceiver(broadcastReceiver, intentFilter) } setSearchThisAreaButtonVisibility(false) + if (shouldPerformMapReadyActionsOnResume) { + shouldPerformMapReadyActionsOnResume = false + performMapReadyActions() + } } override fun onPause() { @@ -292,6 +297,11 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi } fun requestLocationIfNeeded() { + if (isResumed) { + performMapReadyActions() + } else { + shouldPerformMapReadyActionsOnResume = true + } if (!isVisible) return // skips if not visible to user if (locationPermissionsHelper!!.checkLocationPermission(requireActivity())) { if (locationPermissionsHelper!!.isLocationAccessToAppsTurnedOn()) { @@ -361,7 +371,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi if (isCameFromNearbyMap) { moveCameraToPosition( GeoPoint(prevLatitude, prevLongitude), - prevZoom, + prevZoom.coerceIn(1.0, 22.0), 1L ) } else { @@ -379,12 +389,11 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi // get fragment arguments if (arguments != null) { with (requireArguments()) { - prevZoom = getDouble("prev_zoom") - prevLatitude = getDouble("prev_latitude") - prevLongitude = getDouble("prev_longitude") + if (containsKey("prev_zoom")) prevZoom = getDouble("prev_zoom") + if (containsKey("prev_latitude")) prevLatitude = getDouble("prev_latitude") + if (containsKey("prev_longitude")) prevLongitude = getDouble("prev_longitude") } } - setRecentlyCameFromNearbyMap(isCameFromNearbyMap) }