mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-27 08:55:54 +03:00
add cam permission check
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
03cb3a66c6
commit
ab4bba0f27
2 changed files with 36 additions and 1 deletions
|
@ -991,6 +991,17 @@ class ChatController(args: Bundle) :
|
|||
}
|
||||
}
|
||||
|
||||
private fun isCameraPermissionGranted(): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return PermissionChecker.checkSelfPermission(
|
||||
context!!,
|
||||
Manifest.permission.CAMERA
|
||||
) == PermissionChecker.PERMISSION_GRANTED
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private fun startAudioRecording(file: String) {
|
||||
binding.messageInputView.audioRecordDuration.base = SystemClock.elapsedRealtime()
|
||||
binding.messageInputView.audioRecordDuration.start()
|
||||
|
@ -1080,6 +1091,15 @@ class ChatController(args: Bundle) :
|
|||
)
|
||||
}
|
||||
|
||||
private fun requestCameraPermissions() {
|
||||
requestPermissions(
|
||||
arrayOf(
|
||||
Manifest.permission.CAMERA
|
||||
),
|
||||
REQUEST_CAMERA_PERMISSION
|
||||
)
|
||||
}
|
||||
|
||||
private fun checkReadOnlyState() {
|
||||
if (currentConversation != null && isAlive()) {
|
||||
if (currentConversation?.shouldShowLobby(conversationUser) ?: false ||
|
||||
|
@ -1275,6 +1295,15 @@ class ChatController(args: Bundle) :
|
|||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
} else if (requestCode == REQUEST_CAMERA_PERMISSION) {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.d(TAG, "launch cam activity since permission for cam has been granted")
|
||||
startActivityForResult(TakePhotoActivity.createIntent(context!!), REQUEST_CODE_PICK_CAMERA)
|
||||
} else {
|
||||
Toast
|
||||
.makeText(context, context?.getString(R.string.read_storage_no_permission), Toast.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2572,7 +2601,11 @@ class ChatController(args: Bundle) :
|
|||
}
|
||||
|
||||
fun sendPictureFromCamIntent() {
|
||||
startActivityForResult(TakePhotoActivity.createIntent(context!!), REQUEST_CODE_PICK_CAMERA)
|
||||
if (!isCameraPermissionGranted()) {
|
||||
requestCameraPermissions()
|
||||
} else {
|
||||
startActivityForResult(TakePhotoActivity.createIntent(context!!), REQUEST_CODE_PICK_CAMERA)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -2589,6 +2622,7 @@ class ChatController(args: Bundle) :
|
|||
private const val AGE_THREHOLD_FOR_DELETE_MESSAGE: Int = 21600000 // (6 hours in millis = 6 * 3600 * 1000)
|
||||
private const val REQUEST_CODE_CHOOSE_FILE: Int = 555
|
||||
private const val REQUEST_RECORD_AUDIO_PERMISSION = 222
|
||||
private const val REQUEST_CAMERA_PERMISSION = 223
|
||||
private const val REQUEST_CODE_PICK_CAMERA: Int = 333
|
||||
private const val OBJECT_MESSAGE: String = "{object}"
|
||||
private const val MINIMUM_VOICE_RECORD_DURATION: Int = 1000
|
||||
|
|
|
@ -478,4 +478,5 @@
|
|||
<string name="take_photo_switch_camera">Switch camera</string>
|
||||
<string name="take_photo_toggle_torch">Toggle torch</string>
|
||||
<string name="take_photo_error_deleting_picture">Error taking picture</string>
|
||||
<string name="take_photo_permission">Taking a photo is not possible without permissions</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue