mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 09:25:49 +03:00
Ask for permission to write external storage when uri comes from the keyboard (#658)
This commit is contained in:
parent
36060fe332
commit
43fd794c96
4 changed files with 46 additions and 20 deletions
|
@ -13,6 +13,7 @@ Other changes:
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
- Fix issues with some member events rendering (#498)
|
- Fix issues with some member events rendering (#498)
|
||||||
- Passphrase does not match (Export room keys) (#644)
|
- Passphrase does not match (Export room keys) (#644)
|
||||||
|
- Ask for permission to write external storage when uri comes from the keyboard (#658)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
|
|
@ -67,6 +67,7 @@ const val PERMISSION_REQUEST_CODE_EXPORT_KEYS = 573
|
||||||
const val PERMISSION_REQUEST_CODE_CHANGE_AVATAR = 574
|
const val PERMISSION_REQUEST_CODE_CHANGE_AVATAR = 574
|
||||||
const val PERMISSION_REQUEST_CODE_DOWNLOAD_FILE = 575
|
const val PERMISSION_REQUEST_CODE_DOWNLOAD_FILE = 575
|
||||||
const val PERMISSION_REQUEST_CODE_PICK_ATTACHMENT = 576
|
const val PERMISSION_REQUEST_CODE_PICK_ATTACHMENT = 576
|
||||||
|
const val PERMISSION_REQUEST_CODE_INCOMING_URI = 577
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log the used permissions statuses.
|
* Log the used permissions statuses.
|
||||||
|
|
|
@ -81,8 +81,6 @@ import im.vector.riotx.core.platform.VectorBaseFragment
|
||||||
import im.vector.riotx.core.ui.views.JumpToReadMarkerView
|
import im.vector.riotx.core.ui.views.JumpToReadMarkerView
|
||||||
import im.vector.riotx.core.ui.views.NotificationAreaView
|
import im.vector.riotx.core.ui.views.NotificationAreaView
|
||||||
import im.vector.riotx.core.utils.*
|
import im.vector.riotx.core.utils.*
|
||||||
import im.vector.riotx.core.utils.Debouncer
|
|
||||||
import im.vector.riotx.core.utils.createUIHandler
|
|
||||||
import im.vector.riotx.features.attachments.AttachmentTypeSelectorView
|
import im.vector.riotx.features.attachments.AttachmentTypeSelectorView
|
||||||
import im.vector.riotx.features.attachments.AttachmentsHelper
|
import im.vector.riotx.features.attachments.AttachmentsHelper
|
||||||
import im.vector.riotx.features.attachments.ContactAttachment
|
import im.vector.riotx.features.attachments.ContactAttachment
|
||||||
|
@ -619,19 +617,27 @@ class RoomDetailFragment :
|
||||||
}
|
}
|
||||||
composerLayout.callback = object : TextComposerView.Callback {
|
composerLayout.callback = object : TextComposerView.Callback {
|
||||||
override fun onRichContentSelected(contentUri: Uri): Boolean {
|
override fun onRichContentSelected(contentUri: Uri): Boolean {
|
||||||
val shareIntent = Intent().apply {
|
// We need WRITE_EXTERNAL permission
|
||||||
action = Intent.ACTION_SEND
|
return if (checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this@RoomDetailFragment, PERMISSION_REQUEST_CODE_INCOMING_URI)) {
|
||||||
data = contentUri
|
sendUri(contentUri)
|
||||||
|
} else {
|
||||||
|
roomDetailViewModel.pendingUri = contentUri
|
||||||
|
// Always intercept when we request some permission
|
||||||
|
true
|
||||||
}
|
}
|
||||||
val isHandled = attachmentsHelper.handleShareIntent(shareIntent)
|
|
||||||
if (!isHandled) {
|
|
||||||
Toast.makeText(requireContext(), R.string.error_handling_incoming_share, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
return isHandled
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun sendUri(uri: Uri): Boolean {
|
||||||
|
val shareIntent = Intent(Intent.ACTION_SEND, uri)
|
||||||
|
val isHandled = attachmentsHelper.handleShareIntent(shareIntent)
|
||||||
|
if (!isHandled) {
|
||||||
|
Toast.makeText(requireContext(), R.string.error_handling_incoming_share, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
return isHandled
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupAttachmentButton() {
|
private fun setupAttachmentButton() {
|
||||||
composerLayout.attachmentButton.setOnClickListener {
|
composerLayout.attachmentButton.setOnClickListener {
|
||||||
if (!::attachmentTypeSelector.isInitialized) {
|
if (!::attachmentTypeSelector.isInitialized) {
|
||||||
|
@ -906,19 +912,34 @@ class RoomDetailFragment :
|
||||||
|
|
||||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||||
if (allGranted(grantResults)) {
|
if (allGranted(grantResults)) {
|
||||||
if (requestCode == PERMISSION_REQUEST_CODE_DOWNLOAD_FILE) {
|
when (requestCode) {
|
||||||
val action = roomDetailViewModel.pendingAction
|
PERMISSION_REQUEST_CODE_DOWNLOAD_FILE -> {
|
||||||
if (action != null) {
|
val action = roomDetailViewModel.pendingAction
|
||||||
roomDetailViewModel.pendingAction = null
|
if (action != null) {
|
||||||
roomDetailViewModel.process(action)
|
roomDetailViewModel.pendingAction = null
|
||||||
|
roomDetailViewModel.process(action)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (requestCode == PERMISSION_REQUEST_CODE_PICK_ATTACHMENT) {
|
PERMISSION_REQUEST_CODE_INCOMING_URI -> {
|
||||||
val pendingType = attachmentsHelper.pendingType
|
val pendingUri = roomDetailViewModel.pendingUri
|
||||||
if (pendingType != null) {
|
if (pendingUri != null) {
|
||||||
attachmentsHelper.pendingType = null
|
roomDetailViewModel.pendingUri = null
|
||||||
launchAttachmentProcess(pendingType)
|
sendUri(pendingUri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PERMISSION_REQUEST_CODE_PICK_ATTACHMENT -> {
|
||||||
|
val pendingType = attachmentsHelper.pendingType
|
||||||
|
if (pendingType != null) {
|
||||||
|
attachmentsHelper.pendingType = null
|
||||||
|
launchAttachmentProcess(pendingType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Reset all pending data
|
||||||
|
roomDetailViewModel.pendingAction = null
|
||||||
|
roomDetailViewModel.pendingUri = null
|
||||||
|
attachmentsHelper.pendingType = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.riotx.features.home.room.detail
|
package im.vector.riotx.features.home.room.detail
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
import androidx.annotation.IdRes
|
import androidx.annotation.IdRes
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
@ -95,6 +96,8 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
||||||
|
|
||||||
// Slot to keep a pending action during permission request
|
// Slot to keep a pending action during permission request
|
||||||
var pendingAction: RoomDetailActions? = null
|
var pendingAction: RoomDetailActions? = null
|
||||||
|
// Slot to keep a pending uri during permission request
|
||||||
|
var pendingUri: Uri? = null
|
||||||
|
|
||||||
@AssistedInject.Factory
|
@AssistedInject.Factory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
|
|
Loading…
Reference in a new issue