pull/1732/head
kunfei 3 years ago
parent cf0a00a712
commit ca0bb786da
  1. 4
      app/src/main/java/io/legado/app/model/webBook/SearchModel.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -128,7 +128,7 @@ class SearchModel(private val scope: CoroutineScope) {
if (searchIndex >= bookSourceList.lastIndex
+ min(bookSourceList.size, threadCount)
) {
callBack?.onSearchFinish()
callBack?.onSearchFinish(searchBooks.isEmpty())
}
}
@ -214,7 +214,7 @@ class SearchModel(private val scope: CoroutineScope) {
interface CallBack {
fun onSearchStart()
fun onSearchSuccess(searchBooks: ArrayList<SearchBook>)
fun onSearchFinish()
fun onSearchFinish(isEmpty: Boolean)
fun onSearchCancel()
}

@ -17,7 +17,6 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
private val searchModel = SearchModel(viewModelScope)
var isSearchLiveData = MutableLiveData<Boolean>()
var searchKey: String = ""
var isLoading = false
private var searchID = 0L
val searchDataFlow = callbackFlow {
@ -25,21 +24,18 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
val callback = object : SearchModel.CallBack {
override fun onSearchStart() {
isSearchLiveData.postValue(true)
isLoading = true
}
override fun onSearchSuccess(searchBooks: ArrayList<SearchBook>) {
trySend(ArrayList(searchBooks))
}
override fun onSearchFinish() {
override fun onSearchFinish(isEmpty: Boolean) {
isSearchLiveData.postValue(false)
isLoading = false
}
override fun onSearchCancel() {
isSearchLiveData.postValue(false)
isLoading = false
}
}

Loading…
Cancel
Save