|
|
@@ -4,11 +4,12 @@ import androidx.lifecycle.rxLifeScope
|
|
|
import com.miekir.mvp.view.IView
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.Job
|
|
|
+import java.util.concurrent.CopyOnWriteArrayList
|
|
|
|
|
|
//open class BasePresenterKt : AndroidViewModel(Utils.getApp()) {
|
|
|
abstract class BasePresenterKt<V : IView>: BasePresenter<V>() {
|
|
|
- private val mProgressJobList = ArrayList<Job>()
|
|
|
- private val mBackgroundJobList = ArrayList<Job>()
|
|
|
+ private val mProgressJobList = CopyOnWriteArrayList<Job>()
|
|
|
+ private val mBackgroundJobList = CopyOnWriteArrayList<Job>()
|
|
|
|
|
|
/**
|
|
|
* 所有网络请求都在 rxLifeScope 域中启动,当页面销毁时会自动
|
|
|
@@ -19,7 +20,14 @@ abstract class BasePresenterKt<V : IView>: BasePresenter<V>() {
|
|
|
*/
|
|
|
fun launchProgressTask(block: suspend CoroutineScope.() -> Unit, onError: ((Throwable) -> Unit)? = null): Job {
|
|
|
var job : Job? = null
|
|
|
- job = rxLifeScope.launch(block, onError, {}, { mProgressJobList.remove(job) })
|
|
|
+ job = rxLifeScope.launch(block, onError,
|
|
|
+ {
|
|
|
+ showProgress()
|
|
|
+ },
|
|
|
+ {
|
|
|
+ mProgressJobList.remove(job)
|
|
|
+ hideProgress()
|
|
|
+ })
|
|
|
mProgressJobList.add(job)
|
|
|
return job
|
|
|
}
|
|
|
@@ -47,7 +55,7 @@ abstract class BasePresenterKt<V : IView>: BasePresenter<V>() {
|
|
|
/**
|
|
|
* 取消任务
|
|
|
*/
|
|
|
- private fun recycleTask(jobList : ArrayList<Job>) {
|
|
|
+ private fun recycleTask(jobList : CopyOnWriteArrayList<Job>) {
|
|
|
val size = jobList.size
|
|
|
var index = 0
|
|
|
while (index < size) {
|