-
public final class AttachmentsPickerViewModel extends ViewModel
ViewModel responsible for handling the state and business logic of attachments.
Used to load file and media images that are then connected to the UI. It also keeps state of the selected items and prepares items before sending them.
-
-
Field Summary
Fields Modifier and Type Field Description private final Channelchannelprivate AttachmentsPickerModeattachmentsPickerModeprivate List<AttachmentPickerItemState>imagesprivate List<AttachmentPickerItemState>filesprivate List<AttachmentPickerItemState>attachmentsprivate List<AttachmentPickerItemState>pollsprivate final BooleanhasPickedFilesprivate final BooleanhasPickedImagesprivate final BooleanhasPickedAttachmentsprivate BooleanisShowingAttachments
-
Constructor Summary
Constructors Constructor Description AttachmentsPickerViewModel(StorageHelperWrapper storageHelper, StateFlow<ChannelState> channelState, SavedStateHandle savedStateHandle)AttachmentsPickerViewModel(StorageHelperWrapper storageHelper, StateFlow<ChannelState> channelState)
-
Method Summary
Modifier and Type Method Description final ChannelgetChannel()The information for the current Channel. final AttachmentsPickerModegetAttachmentsPickerMode()Currently selected picker mode. final UnitsetAttachmentsPickerMode(AttachmentsPickerMode attachmentsPickerMode)final List<AttachmentPickerItemState>getImages()List of images available, from the system. final UnitsetImages(List<AttachmentPickerItemState> images)List of images available, from the system. final List<AttachmentPickerItemState>getFiles()List of files available, from the system. final UnitsetFiles(List<AttachmentPickerItemState> files)List of files available, from the system. final List<AttachmentPickerItemState>getAttachments()List of attachments available, from the system. final UnitsetAttachments(List<AttachmentPickerItemState> attachments)List of attachments available, from the system. final List<AttachmentPickerItemState>getPolls()List of polls available, from the system. final UnitsetPolls(List<AttachmentPickerItemState> polls)List of polls available, from the system. final BooleangetHasPickedFiles()final BooleangetHasPickedImages()final BooleangetHasPickedAttachments()final BooleangetIsShowingAttachments()final UnitsetIsShowingAttachments(Boolean isShowingAttachments)final UnitloadData()Loads all the items based on the current type. final UnitchangeAttachmentPickerMode(AttachmentsPickerMode attachmentsPickerMode, Function0<Boolean> hasPermission)Changes the currently selected AttachmentsPickerMode and loads the required data. final UnitchangeAttachmentState(Boolean showAttachments)Notifies the ViewModel if we should show attachments or not. final UnitchangeSelectedAttachments(AttachmentPickerItemState attachmentItem)Triggered when an AttachmentMetaData is selected in the list. final List<Attachment>getSelectedAttachments()Loads up the currently selected attachments. final List<Attachment>getAttachmentsFromUris(List<Uri> uris)Transforms selected file Uris to a list of Attachments we can upload. final List<Attachment>getAttachmentsFromMetaData(List<AttachmentMetaData> metaData)Transforms the selected meta data into a list of Attachments we can upload. final UnitdismissAttachments()Triggered when we dismiss the attachments picker. -
Methods inherited from class io.getstream.chat.android.compose.viewmodel.messages.AttachmentsPickerViewModel
addCloseable, addCloseable, addCloseable, getCloseable -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
AttachmentsPickerViewModel
AttachmentsPickerViewModel(StorageHelperWrapper storageHelper, StateFlow<ChannelState> channelState, SavedStateHandle savedStateHandle)
- Parameters:
storageHelper- Wrapper around storage utilities for loading media and files.channelState- The state of the channel where attachments are being picked.savedStateHandle- Handle for persisting state across process death.
-
AttachmentsPickerViewModel
AttachmentsPickerViewModel(StorageHelperWrapper storageHelper, StateFlow<ChannelState> channelState)
- Parameters:
storageHelper- Wrapper around storage utilities for loading media and files.channelState- The state of the channel where attachments are being picked.
-
-
Method Detail
-
getChannel
final Channel getChannel()
The information for the current Channel.
-
getAttachmentsPickerMode
final AttachmentsPickerMode getAttachmentsPickerMode()
Currently selected picker mode. Images, Files or MediaCapture.
-
setAttachmentsPickerMode
final Unit setAttachmentsPickerMode(AttachmentsPickerMode attachmentsPickerMode)
-
getImages
final List<AttachmentPickerItemState> getImages()
List of images available, from the system.
-
setImages
final Unit setImages(List<AttachmentPickerItemState> images)
List of images available, from the system.
-
getFiles
final List<AttachmentPickerItemState> getFiles()
List of files available, from the system.
-
setFiles
final Unit setFiles(List<AttachmentPickerItemState> files)
List of files available, from the system.
-
getAttachments
final List<AttachmentPickerItemState> getAttachments()
List of attachments available, from the system.
-
setAttachments
final Unit setAttachments(List<AttachmentPickerItemState> attachments)
List of attachments available, from the system.
-
getPolls
final List<AttachmentPickerItemState> getPolls()
List of polls available, from the system.
-
setPolls
final Unit setPolls(List<AttachmentPickerItemState> polls)
List of polls available, from the system.
-
getHasPickedFiles
final Boolean getHasPickedFiles()
-
getHasPickedImages
final Boolean getHasPickedImages()
-
getHasPickedAttachments
final Boolean getHasPickedAttachments()
-
getIsShowingAttachments
final Boolean getIsShowingAttachments()
-
setIsShowingAttachments
final Unit setIsShowingAttachments(Boolean isShowingAttachments)
-
loadData
@Deprecated(message = This method is no longer used and will be removed in future versions.) final Unit loadData()
Loads all the items based on the current type.
-
changeAttachmentPickerMode
final Unit changeAttachmentPickerMode(AttachmentsPickerMode attachmentsPickerMode, Function0<Boolean> hasPermission)
Changes the currently selected AttachmentsPickerMode and loads the required data. If no permission is granted will not try and load data to avoid crashes.
- Parameters:
attachmentsPickerMode- The currently selected picker mode.hasPermission- Handler to check if there is permission for wanted action.
-
changeAttachmentState
final Unit changeAttachmentState(Boolean showAttachments)
Notifies the ViewModel if we should show attachments or not.
- Parameters:
showAttachments- If we need to show attachments or hide them.
-
changeSelectedAttachments
final Unit changeSelectedAttachments(AttachmentPickerItemState attachmentItem)
Triggered when an AttachmentMetaData is selected in the list. Added or removed from the corresponding list, be it files or images, based on attachmentsPickerMode.
- Parameters:
attachmentItem- The selected item.
-
getSelectedAttachments
final List<Attachment> getSelectedAttachments()
Loads up the currently selected attachments. It uses the attachmentsPickerMode to know which attachments to use - files or images.
It maps all files to a list of Attachment objects, based on their type.
-
getAttachmentsFromUris
final List<Attachment> getAttachmentsFromUris(List<Uri> uris)
Transforms selected file Uris to a list of Attachments we can upload.
- Parameters:
uris- Selected Uris.
-
getAttachmentsFromMetaData
final List<Attachment> getAttachmentsFromMetaData(List<AttachmentMetaData> metaData)
Transforms the selected meta data into a list of Attachments we can upload.
- Parameters:
metaData- List of attachment meta data items.
-
dismissAttachments
final Unit dismissAttachments()
Triggered when we dismiss the attachments picker. We reset the state to show images and clear the items for now, until the user needs them again.
-
-
-
-