|
|
@ -7,13 +7,9 @@ import androidx.lifecycle.MutableLiveData |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.data.api.CommonHttpApi |
|
|
|
import io.legado.app.data.api.CommonHttpApi |
|
|
|
import io.legado.app.data.entities.SearchBook |
|
|
|
import io.legado.app.data.entities.SearchBook |
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
|
|
|
|
import io.legado.app.help.coroutine.Function |
|
|
|
|
|
|
|
import io.legado.app.help.http.HttpHelper |
|
|
|
import io.legado.app.help.http.HttpHelper |
|
|
|
import kotlinx.coroutines.* |
|
|
|
import kotlinx.coroutines.delay |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
|
|
|
import org.jetbrains.anko.error |
|
|
|
import org.jetbrains.anko.error |
|
|
|
import java.lang.StringBuilder |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearchViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class SearchViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
|
@ -37,11 +33,13 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
// { error { "${it.message}" } }, |
|
|
|
// { error { "${it.message}" } }, |
|
|
|
// { finally?.let { it() } }) |
|
|
|
// { finally?.let { it() } }) |
|
|
|
|
|
|
|
|
|
|
|
val task = Coroutine.of { |
|
|
|
execute { |
|
|
|
val response: String = HttpHelper.getApiService<CommonHttpApi>( |
|
|
|
val response: String = HttpHelper.getApiService<CommonHttpApi>( |
|
|
|
"http://www.baidu.com" |
|
|
|
"http://www.baidu.com" |
|
|
|
).get("http://www.baidu.com").await() |
|
|
|
).get("http://www.baidu.com").await() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delay(4000L) |
|
|
|
|
|
|
|
|
|
|
|
Log.e("TAG1", Thread.currentThread().name) |
|
|
|
Log.e("TAG1", Thread.currentThread().name) |
|
|
|
|
|
|
|
|
|
|
|
response |
|
|
|
response |
|
|
@ -59,7 +57,6 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
Log.e("TAG!", "finally") |
|
|
|
Log.e("TAG!", "finally") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// task.cancel() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|