Commit 1e0c3b1
authored
Reduce boilerplate code when using composables (#3027)
* Add Compose support to AbstractFragment
* Add `createComposeView` to create a ComposeView with app theme
* Add `addComposableToRoot` to add a composable to a fragment's view
* Refactor: Replace ComposeView with createComposeView
* Replaced the ComposeView with a `createComposeView()` method in `AbstractFragment`.
* Removed unnecessary `AppTheme` composables.
* Minor refactor of dialogs.
* Refactor: Extract common logic for setting Compose content
* Introduce `setComposableContent` extension function for `ComposeView` to encapsulate setting the content with `AppTheme`.
* Use `setComposableContent` instead of manually calling `setContent` with `AppTheme` in `OfflineAreasFragment`, `SyncStatusFragment`, and `AbstractTaskFragment`.
* Update `createComposeView` in `AbstractFragment` to use `setComposableContent`.
* Refactor: Replace custom dialogs with `ConfirmationDialog` composable
- Removes `SignOutConfirmationDialog` & `LocationPermissionDialog` composables.
- Replaces the custom dialog implementation with the generic `ConfirmationDialog`
- Removes unused imports & code.
- Use `setComposableContent` instead of `apply` to add compose view.
- Removes `PermissionDeniedDialog` & replace with `ConfirmationDialog`
- Removes unused `AppTheme` composable
* Refactor composable dialog rendering
* Rename `addComposableToRoot` to `renderComposableDialog` for better clarity.
* Add helper methods `createComposeView` and `setComposableContent` in `AbstractFragment` to improve the readability.
* Update all usages of `addComposableToRoot` to `renderComposableDialog`.
* Refactor: Extract compose view creation logic to utility class
* Refactor: Move state management out of Composable in HomeScreenFragment
The changes move the `showUserDetailsDialog` and `showSignOutDialog` state variables and related functions outside of the Composable function in `HomeScreenFragment`. This fixes an issue where navigation clicks would stop working after the first time when adding a Compose view dynamically to the fragment. The state is now managed in the fragment class itself. The Composable still renders the dialogs based on these state variables.
* Refactor: Simplify instructions and confirmation dialogs
* Simplify `InstructionsDialog` to manage its own state, eliminating the need for external state management.
* Simplify `InstructionsDialog` usages in `DrawAreaTaskFragment` and `DropPinTaskFragment`.
* Simplify `ConfirmationDialog` to manage its own state, eliminating the need for external state management.
* Add a preview to `InstructionsDialog`.
* Refactor: Remove unnecessary MutableState from DataSharingTermsDialog
* Simplify DataSharingTermsDialog by removing the MutableState parameter.
* The dialog now uses an internal mutable state to manage its visibility.
* Remove `showDataSharingTermsDialog` from `DataSharingTermsDialog` parameters
* Remove `showDataSharingTermsDialog` from `DataSharingTermsDialog` usage in tests.
* Remove `showDataSharingTermsDialog` from `HomeScreenMapContainerFragment`.
* Fix unit tests
* Fix import order1 parent feae70b commit 1e0c3b1
File tree
24 files changed
+365
-552
lines changed- app/src
- main/java/com/google/android/ground
- ui
- compose
- datacollection
- components
- tasks
- location
- multiplechoice
- number
- photo
- point
- polygon
- text
- home
- mapcontainer
- offlineareas
- selector
- surveyselector
- syncstatus
- util
- test/java/com/google/android/ground/ui/home
24 files changed
+365
-552
lines changedLines changed: 22 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | | - | |
29 | 27 | | |
30 | 28 | | |
31 | 29 | | |
| |||
40 | 38 | | |
41 | 39 | | |
42 | 40 | | |
43 | | - | |
| 41 | + | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
| |||
84 | 82 | | |
85 | 83 | | |
86 | 84 | | |
87 | | - | |
88 | | - | |
89 | | - | |
| 85 | + | |
90 | 86 | | |
91 | 87 | | |
92 | 88 | | |
| |||
101 | 97 | | |
102 | 98 | | |
103 | 99 | | |
104 | | - | |
| 100 | + | |
105 | 101 | | |
106 | 102 | | |
107 | | - | |
| 103 | + | |
108 | 104 | | |
109 | 105 | | |
110 | 106 | | |
| |||
128 | 124 | | |
129 | 125 | | |
130 | 126 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
155 | 144 | | |
156 | | - | |
| 145 | + | |
157 | 146 | | |
158 | 147 | | |
159 | 148 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
Lines changed: 20 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
42 | | - | |
| 41 | + | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
| |||
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
172 | 165 | | |
173 | 166 | | |
174 | 167 | | |
175 | | - | |
| 168 | + | |
176 | 169 | | |
177 | 170 | | |
178 | 171 | | |
| |||
202 | 195 | | |
203 | 196 | | |
204 | 197 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | 212 | | |
230 | 213 | | |
231 | 214 | | |
| |||
Lines changed: 38 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
| 34 | + | |
31 | 35 | | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
52 | 72 | | |
Lines changed: 16 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| |||
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
48 | | - | |
| 47 | + | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
235 | 231 | | |
236 | 232 | | |
237 | 233 | | |
| |||
245 | 241 | | |
246 | 242 | | |
247 | 243 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
258 | 248 | | |
259 | | - | |
| 249 | + | |
260 | 250 | | |
261 | 251 | | |
262 | 252 | | |
| |||
0 commit comments