pull/32/head
Administrator 5 years ago
parent a4d60b4abe
commit df422bcb11
  1. 15
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt
  2. 3
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  3. 5
      app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt

@ -19,7 +19,7 @@ class Coroutine<T>() {
}
private var interceptor: Coroutine<T>? = null
private var job: Job? = null
private lateinit var job: Job
private var start: (suspend CoroutineScope.() -> Unit)? = null
private var execute: (suspend CoroutineScope.(T?) -> Unit)? = null
@ -32,13 +32,13 @@ class Coroutine<T>() {
private var errorReturn: Result<T>? = null
val isCancelled: Boolean
get() = job?.isCancelled ?: false
get() = job.isCancelled
val isActive: Boolean
get() = job?.isActive ?: true
get() = job.isActive
val isCompleted: Boolean
get() = job?.isCompleted ?: false
get() = job.isCompleted
private constructor(
scope: CoroutineScope,
@ -119,7 +119,11 @@ class Coroutine<T>() {
//取消当前任务
fun cancel(cause: CancellationException? = null) {
job?.cancel(cause)
job.cancel(cause)
}
fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle{
return job.invokeOnCompletion(handler)
}
private suspend fun executeInternal(scope: CoroutineScope, block: suspend CoroutineScope.() -> T) {
@ -134,6 +138,7 @@ class Coroutine<T>() {
success?.invoke(scope, value)
true
} ?: false
if (!consume) {
error?.invoke(scope, e)
}

@ -11,7 +11,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchShow
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.getViewModel
@ -45,6 +44,8 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
viewModel.search(it, { startTime ->
content_view.showContentView()
initData(startTime)
}, {
})
}
return true

@ -1,6 +1,7 @@
package io.legado.app.ui.search
import android.app.Application
import android.util.Log
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.help.coroutine.Coroutine
@ -36,6 +37,10 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
}.onError {
it.printStackTrace()
}
task?.invokeOnCompletion {
Log.e("TAG", "complete")
}
}
fun stop() {

Loading…
Cancel
Save