|
@@ -5,6 +5,7 @@ import com.xhly.corelib.Const
|
5
|
5
|
import com.xhly.corelib.utils.LogShow
|
6
|
6
|
import kotlinx.coroutines.CoroutineScope
|
7
|
7
|
import kotlinx.coroutines.Dispatchers
|
|
8
|
+import kotlinx.coroutines.cancel
|
8
|
9
|
import kotlinx.coroutines.launch
|
9
|
10
|
import java.util.LinkedList
|
10
|
11
|
import java.util.Queue
|
|
@@ -13,7 +14,7 @@ object DownLoadUtils {
|
13
|
14
|
val queue: Queue<DownloadItem> = LinkedList()
|
14
|
15
|
var callbackList = mutableListOf<DownloadCallback>()
|
15
|
16
|
var isRunning = false
|
16
|
|
-
|
|
17
|
+ var coroutineScope:CoroutineScope? =null
|
17
|
18
|
fun isEmpty(): Boolean {
|
18
|
19
|
return queue.isEmpty()
|
19
|
20
|
}
|
|
@@ -59,8 +60,10 @@ object DownLoadUtils {
|
59
|
60
|
if (isRunning) {
|
60
|
61
|
return
|
61
|
62
|
}
|
62
|
|
- val coroutineScope = CoroutineScope(Dispatchers.IO)
|
63
|
|
- coroutineScope.launch {
|
|
63
|
+ if (coroutineScope==null){
|
|
64
|
+ coroutineScope = CoroutineScope(Dispatchers.IO)
|
|
65
|
+ }
|
|
66
|
+ coroutineScope?.launch {
|
64
|
67
|
while (queue.size > 0) {
|
65
|
68
|
isRunning = true
|
66
|
69
|
val downItem = queue.peek()
|
|
@@ -121,6 +124,12 @@ object DownLoadUtils {
|
121
|
124
|
}
|
122
|
125
|
|
123
|
126
|
}
|
|
127
|
+
|
|
128
|
+ fun destroyDownLoad(){
|
|
129
|
+ coroutineScope?.cancel()
|
|
130
|
+ isRunning=false
|
|
131
|
+ queue.clear()
|
|
132
|
+ }
|
124
|
133
|
}
|
125
|
134
|
|
126
|
135
|
data class DownloadItem(val url: String, val tag: String, val savepath: String, var progress: Int,var pkgName:String)
|