From b2033c0e59b9ed41a1a604c39395d728a91a8a90 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 14 Feb 2020 09:18:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/search/SearchActivity.kt | 11 ++++++----- .../io/legado/app/ui/book/search/SearchViewModel.kt | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 1f0acfd0e..ca67cad3d 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -56,7 +56,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se initRecyclerView() initSearchView() initOtherView() - initData() + initLiveData() initIntent() } @@ -169,7 +169,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } } - private fun initData() { + private fun initLiveData() { App.db.bookSourceDao().liveGroupEnabled().observe(this, Observer { groups.clear() it.map { group -> @@ -178,13 +178,14 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se upGroupMenu() }) viewModel.searchBookLiveData.observe(this, Observer { - setSearchItems(it) + upSearchItems(it, false) }) viewModel.isSearchLiveData.observe(this, Observer { if (it) { startSearch() } else { searchFinally() + upSearchItems(viewModel.searchBooks, true) } }) } @@ -263,8 +264,8 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } @Synchronized - private fun setSearchItems(items: List) { - if (System.currentTimeMillis() - refreshTime < 1000) { + private fun upSearchItems(items: List, isMandatoryUpdate: Boolean) { + if (!isMandatoryUpdate && System.currentTimeMillis() - refreshTime < 1000) { return } refreshTime = System.currentTimeMillis() 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 9c5ceadbe..a0ee00b4e 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 @@ -26,7 +26,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { var searchKey: String = "" var searchPage = 1 var isLoading = false - private var searchBooks = arrayListOf() + var searchBooks = arrayListOf() fun search(key: String) { task?.cancel()