From 09e025d65fb86ff17e66c31149264082ae8d5cf8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 1 Jan 2023 20:08:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/webBook/SearchModel.kt | 7 ++++++- .../java/io/legado/app/ui/book/search/SearchViewModel.kt | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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()