Skip to content

Commit c8b52ef

Browse files
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 <[email protected]>
1 parent daeade4 commit c8b52ef

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

app/src/main/java/fr/free/nrw/commons/explore/ExploreFragment.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,15 @@ class ExploreFragment : CommonsDaggerSupportFragment() {
121121
// get fragment arguments
122122
if (arguments != null) {
123123
with (requireArguments()) {
124-
prevZoom = getDouble("prev_zoom")
125-
prevLatitude = getDouble("prev_latitude")
126-
prevLongitude = getDouble("prev_longitude")
124+
if (containsKey("prev_zoom")) {
125+
prevZoom = getDouble("prev_zoom")
126+
}
127+
if (containsKey("prev_latitude")) {
128+
prevLatitude = getDouble("prev_latitude")
129+
}
130+
if (containsKey("prev_longitude")) {
131+
prevLongitude = getDouble("prev_longitude")
132+
}
127133
}
128134
}
129135
}
@@ -135,7 +141,9 @@ class ExploreFragment : CommonsDaggerSupportFragment() {
135141
* @return true if user navigated from Nearby map
136142
*/
137143
private val isCameFromNearbyMap: Boolean
138-
get() = prevZoom != 0.0 || prevLatitude != 0.0 || prevLongitude != 0.0
144+
get() = (arguments?.containsKey("prev_zoom") == true
145+
&& arguments?.containsKey("prev_latitude") == true
146+
&& arguments?.containsKey("prev_longitude") == true)
139147

140148
fun onBackPressed(): Boolean {
141149
if (binding!!.tabLayout.selectedTabPosition == 0) {

app/src/main/java/fr/free/nrw/commons/explore/ExploreMapRootFragment.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@ class ExploreMapRootFragment : CommonsDaggerSupportFragment, MediaDetailProvider
2828
constructor(bundle: Bundle) {
2929
// get fragment arguments
3030
val title = bundle.getString("categoryName")
31-
val zoom = bundle.getDouble("prev_zoom")
32-
val latitude = bundle.getDouble("prev_latitude")
33-
val longitude = bundle.getDouble("prev_longitude")
31+
32+
val zoom = if (bundle.containsKey("prev_zoom")) bundle.getDouble("prev_zoom") else 0.0
33+
val latitude = if (bundle.containsKey("prev_latitude")) bundle.getDouble("prev_latitude") else 0.0
34+
val longitude = if (bundle.containsKey("prev_longitude")) bundle.getDouble("prev_longitude") else 0.0
3435

3536
mapFragment = ExploreMapFragment()
3637
val featuredArguments = bundleOf(
3738
"categoryName" to title
3839
)
3940

4041
// if we came from 'Show in Explore' in Nearby, pass on zoom and center
41-
if (zoom != 0.0 || latitude != 0.0 || longitude != 0.0) {
42+
if (bundle.containsKey("prev_zoom") || bundle.containsKey("prev_latitude") || bundle.containsKey("prev_longitude")) {
4243
featuredArguments.putDouble("prev_zoom", zoom)
4344
featuredArguments.putDouble("prev_latitude", latitude)
4445
featuredArguments.putDouble("prev_longitude", longitude)

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
102102
private var prevLatitude = 0.0
103103
private var prevLongitude = 0.0
104104
private var recentlyCameFromNearbyMap = false
105+
private var shouldPerformMapReadyActionsOnResume = false
105106
private var presenter: ExploreMapPresenter? = null
106107
private var binding: FragmentExploreMapBinding? = null
107108
var mediaList: MutableList<Media>? = null
@@ -281,6 +282,10 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
281282
requireActivity().registerReceiver(broadcastReceiver, intentFilter)
282283
}
283284
setSearchThisAreaButtonVisibility(false)
285+
if (shouldPerformMapReadyActionsOnResume) {
286+
shouldPerformMapReadyActionsOnResume = false
287+
performMapReadyActions()
288+
}
284289
}
285290

286291
override fun onPause() {
@@ -292,6 +297,11 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
292297
}
293298

294299
fun requestLocationIfNeeded() {
300+
if (isResumed) {
301+
performMapReadyActions()
302+
} else {
303+
shouldPerformMapReadyActionsOnResume = true
304+
}
295305
if (!isVisible) return // skips if not visible to user
296306
if (locationPermissionsHelper!!.checkLocationPermission(requireActivity())) {
297307
if (locationPermissionsHelper!!.isLocationAccessToAppsTurnedOn()) {
@@ -361,7 +371,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
361371
if (isCameFromNearbyMap) {
362372
moveCameraToPosition(
363373
GeoPoint(prevLatitude, prevLongitude),
364-
prevZoom,
374+
prevZoom.coerceIn(1.0, 22.0),
365375
1L
366376
)
367377
} else {
@@ -379,12 +389,11 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
379389
// get fragment arguments
380390
if (arguments != null) {
381391
with (requireArguments()) {
382-
prevZoom = getDouble("prev_zoom")
383-
prevLatitude = getDouble("prev_latitude")
384-
prevLongitude = getDouble("prev_longitude")
392+
if (containsKey("prev_zoom")) prevZoom = getDouble("prev_zoom")
393+
if (containsKey("prev_latitude")) prevLatitude = getDouble("prev_latitude")
394+
if (containsKey("prev_longitude")) prevLongitude = getDouble("prev_longitude")
385395
}
386396
}
387-
388397
setRecentlyCameFromNearbyMap(isCameFromNearbyMap)
389398
}
390399

0 commit comments

Comments
 (0)