Fix: Map position of Explore set correctly when navigating from Nearby (#6544)
Some checks are pending
Android CI / Run tests and generate APK (push) Waiting to run

* 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 <nicolas.raoul@gmail.com>
This commit is contained in:
Arya Khochare 2025-11-03 12:37:38 +05:30 committed by GitHub
parent daeade450d
commit c8b52efcaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 13 deletions

View file

@ -121,9 +121,15 @@ class ExploreFragment : CommonsDaggerSupportFragment() {
// get fragment arguments // get fragment arguments
if (arguments != null) { if (arguments != null) {
with (requireArguments()) { with (requireArguments()) {
prevZoom = getDouble("prev_zoom") if (containsKey("prev_zoom")) {
prevLatitude = getDouble("prev_latitude") prevZoom = getDouble("prev_zoom")
prevLongitude = getDouble("prev_longitude") }
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 * @return true if user navigated from Nearby map
*/ */
private val isCameFromNearbyMap: Boolean 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 { fun onBackPressed(): Boolean {
if (binding!!.tabLayout.selectedTabPosition == 0) { if (binding!!.tabLayout.selectedTabPosition == 0) {

View file

@ -28,9 +28,10 @@ class ExploreMapRootFragment : CommonsDaggerSupportFragment, MediaDetailProvider
constructor(bundle: Bundle) { constructor(bundle: Bundle) {
// get fragment arguments // get fragment arguments
val title = bundle.getString("categoryName") val title = bundle.getString("categoryName")
val zoom = bundle.getDouble("prev_zoom")
val latitude = bundle.getDouble("prev_latitude") val zoom = if (bundle.containsKey("prev_zoom")) bundle.getDouble("prev_zoom") else 0.0
val longitude = bundle.getDouble("prev_longitude") 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() mapFragment = ExploreMapFragment()
val featuredArguments = bundleOf( 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 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_zoom", zoom)
featuredArguments.putDouble("prev_latitude", latitude) featuredArguments.putDouble("prev_latitude", latitude)
featuredArguments.putDouble("prev_longitude", longitude) featuredArguments.putDouble("prev_longitude", longitude)

View file

@ -102,6 +102,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
private var prevLatitude = 0.0 private var prevLatitude = 0.0
private var prevLongitude = 0.0 private var prevLongitude = 0.0
private var recentlyCameFromNearbyMap = false private var recentlyCameFromNearbyMap = false
private var shouldPerformMapReadyActionsOnResume = false
private var presenter: ExploreMapPresenter? = null private var presenter: ExploreMapPresenter? = null
private var binding: FragmentExploreMapBinding? = null private var binding: FragmentExploreMapBinding? = null
var mediaList: MutableList<Media>? = null var mediaList: MutableList<Media>? = null
@ -281,6 +282,10 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
requireActivity().registerReceiver(broadcastReceiver, intentFilter) requireActivity().registerReceiver(broadcastReceiver, intentFilter)
} }
setSearchThisAreaButtonVisibility(false) setSearchThisAreaButtonVisibility(false)
if (shouldPerformMapReadyActionsOnResume) {
shouldPerformMapReadyActionsOnResume = false
performMapReadyActions()
}
} }
override fun onPause() { override fun onPause() {
@ -292,6 +297,11 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
} }
fun requestLocationIfNeeded() { fun requestLocationIfNeeded() {
if (isResumed) {
performMapReadyActions()
} else {
shouldPerformMapReadyActionsOnResume = true
}
if (!isVisible) return // skips if not visible to user if (!isVisible) return // skips if not visible to user
if (locationPermissionsHelper!!.checkLocationPermission(requireActivity())) { if (locationPermissionsHelper!!.checkLocationPermission(requireActivity())) {
if (locationPermissionsHelper!!.isLocationAccessToAppsTurnedOn()) { if (locationPermissionsHelper!!.isLocationAccessToAppsTurnedOn()) {
@ -361,7 +371,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
if (isCameFromNearbyMap) { if (isCameFromNearbyMap) {
moveCameraToPosition( moveCameraToPosition(
GeoPoint(prevLatitude, prevLongitude), GeoPoint(prevLatitude, prevLongitude),
prevZoom, prevZoom.coerceIn(1.0, 22.0),
1L 1L
) )
} else { } else {
@ -379,12 +389,11 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
// get fragment arguments // get fragment arguments
if (arguments != null) { if (arguments != null) {
with (requireArguments()) { with (requireArguments()) {
prevZoom = getDouble("prev_zoom") if (containsKey("prev_zoom")) prevZoom = getDouble("prev_zoom")
prevLatitude = getDouble("prev_latitude") if (containsKey("prev_latitude")) prevLatitude = getDouble("prev_latitude")
prevLongitude = getDouble("prev_longitude") if (containsKey("prev_longitude")) prevLongitude = getDouble("prev_longitude")
} }
} }
setRecentlyCameFromNearbyMap(isCameFromNearbyMap) setRecentlyCameFromNearbyMap(isCameFromNearbyMap)
} }