Prevent crash that happened once

This commit is contained in:
Sylvain Berfini 2022-01-10 10:14:59 +01:00
parent 44a61a2be2
commit 2ed6fa3246
2 changed files with 13 additions and 5 deletions

View file

@ -42,6 +42,10 @@ abstract class GenericFragment<T : ViewDataBinding> : Fragment() {
protected val binding get() = _binding!!
protected var useMaterialSharedAxisXForwardAnimation = true
protected fun isBindingAvailable(): Boolean {
return _binding != null
}
protected val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
lifecycleScope.launch {

View file

@ -212,11 +212,15 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
.addOnGlobalLayoutListener(
object : OnGlobalLayoutListener {
override fun onGlobalLayout() {
binding.chatMessagesList
.viewTreeObserver
.removeOnGlobalLayoutListener(this)
Log.i("[Chat Room] Messages have been displayed, scrolling to first unread message if any")
scrollToFirstUnreadMessageOrBottom(false)
if (isBindingAvailable()) {
binding.chatMessagesList
.viewTreeObserver
.removeOnGlobalLayoutListener(this)
Log.i("[Chat Room] Messages have been displayed, scrolling to first unread message if any")
scrollToFirstUnreadMessageOrBottom(false)
} else {
Log.e("[Chat Room] Binding not available in onGlobalLayout callback!")
}
}
}
)