pull/1732/head
kunfei 3 years ago
parent ca0bb786da
commit 29f8f6be20
  1. 24
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -22,6 +22,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchKeyword
import io.legado.app.databinding.ActivityBookSearchBinding
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.*
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.book.source.manage.BookSourceActivity
@ -71,6 +72,22 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
initOtherView()
initData()
receiptIntent(intent)
viewModel.searchFinishCallback = {
if (it) {
val searchGroup = getPrefString("searchGroup")
if (!searchGroup.isNullOrEmpty()) {
alert(R.string.empty) {
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
cancelButton()
okButton {
putPrefString("searchGroup", "")
viewModel.searchKey = ""
viewModel.search(searchView.query.toString())
}
}
}
}
}
}
override fun onNewIntent(data: Intent?) {
@ -126,6 +143,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
searchView.clearFocus()
query?.let {
viewModel.saveSearchKey(query)
viewModel.searchKey = ""
viewModel.search(it)
}
openOrCloseHistory(false)
@ -235,7 +253,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
* 滚动到底部事件
*/
private fun scrollToBottom() {
if (!viewModel.isLoading && viewModel.searchKey.isNotEmpty() && loadMoreView.hasMore) {
if (viewModel.isSearchLiveData.value == false
&& viewModel.searchKey.isNotEmpty()
&& loadMoreView.hasMore
) {
viewModel.search("")
}
}
@ -371,6 +392,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
viewModel.deleteHistory(searchKeyword)
}
companion object {
fun start(context: Context, key: String?) {

@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.flowOn
class SearchViewModel(application: Application) : BaseViewModel(application) {
private val searchModel = SearchModel(viewModelScope)
var searchFinishCallback: ((isEmpty: Boolean) -> Unit)? = null
var isSearchLiveData = MutableLiveData<Boolean>()
var searchKey: String = ""
private var searchID = 0L
@ -32,6 +33,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
override fun onSearchFinish(isEmpty: Boolean) {
isSearchLiveData.postValue(false)
searchFinishCallback?.invoke(isEmpty)
}
override fun onSearchCancel() {

Loading…
Cancel
Save