Commit 930e090
authored
Message composer attachments improvements (part 1) (#6175)
* Remove `selectedAttachments` `MutableStateFlow` from `MessageComposerController`. The list of attachments is now managed directly within the `MessageComposerState`.
This change centralizes state management, removing the need to separately observe `selectedAttachments` and update the main state. All functions that previously interacted with `selectedAttachments` now update the `attachments` list within the `MessageComposerState`.
* Remove legacy saveAttachmentsOnDismiss flow
* Introduce AttachmentPickerActions for picker events
Replaced the `AttachmentPickerAction` sealed interface with a dedicated `AttachmentPickerActions` data class. This change centralizes all attachment picker event handlers into a single, cohesive class, improving the API's clarity and simplifying its usage.
Key changes:
- Introduced the `AttachmentPickerActions` data class to hold all picker-related callbacks.
- Added default factory methods (`defaultActions`, `pickerDefaults`) for easy instantiation.
- Removed the now-obsolete `AttachmentPickerAction` sealed interface and its implementations.
- Updated `AttachmentPicker`, `AttachmentPickerContent`, and related components to accept the new `AttachmentPickerActions` class instead of multiple lambda parameters.
* Refactor attachment handling to `AttachmentStorageHelper`
The `StorageHelperWrapper` has been replaced by `AttachmentStorageHelper` and moved from the Compose module to the `ui-common` module.
This refactoring separates concerns more clearly: `AttachmentStorageHelper` now manages converting between `AttachmentMetaData` and the `Attachment` model, while the lower-level `StorageHelper` continues to handle direct interactions with the device's storage.
This change also introduces a deferred file resolution mechanism. Attachments are now created without an `upload` file first and are resolved just before sending. This is more efficient as it avoids unnecessary file copying until the user confirms the action.
* Replace `StorageHelper` with `AttachmentStorageHelper` in ui-components module
* Replace `StorageHelper` with `AttachmentStorageHelper` in compose module
* Refactor attachment handling to `AttachmentStorageHelper`
The `StorageHelperWrapper` has been replaced by `AttachmentStorageHelper` and moved from the Compose module to the `ui-common` module.
This refactoring separates concerns more clearly: `AttachmentStorageHelper` now manages converting between `AttachmentMetaData` and the `Attachment` model, while the lower-level `StorageHelper` continues to handle direct interactions with the device's storage.
This change also introduces a deferred file resolution mechanism. Attachments are now created without an `upload` file first and are resolved just before sending. This is more efficient as it avoids unnecessary file copying until the user confirms the action.
* Resolve deferred attachments before sending message
* Refactor attachment processing out of ViewModels. Leaf composables emit events upward via simple callbacks, the parent wires them to ViewModel operations, and data flows back down through Compose state.
* Use stable keys for attachment previews
The `LazyRow`s for media and file attachment previews now use stable keys, derived from the attachment's source URI or file path. This improves performance and prevents recomposition issues when the list of attachments changes.
* Animate composer attachment preview items
* Update attachment picker selection by replacing the `AttachmentPickerItemState.Selection` sealed interface with a simple `isSelected` boolean. This change simplifies the state management for both single and multiple selection modes.
Key changes:
- Replaced `Selection.Selected(position)` and `Selection.Unselected` with a `isSelected` boolean in `AttachmentPickerItemState`.
- Removed the `allowMultipleSelection` parameter from `ImagesPicker`, as it is no longer needed.
- The selected item indicator now consistently displays a checkmark, removing the numeric position badge.
- The `AttachmentsPickerViewModel` logic has been updated to work with the new `isSelected` state, simplifying selection, deselection, and cross-tab state synchronization.
* Auto-scroll attachment previews on new item
* detekt
* Update location picker icon
* Refactor AttachmentsPickerViewModel API
This change refactors the public API of `AttachmentsPickerViewModel` to improve clarity and consistency.
Key changes include:
- Renamed `isShowingAttachments` to `isPickerVisible`.
- Renamed `changeAttachmentState()` to `setPickerVisible()`.
- Renamed `toggleAttachmentState()` to `togglePickerVisibility()`.
- Renamed `changePickerMode()` to `setPickerMode()`.
- Renamed `changeSelectedAttachments()` to `toggleSelection()`.
- Renamed `removeSelectedAttachment()` to `deselectAttachment()`.
- Renamed `getAttachmentsFromMetaData()` to `getAttachmentsFromMetadata()`.
* Keep attachment selection after closing the picker. Clear only after sending a message.
* Fixes after merge
* Revert `rememberCaptureMediaLauncher` exclusion
* typo
* fix kdoc
* Drop attachments that fail to resolve
* Persist attachment picker state
The attachment picker's visibility and active tab are now persisted using `SavedStateHandle`. This ensures the UI state is restored after process death, such as when returning from a system file picker with "Don't keep activities" enabled.
* Refactor `submittedAttachments` to use `Channel`
Convert the `submittedAttachments` `SharedFlow` into a `Channel`. This change ensures that attachment submission events are retained until they are consumed.
* Persist camera capture file paths
The file paths for photos and videos captured with the camera are now saved and restored.
This allows the captured media to be recovered after process death.
Fix camera picker launching multiple times
* Only call `onAttachmentsSelected` when attachments are not empty
* merge AttachmentPickerActions initialization
* No need toMutableList
* Remove `EXTRA_SOURCE_URI` after resolving attachment
* Enforce attachment selection order
* Cancel previous attachment loading job
* Refactor `sendMessage` to resolve attachments internally
* Fix detekt issues1 parent 510f706 commit 930e090
60 files changed
Lines changed: 1810 additions & 1909 deletions
File tree
- stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui
- location
- stream-chat-android-compose
- api
- src
- main
- java/io/getstream/chat/android/compose
- state/messages/attachments
- ui
- attachments/content
- chats
- components/attachments
- files
- images
- messages
- attachments
- factory
- media
- poll
- theme
- util
- extensions/internal
- viewmodel/messages
- test
- kotlin/io/getstream/chat/android/compose
- ui
- components/attachments/images
- messages/attachments
- viewmodel/messages
- snapshots/images
- stream-chat-android-docs/src/main/kotlin/io/getstream/chat/docs/kotlin
- compose/messages
- cookbook/ui
- stream-chat-android-ui-common
- api
- src
- main/kotlin/io/getstream/chat/android/ui/common
- contract/internal
- feature/messages/composer
- helper/internal
- test/kotlin/io/getstream/chat/android/ui/common
- feature/messages/composer
- helper/internal
- stream-chat-android-ui-components
- api
- src
- main/kotlin/io/getstream/chat/android/ui
- feature/messages/composer/attachment/picker/factory
- file/internal
- media/internal
- system/internal
- viewmodel/messages
- test/kotlin/io/getstream/chat/android/ui/viewmodels/messages
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
362 | | - | |
| 362 | + | |
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
| |||
Lines changed: 11 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
101 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
Lines changed: 86 additions & 119 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2302 | 2302 | | |
2303 | 2303 | | |
2304 | 2304 | | |
2305 | | - | |
| 2305 | + | |
2306 | 2306 | | |
2307 | 2307 | | |
2308 | 2308 | | |
| |||
Lines changed: 3 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 33 | + | |
| 34 | + | |
Lines changed: 13 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| 62 | + | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
67 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
68 | 74 | | |
69 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
70 | 78 | | |
71 | 79 | | |
72 | 80 | | |
| |||
98 | 106 | | |
99 | 107 | | |
100 | 108 | | |
101 | | - | |
102 | | - | |
103 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
104 | 112 | | |
105 | 113 | | |
106 | 114 | | |
| |||
Lines changed: 13 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | | - | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| |||
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| 75 | + | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
80 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
81 | 87 | | |
82 | | - | |
| 88 | + | |
| 89 | + | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
| |||
100 | 107 | | |
101 | 108 | | |
102 | 109 | | |
| 110 | + | |
103 | 111 | | |
104 | | - | |
| 112 | + | |
105 | 113 | | |
106 | 114 | | |
107 | | - | |
| 115 | + | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
726 | 726 | | |
727 | 727 | | |
728 | 728 | | |
729 | | - | |
| 729 | + | |
730 | 730 | | |
731 | 731 | | |
732 | 732 | | |
| |||
Lines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| |||
215 | 214 | | |
216 | 215 | | |
217 | 216 | | |
218 | | - | |
| 217 | + | |
219 | 218 | | |
220 | 219 | | |
221 | 220 | | |
| |||
241 | 240 | | |
242 | 241 | | |
243 | 242 | | |
244 | | - | |
| 243 | + | |
245 | 244 | | |
246 | 245 | | |
247 | 246 | | |
248 | 247 | | |
249 | 248 | | |
250 | | - | |
| 249 | + | |
251 | 250 | | |
252 | 251 | | |
253 | 252 | | |
| |||
0 commit comments