From 5b6b1a3dfa0541ebae5f0e7a4eeef16e8a5dc073 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 15 May 2023 14:19:14 +0200 Subject: [PATCH] Fix crash in CommentsMainFragment --- .../github/libretube/ui/fragments/CommentsMainFragment.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt index ae2ae71aa..a09086955 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt @@ -34,12 +34,13 @@ class CommentsMainFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val binding = _binding ?: return val layoutManager = LinearLayoutManager(requireContext()) binding.commentsRV.layoutManager = layoutManager binding.commentsRV.setItemViewCacheSize(20) binding.commentsRV.viewTreeObserver.addOnScrollChangedListener { - val binding = _binding ?: return@addOnScrollChangedListener + val viewBinding = _binding ?: return@addOnScrollChangedListener // save the last scroll position to become used next time when the sheet is opened viewModel.currentCommentsPosition = layoutManager.findFirstVisibleItemPosition() @@ -48,11 +49,11 @@ class CommentsMainFragment : Fragment() { commentsSheetBinding?.btnScrollToTop?.isVisible = viewModel.currentCommentsPosition != 0 commentsSheetBinding?.btnScrollToTop?.setOnClickListener { // scroll back to the top / first comment - binding.commentsRV.smoothScrollToPosition(0) + viewBinding.commentsRV.smoothScrollToPosition(0) viewModel.currentCommentsPosition = 0 } - if (!binding.commentsRV.canScrollVertically(1)) { + if (!viewBinding.commentsRV.canScrollVertically(1)) { viewModel.fetchNextComments() } }