mirror of
https://github.com/jellyfin/jellyfin-android.git
synced 2026-10-26 16:45:26 +00:00
Re-use coroutine scope in DownloadBroadcastReceiver
This commit is contained in:
1 parent
6a4888f1b9
commit
b2e0658d81
1 file changed
+6
-6
@@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.core.component.KoinComponent
|
||||
@@ -24,6 +25,7 @@ class DownloadBroadcastReceiver : BroadcastReceiver(), KoinComponent {
|
||||
}
|
||||
|
||||
private val downloadManager by inject<DownloadManager>()
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action == ACTION_DOWNLOAD_CANCEL) {
|
||||
@@ -31,12 +33,10 @@ class DownloadBroadcastReceiver : BroadcastReceiver(), KoinComponent {
|
||||
if (id == -1L) return
|
||||
|
||||
val pendingResult = goAsync()
|
||||
CoroutineScope(SupervisorJob()).launch {
|
||||
try {
|
||||
downloadManager.cancel(id)
|
||||
} finally {
|
||||
pendingResult.finish()
|
||||
}
|
||||
coroutineScope.launch {
|
||||
downloadManager.cancel(id)
|
||||
}.invokeOnCompletion {
|
||||
pendingResult.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user