Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions app/src/main/java/fr/free/nrw/commons/explore/ExploreFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -281,6 +282,10 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
requireActivity().registerReceiver(broadcastReceiver, intentFilter)
}
setSearchThisAreaButtonVisibility(false)
if (shouldPerformMapReadyActionsOnResume) {
shouldPerformMapReadyActionsOnResume = false
performMapReadyActions()
}
}

override fun onPause() {
Expand All @@ -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()) {
Expand Down Expand Up @@ -361,7 +371,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
if (isCameFromNearbyMap) {
moveCameraToPosition(
GeoPoint(prevLatitude, prevLongitude),
prevZoom,
prevZoom.coerceIn(1.0, 22.0),
1L
)
} else {
Expand All @@ -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)
}

Expand Down