Skip to content

Commit 5460f73

Browse files
committed
Don't display the editor's placeholder while the screen is shimmering
1 parent e1cc3ec commit 5460f73

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageFragment.kt

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ import com.infomaniak.mail.utils.extensions.AttachmentExtensions.openAttachment
7878
import dagger.hilt.android.AndroidEntryPoint
7979
import io.sentry.Sentry
8080
import io.sentry.SentryLevel
81+
import kotlinx.coroutines.flow.combine
8182
import kotlinx.coroutines.flow.filterNotNull
8283
import kotlinx.coroutines.flow.launchIn
8384
import kotlinx.coroutines.flow.onEach
85+
import kotlinx.coroutines.launch
8486
import javax.inject.Inject
8587

8688
@AndroidEntryPoint
@@ -175,6 +177,7 @@ class NewMessageFragment : Fragment() {
175177
observeBodyLoader()
176178
observeUiSignature()
177179
observeUiQuote()
180+
observeShimmering()
178181

179182
editorManager.observeEditorActions()
180183
externalsManager.observeExternals(newMessageViewModel.arrivedFromExistingDraft())
@@ -192,6 +195,26 @@ class NewMessageFragment : Fragment() {
192195
}
193196
}
194197

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+
195218
private fun initManagers() {
196219
aiManager.initValues(
197220
newMessageViewModel = newMessageViewModel,
@@ -311,9 +334,13 @@ class NewMessageFragment : Fragment() {
311334
addCss(context.readRawResource(R.raw.style))
312335
addCss(context.readRawResource(R.raw.editor_style))
313336

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 }
317344
.launchIn(lifecycleScope)
318345
}
319346

@@ -342,21 +369,6 @@ class NewMessageFragment : Fragment() {
342369
}
343370
}
344371

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-
360372
private fun showKeyboardInCorrectView(isToFieldEmpty: Boolean) = with(recipientFieldsManager) {
361373
when (newMessageViewModel.draftMode()) {
362374
DraftMode.REPLY,
@@ -460,7 +472,6 @@ class NewMessageFragment : Fragment() {
460472

461473
private fun observeInitResult() {
462474
newMessageViewModel.initResult.observe(viewLifecycleOwner) { (draft, signatures) ->
463-
hideLoader()
464475
configureUiWithDraftData(draft)
465476
setupFromField(signatures)
466477
editorManager.setupEditorActions()

app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ import kotlinx.coroutines.*
7979
import kotlinx.coroutines.channels.Channel
8080
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
8181
import kotlinx.coroutines.channels.ReceiveChannel
82+
import kotlinx.coroutines.flow.MutableStateFlow
83+
import kotlinx.coroutines.flow.StateFlow
8284
import kotlinx.coroutines.flow.map
8385
import org.jsoup.Jsoup
8486
import org.jsoup.nodes.Document
@@ -145,6 +147,9 @@ class NewMessageViewModel @Inject constructor(
145147
// Needs to trigger every time the Fragment is recreated
146148
val initResult = MutableLiveData<InitResult>()
147149

150+
private val _isShimmering = MutableStateFlow(true)
151+
val isShimmering: StateFlow<Boolean> = _isShimmering
152+
148153
val currentMailbox by lazy { mailboxController.getMailbox(AccountUtils.currentUserId, AccountUtils.currentMailboxId)!! }
149154

150155
val currentMailboxLive = mailboxController.getMailboxAsync(
@@ -217,6 +222,7 @@ class NewMessageViewModel @Inject constructor(
217222
realm.writeBlocking { draftController.upsertDraft(it, realm = this) }
218223
it.saveSnapshot(it.uiBody.content)
219224
it.initLiveData(signatures)
225+
_isShimmering.emit(false)
220226

221227
initResult.postValue(InitResult(it, signatures))
222228
}

app/src/main/java/com/infomaniak/mail/ui/newMessage/RecipientFieldView.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ class RecipientFieldView @JvmOverloads constructor(
164164
}
165165
}
166166

167-
fun hideLoader() = with(binding) {
168-
textInput.isVisible = true
169-
chevronContainer.isVisible = true
167+
fun setShimmerVisibility(isShimmering: Boolean) = with(binding) {
168+
textInput.isGone = isShimmering
169+
chevronContainer.isGone = isShimmering
170170

171-
loader.isGone = true
171+
loader.isVisible = isShimmering
172172
}
173173

174174
fun showKeyboardInTextInput() {

0 commit comments

Comments
 (0)