@@ -78,9 +78,11 @@ import com.infomaniak.mail.utils.extensions.AttachmentExtensions.openAttachment
78
78
import dagger.hilt.android.AndroidEntryPoint
79
79
import io.sentry.Sentry
80
80
import io.sentry.SentryLevel
81
+ import kotlinx.coroutines.flow.combine
81
82
import kotlinx.coroutines.flow.filterNotNull
82
83
import kotlinx.coroutines.flow.launchIn
83
84
import kotlinx.coroutines.flow.onEach
85
+ import kotlinx.coroutines.launch
84
86
import javax.inject.Inject
85
87
86
88
@AndroidEntryPoint
@@ -175,6 +177,7 @@ class NewMessageFragment : Fragment() {
175
177
observeBodyLoader()
176
178
observeUiSignature()
177
179
observeUiQuote()
180
+ observeShimmering()
178
181
179
182
editorManager.observeEditorActions()
180
183
externalsManager.observeExternals(newMessageViewModel.arrivedFromExistingDraft())
@@ -192,6 +195,26 @@ class NewMessageFragment : Fragment() {
192
195
}
193
196
}
194
197
198
+ private fun observeShimmering () {
199
+ lifecycleScope.launch {
200
+ newMessageViewModel.isShimmering.collect(::setShimmerVisibility)
201
+ }
202
+ }
203
+
204
+ private fun setShimmerVisibility (isShimmering : Boolean ) = with (binding) {
205
+ fromMailAddress.isGone = isShimmering
206
+ subjectTextField.isGone = isShimmering
207
+ editor.isGone = isShimmering
208
+
209
+ fromLoader.isVisible = isShimmering
210
+ subjectLoader.isVisible = isShimmering
211
+ bodyLoader.isVisible = isShimmering
212
+
213
+ toField.setShimmerVisibility(isShimmering)
214
+ ccField.setShimmerVisibility(isShimmering)
215
+ bccField.setShimmerVisibility(isShimmering)
216
+ }
217
+
195
218
private fun initManagers () {
196
219
aiManager.initValues(
197
220
newMessageViewModel = newMessageViewModel,
@@ -311,9 +334,13 @@ class NewMessageFragment : Fragment() {
311
334
addCss(context.readRawResource(R .raw.style))
312
335
addCss(context.readRawResource(R .raw.editor_style))
313
336
314
- isEmptyFlow
315
- .filterNotNull()
316
- .onEach { isEditorEmpty -> newMessagePlaceholder.isVisible = isEditorEmpty }
337
+ val isPlaceholderVisible = combine(
338
+ isEmptyFlow.filterNotNull(),
339
+ newMessageViewModel.isShimmering,
340
+ ) { isEditorEmpty, isShimmering -> isEditorEmpty && ! isShimmering }
341
+
342
+ isPlaceholderVisible
343
+ .onEach { isVisible -> newMessagePlaceholder.isVisible = isVisible }
317
344
.launchIn(lifecycleScope)
318
345
}
319
346
@@ -342,21 +369,6 @@ class NewMessageFragment : Fragment() {
342
369
}
343
370
}
344
371
345
- private fun hideLoader () = with (binding) {
346
-
347
- fromMailAddress.isVisible = true
348
- subjectTextField.isVisible = true
349
- editor.isVisible = true
350
-
351
- fromLoader.isGone = true
352
- subjectLoader.isGone = true
353
- bodyLoader.isGone = true
354
-
355
- toField.hideLoader()
356
- ccField.hideLoader()
357
- bccField.hideLoader()
358
- }
359
-
360
372
private fun showKeyboardInCorrectView (isToFieldEmpty : Boolean ) = with (recipientFieldsManager) {
361
373
when (newMessageViewModel.draftMode()) {
362
374
DraftMode .REPLY ,
@@ -460,7 +472,6 @@ class NewMessageFragment : Fragment() {
460
472
461
473
private fun observeInitResult () {
462
474
newMessageViewModel.initResult.observe(viewLifecycleOwner) { (draft, signatures) ->
463
- hideLoader()
464
475
configureUiWithDraftData(draft)
465
476
setupFromField(signatures)
466
477
editorManager.setupEditorActions()
0 commit comments