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

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

Loading…
Cancel
Save