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 5d2eaa5dc..6d8d9f394 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 @@ -98,6 +98,11 @@ class CommentsMainFragment : Fragment() { binding.errorTV.isVisible = true return@observe } + + // sometimes the received comments have the same size as the existing ones + // which causes comments.subList to throw InvalidArgumentException + if (commentsAdapter.itemCount > it.comments.size) return@observe + commentsAdapter.updateItems( // only add the new comments to the recycler view it.comments.subList(commentsAdapter.itemCount, it.comments.size) diff --git a/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt b/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt index 8db9afdca..d084f75d6 100644 --- a/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt +++ b/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt @@ -56,9 +56,13 @@ class CommentsViewModel : ViewModel() { Log.e(TAG(), e.toString()) return@launch } + val updatedPage = commentsPage.value?.apply { - comments += response.comments.filterNonEmptyComments() + comments += response.comments + .filterNonEmptyComments() + .filter { comment -> comments.none { it.commentId == comment.commentId } } } + nextPage = response.nextpage commentsPage.postValue(updatedPage) isLoading = false