Merge pull request #4859 from Bnyro/master

fix: crash when navigating too fast in replies
This commit is contained in:
Bnyro 2023-09-26 13:04:02 +02:00 committed by GitHub
commit 16c6c69bc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,7 +31,6 @@ import kotlinx.coroutines.withContext
class CommentsRepliesFragment : Fragment() { class CommentsRepliesFragment : Fragment() {
private var _binding: FragmentCommentsBinding? = null private var _binding: FragmentCommentsBinding? = null
private val binding get() = _binding!!
private lateinit var repliesPage: CommentsPage private lateinit var repliesPage: CommentsPage
private lateinit var repliesAdapter: CommentsAdapter private lateinit var repliesAdapter: CommentsAdapter
@ -45,7 +44,7 @@ class CommentsRepliesFragment : Fragment() {
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View { ): View {
_binding = FragmentCommentsBinding.inflate(inflater, container, false) _binding = FragmentCommentsBinding.inflate(inflater, container, false)
return binding.root return _binding!!.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -54,6 +53,8 @@ class CommentsRepliesFragment : Fragment() {
val videoId = arguments.getString(IntentData.videoId, "") val videoId = arguments.getString(IntentData.videoId, "")
val comment = arguments.parcelable<Comment>(IntentData.comment)!! val comment = arguments.parcelable<Comment>(IntentData.comment)!!
val binding = _binding ?: return
repliesAdapter = CommentsAdapter( repliesAdapter = CommentsAdapter(
null, null,
videoId, videoId,
@ -96,10 +97,10 @@ class CommentsRepliesFragment : Fragment() {
nextPage: String, nextPage: String,
repliesAdapter: CommentsAdapter repliesAdapter: CommentsAdapter
) { ) {
binding.progress.isVisible = true _binding?.progress?.isVisible = true
fetchReplies(videoId, nextPage) { fetchReplies(videoId, nextPage) {
repliesAdapter.updateItems(it.comments) repliesAdapter.updateItems(it.comments)
binding.progress.isGone = true _binding?.progress?.isGone = true
} }
} }
@ -111,6 +112,7 @@ class CommentsRepliesFragment : Fragment() {
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
if (isLoading) return@launch if (isLoading) return@launch
isLoading = true isLoading = true
repliesPage = try { repliesPage = try {
RetrofitInstance.api.getCommentsNextPage(videoId, nextPage) RetrofitInstance.api.getCommentsNextPage(videoId, nextPage)
} catch (e: Exception) { } catch (e: Exception) {