Remove usage of GlobalScope

This commit is contained in:
Benoit Marty 2021-05-14 14:56:31 +02:00
parent 555eada37a
commit 4112d28127

View File

@ -25,8 +25,9 @@ import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.files.LocalFilesHelper import im.vector.app.core.files.LocalFilesHelper
import im.vector.app.features.session.coroutineScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
@ -39,6 +40,9 @@ class VideoContentRenderer @Inject constructor(private val localFilesHelper: Loc
private val activeSessionHolder: ActiveSessionHolder, private val activeSessionHolder: ActiveSessionHolder,
private val errorFormatter: ErrorFormatter) { private val errorFormatter: ErrorFormatter) {
private val sessionScope: CoroutineScope
get() = activeSessionHolder.getActiveSession().coroutineScope
@Parcelize @Parcelize
data class Data( data class Data(
override val eventId: String, override val eventId: String,
@ -76,7 +80,7 @@ class VideoContentRenderer @Inject constructor(private val localFilesHelper: Loc
thumbnailView.isVisible = true thumbnailView.isVisible = true
loadingView.isVisible = true loadingView.isVisible = true
GlobalScope.launch { sessionScope.launch {
val result = runCatching { val result = runCatching {
activeSessionHolder.getActiveSession().fileService() activeSessionHolder.getActiveSession().fileService()
.downloadFile( .downloadFile(
@ -119,7 +123,7 @@ class VideoContentRenderer @Inject constructor(private val localFilesHelper: Loc
thumbnailView.isVisible = true thumbnailView.isVisible = true
loadingView.isVisible = true loadingView.isVisible = true
GlobalScope.launch { sessionScope.launch {
val result = runCatching { val result = runCatching {
activeSessionHolder.getActiveSession().fileService() activeSessionHolder.getActiveSession().fileService()
.downloadFile( .downloadFile(