mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-11-04 08:43:52 +01:00 
			
		
		
		
	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
				
			
		
		
	
	
				
					
				
			
		
			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:
		
							parent
							
								
									daeade450d
								
							
						
					
					
						commit
						c8b52efcaa
					
				
					 3 changed files with 31 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<Media>? = 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)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue