mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Added location prompt at Map screen
This commit is contained in:
parent
fcc63b9f09
commit
0785a2db90
4 changed files with 75 additions and 16 deletions
|
|
@ -64,6 +64,9 @@ class ExploreFragment : CommonsDaggerSupportFragment() {
|
||||||
override fun onPageScrollStateChanged(state: Int) = Unit
|
override fun onPageScrollStateChanged(state: Int) = Unit
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
binding!!.viewPager.canScroll = position != 2
|
binding!!.viewPager.canScroll = position != 2
|
||||||
|
if (position == 2) {
|
||||||
|
mapRootFragment?.requestLocationIfNeeded()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
setTabs()
|
setTabs()
|
||||||
|
|
@ -171,14 +174,11 @@ class ExploreFragment : CommonsDaggerSupportFragment() {
|
||||||
// if on Map tab, show all menu options, else only show search
|
// if on Map tab, show all menu options, else only show search
|
||||||
binding!!.viewPager.addOnPageChangeListener(object : OnPageChangeListener {
|
binding!!.viewPager.addOnPageChangeListener(object : OnPageChangeListener {
|
||||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) = Unit
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) = Unit
|
||||||
|
override fun onPageScrollStateChanged(state: Int) = Unit
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
others.setVisible((position == 2))
|
binding!!.viewPager.canScroll = position != 2
|
||||||
}
|
if (position == 2) {
|
||||||
|
mapRootFragment?.requestLocationIfNeeded()
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
|
||||||
if (state == ViewPager.SCROLL_STATE_IDLE && binding!!.viewPager.currentItem == 2) {
|
|
||||||
onPageSelected(2)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,17 @@ class ExploreMapRootFragment : CommonsDaggerSupportFragment, MediaDetailProvider
|
||||||
binding = null
|
binding = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun requestLocationIfNeeded() {
|
||||||
|
mapFragment?.requestLocationIfNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
|
||||||
|
super.setUserVisibleHint(isVisibleToUser)
|
||||||
|
if (isVisibleToUser) {
|
||||||
|
requestLocationIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun newInstance(): ExploreMapRootFragment = ExploreMapRootFragment().apply {
|
fun newInstance(): ExploreMapRootFragment = ExploreMapRootFragment().apply {
|
||||||
retainInstance = true
|
retainInstance = true
|
||||||
|
|
|
||||||
|
|
@ -278,14 +278,11 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
|
||||||
super.onResume()
|
super.onResume()
|
||||||
binding!!.mapView.onResume()
|
binding!!.mapView.onResume()
|
||||||
presenter!!.attachView(this)
|
presenter!!.attachView(this)
|
||||||
registerNetworkReceiver()
|
locationManager.addLocationListener(this)
|
||||||
if (isResumed) {
|
if (broadcastReceiver != null) {
|
||||||
if (locationPermissionsHelper!!.checkLocationPermission(requireActivity())) {
|
requireActivity().registerReceiver(broadcastReceiver, intentFilter)
|
||||||
performMapReadyActions()
|
|
||||||
} else {
|
|
||||||
startMapWithoutPermission()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
setSearchThisAreaButtonVisibility(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
|
@ -294,6 +291,38 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
|
||||||
unregisterNetworkReceiver()
|
unregisterNetworkReceiver()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun requestLocationIfNeeded() {
|
||||||
|
if (!isVisible) return // Skip if not visible to user
|
||||||
|
if (locationPermissionsHelper!!.checkLocationPermission(requireActivity())) {
|
||||||
|
if (locationPermissionsHelper!!.isLocationAccessToAppsTurnedOn()) {
|
||||||
|
locationManager.registerLocationManager()
|
||||||
|
drawMyLocationMarker()
|
||||||
|
} else {
|
||||||
|
locationPermissionsHelper!!.showLocationOffDialog(requireActivity(), R.string.location_off_dialog_text)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
locationPermissionsHelper!!.requestForLocationAccess(
|
||||||
|
R.string.location_permission_title,
|
||||||
|
R.string.location_permission_rationale
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun drawMyLocationMarker() {
|
||||||
|
val location = locationManager.getLastLocation()
|
||||||
|
if (location != null) {
|
||||||
|
val geoPoint = GeoPoint(location.latitude, location.longitude)
|
||||||
|
val startMarker = Marker(binding!!.mapView).apply {
|
||||||
|
setPosition(geoPoint)
|
||||||
|
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
||||||
|
icon = ContextCompat.getDrawable(requireContext(), R.drawable.current_location_marker)
|
||||||
|
title = "Your Location"
|
||||||
|
textLabelFontSize = 24
|
||||||
|
}
|
||||||
|
binding!!.mapView.overlays.add(startMarker)
|
||||||
|
binding!!.mapView.invalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters the networkReceiver
|
* Unregisters the networkReceiver
|
||||||
|
|
@ -807,7 +836,7 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the specific Media object from the mediaList field.
|
* Retrieves the specific Mediaa object from the mediaList field.
|
||||||
* @param url The specific Media's image URL.
|
* @param url The specific Media's image URL.
|
||||||
* @return The Media object that matches the URL or null if it could not be found.
|
* @return The Media object that matches the URL or null if it could not be found.
|
||||||
*/
|
*/
|
||||||
|
|
@ -1079,7 +1108,24 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi
|
||||||
|
|
||||||
override fun onLocationPermissionDenied(toastMessage: String) = Unit
|
override fun onLocationPermissionDenied(toastMessage: String) = Unit
|
||||||
|
|
||||||
override fun onLocationPermissionGranted() = Unit
|
override fun onLocationPermissionGranted() {
|
||||||
|
if (locationPermissionsHelper!!.isLocationAccessToAppsTurnedOn()) {
|
||||||
|
locationManager.registerLocationManager()
|
||||||
|
drawMyLocationMarker()
|
||||||
|
} else {
|
||||||
|
locationPermissionsHelper!!.showLocationOffDialog(requireActivity(), R.string.location_off_dialog_text)
|
||||||
|
}
|
||||||
|
onLocationChanged(LocationChangeType.PERMISSION_JUST_GRANTED, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onLocationChanged(locationChangeType: LocationChangeType, location: Location?) {
|
||||||
|
if (locationChangeType == LocationChangeType.PERMISSION_JUST_GRANTED) {
|
||||||
|
val curLatLng = locationManager.getLastLocation() ?: getMapCenter()
|
||||||
|
populatePlaces(curLatLng)
|
||||||
|
} else {
|
||||||
|
presenter!!.updateMap(locationChangeType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun newInstance(): ExploreMapFragment {
|
fun newInstance(): ExploreMapFragment {
|
||||||
|
|
|
||||||
|
|
@ -748,6 +748,8 @@ Upload your first media by tapping on the add button.</string>
|
||||||
<string name="wlm_campaign_description">Wiki Loves Monuments is an international photo contest for monuments organised by Wikimedia</string>
|
<string name="wlm_campaign_description">Wiki Loves Monuments is an international photo contest for monuments organised by Wikimedia</string>
|
||||||
<string name="need_permission">Need Permission</string>
|
<string name="need_permission">Need Permission</string>
|
||||||
<string name="read_phone_state_permission_message">Nearby maps need to read PHONE STATE to function properly</string>
|
<string name="read_phone_state_permission_message">Nearby maps need to read PHONE STATE to function properly</string>
|
||||||
|
<string name="location_off_dialog_text">Please turn on location services to view nearby places.</string>
|
||||||
|
<string name="location_permission_rationale">Location access is needed to show nearby places on the map.</string>
|
||||||
|
|
||||||
<string name="contributions_of_user">Contributions of User: %s</string>
|
<string name="contributions_of_user">Contributions of User: %s</string>
|
||||||
<string name="achievements_of_user">Achievements of User: %s</string>
|
<string name="achievements_of_user">Achievements of User: %s</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue