Merge pull request #1548 from Bnyro/master

replies performance improvements
This commit is contained in:
Bnyro 2022-10-13 14:16:54 +02:00 committed by GitHub
commit 5c2013ae56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,7 @@ import com.github.libretube.util.NavigationHelper
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class CommentsAdapter( class CommentsAdapter(
private val videoId: String, private val videoId: String,
@ -126,7 +127,7 @@ class CommentsAdapter(
} }
private fun fetchReplies(nextPage: String, onFinished: (CommentsPage) -> Unit) { private fun fetchReplies(nextPage: String, onFinished: (CommentsPage) -> Unit) {
CoroutineScope(Dispatchers.Main).launch { CoroutineScope(Dispatchers.IO).launch {
if (isLoading) return@launch if (isLoading) return@launch
isLoading = true isLoading = true
repliesPage = try { repliesPage = try {
@ -135,7 +136,9 @@ class CommentsAdapter(
Log.e(TAG(), "IOException, you might not have internet connection") Log.e(TAG(), "IOException, you might not have internet connection")
return@launch return@launch
} }
withContext(Dispatchers.Main) {
onFinished.invoke(repliesPage) onFinished.invoke(repliesPage)
}
isLoading = false isLoading = false
} }
} }