mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-12 18:40:52 +00:00
add cam permission check
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
03cb3a66c6
commit
ab4bba0f27
@ -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) {
|
private fun startAudioRecording(file: String) {
|
||||||
binding.messageInputView.audioRecordDuration.base = SystemClock.elapsedRealtime()
|
binding.messageInputView.audioRecordDuration.base = SystemClock.elapsedRealtime()
|
||||||
binding.messageInputView.audioRecordDuration.start()
|
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() {
|
private fun checkReadOnlyState() {
|
||||||
if (currentConversation != null && isAlive()) {
|
if (currentConversation != null && isAlive()) {
|
||||||
if (currentConversation?.shouldShowLobby(conversationUser) ?: false ||
|
if (currentConversation?.shouldShowLobby(conversationUser) ?: false ||
|
||||||
@ -1275,6 +1295,15 @@ class ChatController(args: Bundle) :
|
|||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
).show()
|
).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() {
|
fun sendPictureFromCamIntent() {
|
||||||
startActivityForResult(TakePhotoActivity.createIntent(context!!), REQUEST_CODE_PICK_CAMERA)
|
if (!isCameraPermissionGranted()) {
|
||||||
|
requestCameraPermissions()
|
||||||
|
} else {
|
||||||
|
startActivityForResult(TakePhotoActivity.createIntent(context!!), REQUEST_CODE_PICK_CAMERA)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
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 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_CODE_CHOOSE_FILE: Int = 555
|
||||||
private const val REQUEST_RECORD_AUDIO_PERMISSION = 222
|
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 REQUEST_CODE_PICK_CAMERA: Int = 333
|
||||||
private const val OBJECT_MESSAGE: String = "{object}"
|
private const val OBJECT_MESSAGE: String = "{object}"
|
||||||
private const val MINIMUM_VOICE_RECORD_DURATION: Int = 1000
|
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_switch_camera">Switch camera</string>
|
||||||
<string name="take_photo_toggle_torch">Toggle torch</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_error_deleting_picture">Error taking picture</string>
|
||||||
|
<string name="take_photo_permission">Taking a photo is not possible without permissions</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user