Commit ce7a78b
Refactor: Improve recording state management in AudioRecorderViewModel
This commit refactors the recording state management in `AudioRecorderViewModel`.
- Replaced `collectAsState` with `collectAsStateWithLifecycle` for better lifecycle awareness in `RecordingScreen`.
- Moved screen state management (`ScreenState`) into `AudioRecorderViewModel` from `RecordingScreen`.
- Simplified `onStartRecording` and `onStopRecording` by removing the `updateUI` callback and directly updating the screen state within the ViewModel.
- Ensured `onStopRecording` and `finishRecorder` are called in `onCleared` of the ViewModel.
- Initialized the recorder by calling `setupRecorder()` in the `init` block of `AudioRecorderViewModel`.
- Removed `DisposableEffect` for recorder setup and teardown from `RecordingScreen` as it's now handled by the ViewModel's lifecycle.1 parent 6f280ed commit ce7a78b
2 files changed
Lines changed: 26 additions & 21 deletions
File tree
shared/src/commonMain/kotlin/com/module/notelycompose/audio/presentation/AudioRecorderViewModel.kt
Lines changed: 22 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
16 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
17 | 28 | | |
18 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
19 | 32 | | |
20 | 33 | | |
21 | | - | |
22 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
23 | 37 | | |
24 | 38 | | |
25 | 39 | | |
| |||
39 | 53 | | |
40 | 54 | | |
41 | 55 | | |
| 56 | + | |
42 | 57 | | |
| 58 | + | |
| 59 | + | |
43 | 60 | | |
44 | 61 | | |
45 | 62 | | |
| |||
Lines changed: 4 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | 39 | | |
41 | | - | |
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
| |||
58 | 56 | | |
59 | 57 | | |
60 | 58 | | |
| 59 | + | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
| |||
92 | 91 | | |
93 | 92 | | |
94 | 93 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 94 | + | |
| 95 | + | |
105 | 96 | | |
106 | 97 | | |
107 | 98 | | |
| |||
115 | 106 | | |
116 | 107 | | |
117 | 108 | | |
118 | | - | |
119 | | - | |
120 | | - | |
| 109 | + | |
121 | 110 | | |
122 | 111 | | |
123 | 112 | | |
| |||
127 | 116 | | |
128 | 117 | | |
129 | 118 | | |
130 | | - | |
131 | 119 | | |
132 | 120 | | |
133 | 121 | | |
| |||
0 commit comments