pull/2670/head
kunfei 2 years ago
parent 60e7466c93
commit 09e025d65f
  1. 7
      app/src/main/java/io/legado/app/model/webBook/SearchModel.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -5,6 +5,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.ui.book.search.SearchScope
@ -55,6 +56,10 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
searchBooks.clear()
callBack.onSearchSuccess(searchBooks)
bookSourceList.addAll(callBack.getSearchScope().getBookSources())
if (bookSourceList.isEmpty()) {
callBack.onSearchCancel(NoStackTraceException("启用书源为空"))
return
}
} else {
searchPage++
}
@ -197,7 +202,7 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
fun onSearchStart()
fun onSearchSuccess(searchBooks: ArrayList<SearchBook>)
fun onSearchFinish(isEmpty: Boolean)
fun onSearchCancel()
fun onSearchCancel(exception: Exception? = null)
}
}

@ -10,6 +10,7 @@ import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchKeyword
import io.legado.app.help.config.AppConfig
import io.legado.app.model.webBook.SearchModel
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
@ -41,9 +42,13 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
searchFinishCallback?.invoke(isEmpty)
}
override fun onSearchCancel() {
override fun onSearchCancel(exception: Exception?) {
isSearchLiveData.postValue(false)
exception?.let {
context.toastOnUi(it.localizedMessage)
}
}
})
var searchFinishCallback: ((isEmpty: Boolean) -> Unit)? = null
var isSearchLiveData = MutableLiveData<Boolean>()

Loading…
Cancel
Save