From cfefa87f574b3e9dbb177b0dc2e3606951d6b134 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 13 Oct 2022 14:16:37 +0200 Subject: [PATCH] replies performance improvements --- .../com/github/libretube/ui/adapters/CommentsAdapter.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt index b0932c34d..4424c1ddd 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt @@ -22,6 +22,7 @@ import com.github.libretube.util.NavigationHelper import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext class CommentsAdapter( private val videoId: String, @@ -126,7 +127,7 @@ class CommentsAdapter( } private fun fetchReplies(nextPage: String, onFinished: (CommentsPage) -> Unit) { - CoroutineScope(Dispatchers.Main).launch { + CoroutineScope(Dispatchers.IO).launch { if (isLoading) return@launch isLoading = true repliesPage = try { @@ -135,7 +136,9 @@ class CommentsAdapter( Log.e(TAG(), "IOException, you might not have internet connection") return@launch } - onFinished.invoke(repliesPage) + withContext(Dispatchers.Main) { + onFinished.invoke(repliesPage) + } isLoading = false } }