diff --git a/app/src/main/java/io/legado/app/model/webBook/SearchModel.kt b/app/src/main/java/io/legado/app/model/webBook/SearchModel.kt index 768e14b45..dcc5dca75 100644 --- a/app/src/main/java/io/legado/app/model/webBook/SearchModel.kt +++ b/app/src/main/java/io/legado/app/model/webBook/SearchModel.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) fun onSearchFinish(isEmpty: Boolean) - fun onSearchCancel() + fun onSearchCancel(exception: Exception? = null) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 44e4121f1..6a23549ef 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -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()