-
public final class AttachmentsPickerViewModel extends ViewModel
ViewModel for the attachment picker. Drives picker tab state, device storage browsing, and the
isSelectedcheckmarks shown in attachments.Note: attachments reflects only the checkmark selection, not the full attachment list staged for the message. The composer attachment list is owned by MessageComposerViewModel.
The active tab and checkmark selection survive process death (e.g. "Don't keep activities"). Checkmarks are not reset on hide — they persist until the session is explicitly consumed (e.g. after a message is sent, a poll is created, or a command is selected).
-
-
Field Summary
Fields Modifier and Type Field Description private final Channelchannelprivate final AttachmentPickerModepickerModeprivate final BooleanisPickerVisibleprivate final List<AttachmentPickerItemState>attachmentsprivate final Flow<SubmittedAttachments>submittedAttachments
-
Constructor Summary
Constructors Constructor Description AttachmentsPickerViewModel(AttachmentStorageHelper storageHelper, StateFlow<ChannelState> channelState, SavedStateHandle savedStateHandle)AttachmentsPickerViewModel(AttachmentStorageHelper storageHelper, StateFlow<ChannelState> channelState)
-
Method Summary
Modifier and Type Method Description final ChannelgetChannel()The current Channel information. final AttachmentPickerModegetPickerMode()The active picker tab. final BooleangetIsPickerVisible()Whether the attachment picker is currently visible. final List<AttachmentPickerItemState>getAttachments()The attachment list for the active pickerMode, with each item's AttachmentPickerItemState.isSelected reflecting the current picker selection. final Flow<SubmittedAttachments>getSubmittedAttachments()final UnitsetPickerMode(AttachmentPickerMode mode)Switches the active picker tab. final UnitsetPickerVisible(Boolean visible)Shows or hides the attachment picker. final UnittogglePickerVisibility()Toggles the attachment picker visibility. final List<Attachment>getAttachmentsFromMetadata(List<AttachmentMetaData> metaData)Converts the given metaData into lightweight Attachments ready to be staged in the composer. final UnitloadAttachments()Loads attachment metadata from device storage for the current pickerMode. final UnitresolveAndSubmitUris(List<Uri> uris)Resolves uris from a system picker into Attachments and emits the result via submittedAttachments. -
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(AttachmentStorageHelper storageHelper, StateFlow<ChannelState> channelState, SavedStateHandle savedStateHandle)
- Parameters:
storageHelper- Provides device storage queries and attachment conversion.channelState- Provides the current ChannelState for channel-specific configuration.savedStateHandle- Persists picker tab and selection state across process death.
-
AttachmentsPickerViewModel
AttachmentsPickerViewModel(AttachmentStorageHelper storageHelper, StateFlow<ChannelState> channelState)
- Parameters:
storageHelper- Provides device storage queries and attachment conversion.channelState- Provides the current ChannelState for channel-specific configuration.
-
-
Method Detail
-
getChannel
final Channel getChannel()
The current Channel information.
-
getPickerMode
final AttachmentPickerMode getPickerMode()
The active picker tab.
-
getIsPickerVisible
final Boolean getIsPickerVisible()
Whether the attachment picker is currently visible.
-
getAttachments
final List<AttachmentPickerItemState> getAttachments()
The attachment list for the active pickerMode, with each item's AttachmentPickerItemState.isSelected reflecting the current picker selection.
-
getSubmittedAttachments
final Flow<SubmittedAttachments> getSubmittedAttachments()
-
setPickerMode
final Unit setPickerMode(AttachmentPickerMode mode)
Switches the active picker tab.
- Parameters:
mode- The AttachmentPickerMode to activate.
-
setPickerVisible
final Unit setPickerVisible(Boolean visible)
Shows or hides the attachment picker. Hiding clears cached media data but preserves the current selection so checkmarks remain when the picker is reopened.
- Parameters:
visible-trueto show the picker,falseto hide it.
-
togglePickerVisibility
final Unit togglePickerVisibility()
Toggles the attachment picker visibility.
-
getAttachmentsFromMetadata
final List<Attachment> getAttachmentsFromMetadata(List<AttachmentMetaData> metaData)
Converts the given metaData into lightweight Attachments ready to be staged in the composer.
- Parameters:
metaData- The metadata items to convert.
-
loadAttachments
final Unit loadAttachments()
Loads attachment metadata from device storage for the current pickerMode.
-
resolveAndSubmitUris
final Unit resolveAndSubmitUris(List<Uri> uris)
Resolves uris from a system picker into Attachments and emits the result via submittedAttachments.
URIs whose content is inaccessible (e.g. cloud-backed files not downloaded to the device) are detected via a lightweight accessibility check and excluded from the result. When any URI is inaccessible, hasUnresolvedAttachments is set so the UI layer can display an appropriate message.
- Parameters:
uris- Content URIs returned by the system picker.
-
-
-
-