No preview for elements sent from the keyboard

This commit is contained in:
Benoit Marty 2020-02-17 14:48:12 +01:00
parent ca0cd9e97d
commit a3b205b310
2 changed files with 18 additions and 8 deletions

View File

@ -650,9 +650,11 @@ class RoomDetailFragment @Inject constructor(
} }
private fun sendUri(uri: Uri): Boolean { private fun sendUri(uri: Uri): Boolean {
roomDetailViewModel.preventAttachmentPreview = true
val shareIntent = Intent(Intent.ACTION_SEND, uri) val shareIntent = Intent(Intent.ACTION_SEND, uri)
val isHandled = attachmentsHelper.handleShareIntent(shareIntent) val isHandled = attachmentsHelper.handleShareIntent(shareIntent)
if (!isHandled) { if (!isHandled) {
roomDetailViewModel.preventAttachmentPreview = false
Toast.makeText(requireContext(), R.string.error_handling_incoming_share, Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), R.string.error_handling_incoming_share, Toast.LENGTH_SHORT).show()
} }
return isHandled return isHandled
@ -1347,6 +1349,10 @@ class RoomDetailFragment @Inject constructor(
// AttachmentsHelper.Callback // AttachmentsHelper.Callback
override fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) { override fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) {
if (roomDetailViewModel.preventAttachmentPreview) {
roomDetailViewModel.preventAttachmentPreview = false
roomDetailViewModel.handle(RoomDetailAction.SendMedia(attachments, false))
} else {
val grouped = attachments.toGroupedContentAttachmentData() val grouped = attachments.toGroupedContentAttachmentData()
if (grouped.notPreviewables.isNotEmpty()) { if (grouped.notPreviewables.isNotEmpty()) {
// Send the not previewable attachments right now (?) // Send the not previewable attachments right now (?)
@ -1357,8 +1363,10 @@ class RoomDetailFragment @Inject constructor(
startActivityForResult(intent, AttachmentsPreviewActivity.REQUEST_CODE) startActivityForResult(intent, AttachmentsPreviewActivity.REQUEST_CODE)
} }
} }
}
override fun onAttachmentsProcessFailed() { override fun onAttachmentsProcessFailed() {
roomDetailViewModel.preventAttachmentPreview = false
Toast.makeText(requireContext(), R.string.error_attachment, Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), R.string.error_attachment, Toast.LENGTH_SHORT).show()
} }

View File

@ -115,6 +115,8 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
var pendingAction: RoomDetailAction? = null var pendingAction: RoomDetailAction? = null
// Slot to keep a pending uri during permission request // Slot to keep a pending uri during permission request
var pendingUri: Uri? = null var pendingUri: Uri? = null
// Slot to store if we want to prevent preview of attachment
var preventAttachmentPreview = false
private var trackUnreadMessages = AtomicBoolean(false) private var trackUnreadMessages = AtomicBoolean(false)
private var mostRecentDisplayedEvent: TimelineEvent? = null private var mostRecentDisplayedEvent: TimelineEvent? = null