#
Attachment GalleryAttachmentGalleryActivity
is an Activity used to display attachments that the users have sent in the chat. It is an image gallery where users can view, share, and download the pictures, and use a menu to easily navigate through them.
Light Mode | Dark Mode |
---|---|
![]() | ![]() |
![]() | ![]() |
#
Handling ActionsThere are four user actions that can be customized by the following handlers:
AttachmentReplyOptionHandler
AttachmentShowInChatOptionHandler
AttachmentDownloadOptionHandler
AttachmentDeleteOptionHandler
These are called when the user selects one of the options from the overflow menu in the top right:
Light | Dark |
---|---|
![]() | ![]() |
As the gallery is usually opened from MessageListView
, you can set these handlers on that View the following way:
- Kotlin
- Java
messageListView.setAttachmentReplyOptionClickHandler { resultItem ->
resultItem.messageId
// Handle reply to attachment
}
messageListView.setAttachmentShowInChatOptionClickHandler { resultItem ->
resultItem.messageId
// Handle show in chat
}
messageListView.setDownloadOptionHandler { resultItem ->
resultItem.assetUrl
// Handle download the attachment
}
messageListView.setAttachmentDeleteOptionClickHandler { resultItem ->
resultItem.assetUrl
resultItem.imageUrl
// Handle delete
}
messageListView.setAttachmentReplyOptionClickHandler(resultItem -> {
resultItem.getMessageId();
// Handle reply to attachment
});
messageListView.setAttachmentShowInChatOptionClickHandler(resultItem -> {
resultItem.getMessageId();
// Handle show in chat
});
messageListView.setDownloadOptionHandler(resultItem -> {
resultItem.getAssetUrl();
// Handle download the attachment
});
messageListView.setAttachmentDeleteOptionClickHandler(resultItem -> {
resultItem.getAssetUrl();
resultItem.getImageUrl();
// Handle delete
});
#
Navigating To Attachment GalleryBy default, the Attachment Gallery is opened when a user clicks on an attachment in MessageListView
. In that case, all actions mentioned above have a default implementation, which can be changed by overriding MessageListView
's handlers.
You can also navigate to AttachmentGalleryActivity
manually from anywhere else in your code. In this case, you will need to implement all available actions:
- Kotlin
- Java
// Create Attachment Gallery Destination
val destination = AttachmentGalleryDestination(
requireContext(),
attachmentReplyOptionHandler = { resultItem ->
// Handle reply
},
attachmentShowInChatOptionHandler = { resultItem ->
// Handle show image in chat
},
attachmentDownloadOptionHandler = { resultItem ->
// Handle download image
},
attachmentDeleteOptionClickHandler = { resultItem ->
// Handle delete image
},
)
// Register destination with the ActivityResultRegistry
activity?.activityResultRegistry?.let { registry ->
destination.register(registry)
}
// Set the data to display
destination.setData(attachmentGalleryItems = listOf(), attachmentIndex = 0)
// Fire the navigation request
ChatUI.navigator.navigate(destination)
// Create Attachment Gallery Destination
AttachmentGalleryDestination destination = new AttachmentGalleryDestination(
activity,
resultItem -> {
// Handle reply
},
resultItem -> {
// Handle show image in chat
},
resultItem -> {
// Handle download image
},
resultItem -> {
// Handle delete image
}
);
// Register destination with the ActivityResultRegistry
destination.register(activity.getActivityResultRegistry());
// Set the data to display
int attachmentIndex = 0;
destination.setData(Collections.emptyList(), attachmentIndex);
// Fire the navigation request
ChatUI.getNavigator().navigate(destination);