feat: 优化代码

pull/167/head
kunfei 5 years ago
parent bed5c2e34a
commit 78a2f6ce2f
  1. 5
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -16,7 +16,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import java.util.concurrent.Executors import java.util.concurrent.Executors
class SearchViewModel(application: Application) : BaseViewModel(application) { class SearchViewModel(application: Application) : BaseViewModel(application) {
@ -34,10 +33,9 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
* 开始搜索 * 开始搜索
*/ */
fun search(key: String) { fun search(key: String) {
launch {
task?.cancel() task?.cancel()
if (key.isEmpty() && searchKey.isEmpty()) { if (key.isEmpty() && searchKey.isEmpty()) {
return@launch return
} else if (key.isEmpty()) { } else if (key.isEmpty()) {
isLoading = true isLoading = true
searchPage++ searchPage++
@ -88,7 +86,6 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
isLoading = false isLoading = false
} }
} }
}
/** /**
* 精确搜索处理 * 精确搜索处理

Loading…
Cancel
Save