mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -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>()
|
||||
|
||||
Reference in New Issue
Block a user