From b16a9dd5e692788706644a3f91e30a0477c17472 Mon Sep 17 00:00:00 2001 From: Nicolas Bourdin Date: Fri, 1 Nov 2024 16:04:48 +0100 Subject: [PATCH] fix: 'changeToolbarColorOnScroll' crash --- .../com/infomaniak/mail/utils/extensions/Extensions.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/infomaniak/mail/utils/extensions/Extensions.kt b/app/src/main/java/com/infomaniak/mail/utils/extensions/Extensions.kt index e91c5133ce..5a66389e87 100644 --- a/app/src/main/java/com/infomaniak/mail/utils/extensions/Extensions.kt +++ b/app/src/main/java/com/infomaniak/mail/utils/extensions/Extensions.kt @@ -49,6 +49,7 @@ import androidx.lifecycle.Lifecycle.Event import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LiveData +import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.widget.ViewPager2 import androidx.webkit.WebSettingsCompat @@ -114,6 +115,8 @@ import io.realm.kotlin.query.RealmQuery import io.realm.kotlin.query.Sort import io.realm.kotlin.types.RealmInstant import io.realm.kotlin.types.RealmObject +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import kotlinx.serialization.encodeToString import org.jsoup.nodes.Document import java.util.Calendar @@ -489,7 +492,9 @@ fun Fragment.changeToolbarColorOnScroll( valueAnimator = animateColorChange(oldColor, newColor, animate = true) { color -> oldColor = color toolbar.setBackgroundColor(color) - if (shouldUpdateStatusBar()) requireActivity().window.statusBarColor = color + if (shouldUpdateStatusBar()) { + viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) { requireActivity().window.statusBarColor = color } + } otherUpdates?.invoke(color) } }