From 22779b21506ef68adec475b49c465a8ff332012a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 30 Oct 2019 08:17:14 +0800 Subject: [PATCH] up --- .../app/ui/book/search/SearchActivity.kt | 20 +++++++++++-------- .../app/ui/book/search/SearchViewModel.kt | 12 +++++------ 2 files changed, 17 insertions(+), 15 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 2e2342348..36ebf13af 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 @@ -99,14 +99,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se search_view.clearFocus() query?.let { viewModel.saveSearchKey(query) - viewModel.search(it, { - refresh_progress_bar.isAutoLoading = true - initData() - fb_stop.visible() - }, { - refresh_progress_bar.isAutoLoading = false - fb_stop.invisible() - }) + viewModel.search(it) } return true } @@ -227,6 +220,17 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se historyData?.observe(this, Observer { historyKeyAdapter.setItems(it) }) } + override fun startSearch() { + refresh_progress_bar.isAutoLoading = true + initData() + fb_stop.visible() + } + + override fun searchFinally() { + refresh_progress_bar.isAutoLoading = false + fb_stop.invisible() + } + override fun showBookInfo(name: String, author: String) { viewModel.getSearchBook(name, author) { searchBook -> searchBook?.let { 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 3d8d715d9..a271f794a 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 @@ -25,11 +25,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { var isLoading = false private var searchBooks = arrayListOf() - fun search( - key: String, - start: (() -> Unit)? = null, - finally: (() -> Unit)? = null - ) { + fun search(key: String) { task?.cancel() if (key.isEmpty()) { searchPage++ @@ -39,7 +35,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } if (searchKey.isEmpty()) return startTime = System.currentTimeMillis() - start?.invoke() + callBack?.startSearch() task = execute { isLoading = true val searchGroup = context.getPrefString("searchGroup") ?: "" @@ -66,7 +62,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } task?.invokeOnCompletion { - finally?.invoke() + callBack?.searchFinally() isLoading = false } } @@ -176,5 +172,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { interface CallBack { var adapter: SearchAdapter + fun startSearch() + fun searchFinally() } }