Show preview when sending attachment from the keyboard (#2440)

It's actually a revert of a3b205b310
This commit is contained in:
Benoit Marty 2020-12-01 17:11:05 +01:00 committed by Benoit Marty
parent 38843f74ab
commit eb30b9fae9
3 changed files with 9 additions and 19 deletions

View File

@ -15,6 +15,7 @@ Bugfix 🐛:
- Fix cancellation of sending event (#2438)
- Double bottomsheet effect after verify with passphrase
- EditText cursor jumps to the start while typing fast (#2469)
- Show preview when sending attachment from the keyboard (#2440)
Translations 🗣:
-

View File

@ -1176,11 +1176,9 @@ class RoomDetailFragment @Inject constructor(
}
private fun sendUri(uri: Uri): Boolean {
roomDetailViewModel.preventAttachmentPreview = true
val shareIntent = Intent(Intent.ACTION_SEND, uri)
val isHandled = attachmentsHelper.handleShareIntent(requireContext(), shareIntent)
if (!isHandled) {
roomDetailViewModel.preventAttachmentPreview = false
Toast.makeText(requireContext(), R.string.error_handling_incoming_share, Toast.LENGTH_SHORT).show()
}
return isHandled
@ -1936,24 +1934,18 @@ class RoomDetailFragment @Inject constructor(
// AttachmentsHelper.Callback
override fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) {
if (roomDetailViewModel.preventAttachmentPreview) {
roomDetailViewModel.preventAttachmentPreview = false
roomDetailViewModel.handle(RoomDetailAction.SendMedia(attachments, false))
} else {
val grouped = attachments.toGroupedContentAttachmentData()
if (grouped.notPreviewables.isNotEmpty()) {
// Send the not previewable attachments right now (?)
roomDetailViewModel.handle(RoomDetailAction.SendMedia(grouped.notPreviewables, false))
}
if (grouped.previewables.isNotEmpty()) {
val intent = AttachmentsPreviewActivity.newIntent(requireContext(), AttachmentsPreviewArgs(grouped.previewables))
contentAttachmentActivityResultLauncher.launch(intent)
}
val grouped = attachments.toGroupedContentAttachmentData()
if (grouped.notPreviewables.isNotEmpty()) {
// Send the not previewable attachments right now (?)
roomDetailViewModel.handle(RoomDetailAction.SendMedia(grouped.notPreviewables, false))
}
if (grouped.previewables.isNotEmpty()) {
val intent = AttachmentsPreviewActivity.newIntent(requireContext(), AttachmentsPreviewArgs(grouped.previewables))
contentAttachmentActivityResultLauncher.launch(intent)
}
}
override fun onAttachmentsProcessFailed() {
roomDetailViewModel.preventAttachmentPreview = false
Toast.makeText(requireContext(), R.string.error_attachment, Toast.LENGTH_SHORT).show()
}

View File

@ -128,9 +128,6 @@ class RoomDetailViewModel @AssistedInject constructor(
// Slot to keep a pending action during permission request
var pendingAction: RoomDetailAction? = null
// Slot to store if we want to prevent preview of attachment
var preventAttachmentPreview = false
private var trackUnreadMessages = AtomicBoolean(false)
private var mostRecentDisplayedEvent: TimelineEvent? = null