mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 01:45:52 +03:00
Ask for write permission before editing media
This commit is contained in:
parent
d67cd2cbef
commit
82bd8a2e2a
2 changed files with 21 additions and 1 deletions
|
@ -68,6 +68,7 @@ const val PERMISSION_REQUEST_CODE_CHANGE_AVATAR = 574
|
|||
const val PERMISSION_REQUEST_CODE_DOWNLOAD_FILE = 575
|
||||
const val PERMISSION_REQUEST_CODE_PICK_ATTACHMENT = 576
|
||||
const val PERMISSION_REQUEST_CODE_INCOMING_URI = 577
|
||||
const val PERMISSION_REQUEST_CODE_PREVIEW_FRAGMENT = 578
|
||||
|
||||
/**
|
||||
* Log the used permissions statuses.
|
||||
|
|
|
@ -45,8 +45,12 @@ import im.vector.riotx.core.extensions.cleanup
|
|||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.utils.OnSnapPositionChangeListener
|
||||
import im.vector.riotx.core.utils.PERMISSIONS_FOR_WRITING_FILES
|
||||
import im.vector.riotx.core.utils.PERMISSION_REQUEST_CODE_PREVIEW_FRAGMENT
|
||||
import im.vector.riotx.core.utils.SnapOnScrollListener
|
||||
import im.vector.riotx.core.utils.allGranted
|
||||
import im.vector.riotx.core.utils.attachSnapHelperWithListener
|
||||
import im.vector.riotx.core.utils.checkPermissions
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.android.synthetic.main.fragment_attachments_preview.*
|
||||
import timber.log.Timber
|
||||
|
@ -178,7 +182,22 @@ class AttachmentsPreviewFragment @Inject constructor(
|
|||
viewModel.handle(AttachmentsPreviewAction.RemoveCurrentAttachment)
|
||||
}
|
||||
|
||||
private fun handleEditAction() = withState(viewModel) {
|
||||
private fun handleEditAction() {
|
||||
// check permissions
|
||||
if (checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this, PERMISSION_REQUEST_CODE_PREVIEW_FRAGMENT)) {
|
||||
doHandleEditAction()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
|
||||
if (requestCode == PERMISSION_REQUEST_CODE_PREVIEW_FRAGMENT && allGranted(grantResults)) {
|
||||
doHandleEditAction()
|
||||
}
|
||||
}
|
||||
|
||||
private fun doHandleEditAction() = withState(viewModel) {
|
||||
val currentAttachment = it.attachments.getOrNull(it.currentAttachmentIndex) ?: return@withState
|
||||
val destinationFile = File(requireContext().cacheDir, "${currentAttachment.name}_edited_image_${System.currentTimeMillis()}")
|
||||
UCrop.of(currentAttachment.queryUri.toUri(), destinationFile.toUri())
|
||||
|
|
Loading…
Reference in a new issue