Fix denied permission issue

And remove dead code
This commit is contained in:
Benoit Marty 2021-07-13 11:02:22 +02:00
parent 9df874c975
commit 83bf48dfff
6 changed files with 24 additions and 18 deletions

View File

@ -34,6 +34,7 @@ import im.vector.app.core.platform.VectorBaseActivity
// Permissions sets
val PERMISSIONS_FOR_AUDIO_IP_CALL = listOf(Manifest.permission.RECORD_AUDIO)
val PERMISSIONS_FOR_VIDEO_IP_CALL = listOf(Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA)
val PERMISSIONS_FOR_VOICE_MESSAGE = listOf(Manifest.permission.RECORD_AUDIO)
val PERMISSIONS_FOR_TAKING_PHOTO = listOf(Manifest.permission.CAMERA)
val PERMISSIONS_FOR_MEMBERS_SEARCH = listOf(Manifest.permission.READ_CONTACTS)
val PERMISSIONS_FOR_ROOM_AVATAR = listOf(Manifest.permission.CAMERA)

View File

@ -51,6 +51,8 @@ class RoomDetailActivity :
return ActivityRoomDetailBinding.inflate(layoutInflater)
}
override fun getCoordinatorLayout() = views.coordinatorLayout
private lateinit var sharedActionViewModel: RoomDetailSharedActionViewModel
private val requireActiveMembershipViewModel: RequireActiveMembershipViewModel by viewModel()

View File

@ -95,7 +95,7 @@ import im.vector.app.core.ui.views.NotificationAreaView
import im.vector.app.core.utils.Debouncer
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.core.utils.KeyboardStateUtils
import im.vector.app.core.utils.PERMISSIONS_FOR_AUDIO_IP_CALL
import im.vector.app.core.utils.PERMISSIONS_FOR_VOICE_MESSAGE
import im.vector.app.core.utils.PERMISSIONS_FOR_WRITING_FILES
import im.vector.app.core.utils.checkPermissions
import im.vector.app.core.utils.colorizeMatchingText
@ -104,6 +104,7 @@ import im.vector.app.core.utils.createJSonViewerStyleProvider
import im.vector.app.core.utils.createUIHandler
import im.vector.app.core.utils.isValidUrl
import im.vector.app.core.utils.onPermissionDeniedDialog
import im.vector.app.core.utils.onPermissionDeniedSnackbar
import im.vector.app.core.utils.openUrlInExternalBrowser
import im.vector.app.core.utils.registerForPermissionsResult
import im.vector.app.core.utils.saveMedia
@ -613,17 +614,26 @@ class RoomDetailFragment @Inject constructor(
}
}
private val permissionVoiceMessageLauncher = registerForPermissionsResult { allGranted, deniedPermanently ->
if (allGranted) {
// In this case, let the user start again the gesture
} else if (deniedPermanently) {
vectorBaseActivity.onPermissionDeniedSnackbar(R.string.denied_permission_voice_message)
}
}
private fun setupVoiceMessageView() {
views.voiceMessageRecorderView.voiceMessagePlaybackTracker = voiceMessagePlaybackTracker
views.voiceMessageRecorderView.callback = object : VoiceMessageRecorderView.Callback {
override fun onVoiceRecordingStarted(): Boolean {
return if (checkPermissions(PERMISSIONS_FOR_AUDIO_IP_CALL, requireActivity(), 0)) {
return if (checkPermissions(PERMISSIONS_FOR_VOICE_MESSAGE, requireActivity(), permissionVoiceMessageLauncher)) {
views.composerLayout.isInvisible = true
roomDetailViewModel.handle(RoomDetailAction.StartRecordingVoiceMessage)
vibrate(requireContext())
true
} else {
// Permission dialog is displayed
false
}
}
@ -1272,13 +1282,6 @@ class RoomDetailFragment @Inject constructor(
override fun onTextBlankStateChanged(isBlank: Boolean) {
views.voiceMessageRecorderView.isVisible = !views.composerLayout.views.sendButton.isVisible && vectorPreferences.labsUseVoiceMessage()
}
override fun onTouchVoiceRecording() {
if (checkPermissions(PERMISSIONS_FOR_AUDIO_IP_CALL, requireActivity(), 0)) {
views.composerLayout.isInvisible = true
views.voiceMessageRecorderView.isVisible = true
}
}
}
}

View File

@ -48,7 +48,6 @@ class TextComposerView @JvmOverloads constructor(
fun onCloseRelatedMessage()
fun onSendMessage(text: CharSequence)
fun onAddAttachment()
fun onTouchVoiceRecording()
}
val views: ComposerLayoutBinding

View File

@ -119,18 +119,18 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
views.voiceMessageMicButton.setOnTouchListener { _, event ->
return@setOnTouchListener when (event.action) {
MotionEvent.ACTION_DOWN -> {
startRecordingTimer()
val recordingStarted = callback?.onVoiceRecordingStarted().orFalse()
if (recordingStarted) {
startRecordingTimer()
renderToast(context.getString(R.string.voice_message_release_to_send_toast))
}
recordingState = RecordingState.STARTED
showRecordingViews()
recordingState = RecordingState.STARTED
showRecordingViews()
firstX = event.rawX
firstY = event.rawY
lastX = firstX
lastY = firstY
firstX = event.rawX
firstY = event.rawY
lastX = firstX
lastY = firstY
}
true
}
MotionEvent.ACTION_UP -> {

View File

@ -389,6 +389,7 @@
<!-- Permissions denied forever -->
<string name="denied_permission_generic">Some permissions are missing to perform this action, please grant the permissions from the system settings.</string>
<string name="denied_permission_camera">To perform this action, please grant the Camera permission from the system settings.</string>
<string name="denied_permission_voice_message">To send voice messages, please grant the Microphone permission.</string>
<!-- First param will be replace by the value of ongoing_conference_call_voice, and second one by the value of ongoing_conference_call_video -->
<string name="ongoing_conference_call">Ongoing conference call.\nJoin as %1$s or %2$s</string>