mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Remove runtime permission request
This commit is contained in:
parent
90cda6b2be
commit
233fe21f26
@ -19,7 +19,6 @@ package im.vector.app.core.utils
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
@ -43,11 +42,6 @@ val PERMISSIONS_FOR_ROOM_AVATAR = listOf(Manifest.permission.CAMERA)
|
||||
val PERMISSIONS_FOR_WRITING_FILES = listOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
val PERMISSIONS_FOR_PICKING_CONTACT = listOf(Manifest.permission.READ_CONTACTS)
|
||||
val PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING = listOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
val PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
listOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||
} else {
|
||||
PERMISSIONS_EMPTY
|
||||
}
|
||||
|
||||
// This is not ideal to store the value like that, but it works
|
||||
private var permissionDialogDisplayed = false
|
||||
|
@ -17,20 +17,10 @@
|
||||
package im.vector.app.features.location
|
||||
|
||||
import android.app.Activity
|
||||
import im.vector.app.core.utils.openAppSettingsPage
|
||||
|
||||
class DefaultLocationSharingNavigator constructor(val activity: Activity?) : LocationSharingNavigator {
|
||||
|
||||
override var goingToAppSettings: Boolean = false
|
||||
|
||||
override fun quit() {
|
||||
activity?.finish()
|
||||
}
|
||||
|
||||
override fun goToAppSettings() {
|
||||
activity?.let {
|
||||
goingToAppSettings = true
|
||||
openAppSettingsPage(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ import com.mapbox.mapboxsdk.maps.MapView
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
|
||||
import im.vector.app.core.platform.VectorBaseFragment
|
||||
import im.vector.app.core.utils.PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING
|
||||
import im.vector.app.core.utils.PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING
|
||||
import im.vector.app.core.utils.checkPermissions
|
||||
import im.vector.app.core.utils.onPermissionDeniedDialog
|
||||
import im.vector.app.core.utils.registerForPermissionsResult
|
||||
import im.vector.app.databinding.FragmentLocationSharingBinding
|
||||
import im.vector.app.features.home.AvatarRenderer
|
||||
@ -100,11 +100,6 @@ class LocationSharingFragment @Inject constructor(
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
views.mapView.onResume()
|
||||
if (locationSharingNavigator.goingToAppSettings) {
|
||||
locationSharingNavigator.goingToAppSettings = false
|
||||
// retry to start live location
|
||||
tryStartLiveLocationSharing()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@ -162,18 +157,6 @@ class LocationSharingFragment @Inject constructor(
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun handleMissingBackgroundLocationPermission() {
|
||||
MaterialAlertDialogBuilder(requireActivity())
|
||||
.setTitle(R.string.location_in_background_missing_permission_dialog_title)
|
||||
.setMessage(R.string.location_in_background_missing_permission_dialog_content)
|
||||
.setPositiveButton(R.string.settings) { _, _ ->
|
||||
locationSharingNavigator.goToAppSettings()
|
||||
}
|
||||
.setNegativeButton(R.string.action_not_now, null)
|
||||
.setCancelable(false)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun initLocateButton() {
|
||||
views.mapView.locateButton.setOnClickListener {
|
||||
viewModel.handle(LocationSharingAction.ZoomToUserLocation)
|
||||
@ -212,30 +195,16 @@ class LocationSharingFragment @Inject constructor(
|
||||
}
|
||||
|
||||
private val foregroundLocationResultLauncher = registerForPermissionsResult { allGranted, deniedPermanently ->
|
||||
if (allGranted && checkPermissions(PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING, requireActivity(), backgroundLocationResultLauncher)) {
|
||||
startLiveLocationSharing()
|
||||
} else if (deniedPermanently) {
|
||||
handleMissingBackgroundLocationPermission()
|
||||
}
|
||||
}
|
||||
|
||||
private val backgroundLocationResultLauncher = registerForPermissionsResult { allGranted, deniedPermanently ->
|
||||
if (allGranted) {
|
||||
startLiveLocationSharing()
|
||||
} else if (deniedPermanently) {
|
||||
handleMissingBackgroundLocationPermission()
|
||||
activity?.onPermissionDeniedDialog(R.string.denied_permission_generic)
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryStartLiveLocationSharing() {
|
||||
// we need to re-check foreground location to be sure it has not changed after landing on this screen
|
||||
if (checkPermissions(PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING, requireActivity(), foregroundLocationResultLauncher) &&
|
||||
checkPermissions(
|
||||
PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING,
|
||||
requireActivity(),
|
||||
backgroundLocationResultLauncher,
|
||||
R.string.location_in_background_missing_permission_dialog_content
|
||||
)) {
|
||||
if (checkPermissions(PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING, requireActivity(), foregroundLocationResultLauncher)) {
|
||||
startLiveLocationSharing()
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,5 @@
|
||||
package im.vector.app.features.location
|
||||
|
||||
interface LocationSharingNavigator {
|
||||
var goingToAppSettings: Boolean
|
||||
fun quit()
|
||||
fun goToAppSettings()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user