replies performance improvements

This commit is contained in:
Bnyro 2022-10-13 14:16:37 +02:00
parent e836625223
commit cfefa87f57

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
} }
onFinished.invoke(repliesPage) withContext(Dispatchers.Main) {
onFinished.invoke(repliesPage)
}
isLoading = false isLoading = false
} }
} }