From a7eb6bf21f62dd2b5a674215ea4ab615b771dfdd Mon Sep 17 00:00:00 2001 From: Arya Khochare Date: Sun, 26 Oct 2025 17:09:46 +0530 Subject: [PATCH 1/3] fix: show in explorer in same position as nearby --- .../nrw/commons/explore/ExploreFragment.kt | 16 +++++++--- .../commons/explore/ExploreMapRootFragment.kt | 10 +++---- .../commons/explore/map/ExploreMapFragment.kt | 29 +++++++++++++++---- 3 files changed, 41 insertions(+), 14 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 bc8f9cfaa5..878610c75a 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 d405709a82..b3acd6d127 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,17 +28,17 @@ 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( "categoryName" to title ) - // 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 a1bae09fb6..46aa2ab31d 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()) { @@ -359,9 +369,19 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi // if we came from 'Show in Explore' in Nearby, load Nearby map center and zoom if (isCameFromNearbyMap) { + val minZoom = 1.0 + val maxZoom = 22.0 + val defaultNearbyZoom = 15.0 + + val safeZoom = when { + prevZoom > maxZoom -> maxZoom + prevZoom < minZoom -> defaultNearbyZoom + else -> prevZoom + } + moveCameraToPosition( GeoPoint(prevLatitude, prevLongitude), - prevZoom, + safeZoom, 1L ) } else { @@ -379,12 +399,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) } From 447bb08e50fa8dacaa71995e5e941325fc284c2e Mon Sep 17 00:00:00 2001 From: Arya Khochare Date: Sun, 26 Oct 2025 17:15:30 +0530 Subject: [PATCH 2/3] fix: Show in explorer map position: added the removed comment --- .../java/fr/free/nrw/commons/explore/ExploreMapRootFragment.kt | 1 + 1 file changed, 1 insertion(+) 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 b3acd6d127..70388c07c5 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 @@ -38,6 +38,7 @@ class ExploreMapRootFragment : CommonsDaggerSupportFragment, MediaDetailProvider "categoryName" to title ) + // if we came from 'Show in Explore' in Nearby, pass on zoom and center if (bundle.containsKey("prev_zoom") || bundle.containsKey("prev_latitude") || bundle.containsKey("prev_longitude")) { featuredArguments.putDouble("prev_zoom", zoom) featuredArguments.putDouble("prev_latitude", latitude) From 5391955201dbf89d4b7d178aa159d5da3a327958 Mon Sep 17 00:00:00 2001 From: Arya Khochare Date: Sun, 26 Oct 2025 18:12:29 +0530 Subject: [PATCH 3/3] code rabbit changes --- .../fr/free/nrw/commons/explore/ExploreFragment.kt | 4 ++-- .../nrw/commons/explore/map/ExploreMapFragment.kt | 12 +----------- 2 files changed, 3 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 878610c75a..a5e23cc05e 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 @@ -142,8 +142,8 @@ class ExploreFragment : CommonsDaggerSupportFragment() { */ private val isCameFromNearbyMap: Boolean get() = (arguments?.containsKey("prev_zoom") == true - || arguments?.containsKey("prev_latitude") == true - || arguments?.containsKey("prev_longitude") == 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/map/ExploreMapFragment.kt b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt index 46aa2ab31d..93cbdb0409 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 @@ -369,19 +369,9 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi // if we came from 'Show in Explore' in Nearby, load Nearby map center and zoom if (isCameFromNearbyMap) { - val minZoom = 1.0 - val maxZoom = 22.0 - val defaultNearbyZoom = 15.0 - - val safeZoom = when { - prevZoom > maxZoom -> maxZoom - prevZoom < minZoom -> defaultNearbyZoom - else -> prevZoom - } - moveCameraToPosition( GeoPoint(prevLatitude, prevLongitude), - safeZoom, + prevZoom.coerceIn(1.0, 22.0), 1L ) } else {