From c056b5d3f1008330690a14af80cebf03598b445d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 12 Oct 2022 21:07:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=B7=BB=E5=8A=A0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E8=8C=83=E5=9B=B4=E5=8F=AF=E9=80=89=E6=8B=A9=E5=8D=95?= =?UTF-8?q?=E4=B8=AA=E4=B9=A6=E6=BA=90=E5=92=8C=E5=88=86=E7=BB=84,?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/search/SearchActivity.kt | 17 ++++++- .../legado/app/ui/book/search/SearchScope.kt | 50 +++++++++++++++++++ .../app/ui/book/search/SearchScopeAdapter.kt | 31 ++++++++++++ .../app/ui/book/search/SearchScopeDialog.kt | 2 +- .../app/ui/book/search/SearchViewModel.kt | 1 + .../main/res/layout/activity_book_search.xml | 7 ++- 6 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/search/SearchScope.kt create mode 100644 app/src/main/java/io/legado/app/ui/book/search/SearchScopeAdapter.kt 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 1baed0576..5fad029d8 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 @@ -21,6 +21,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.help.IntentData import io.legado.app.help.config.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.* @@ -51,6 +52,9 @@ class SearchActivity : VMBaseActivity(searchScopeKey)?.let { searchScope -> + viewModel.searchScope = searchScope + } + } val key = intent?.getStringExtra("key") if (key.isNullOrBlank()) { searchView.findViewById(androidx.appcompat.R.id.search_src_text) @@ -411,8 +424,8 @@ class SearchActivity : VMBaseActivity? = null, + private val sources: List? = null +) { + + /** + * 搜索范围显示 + */ + fun getShowNames(): List { + val list = arrayListOf() + groups?.let { + list.addAll(it) + } + sources?.forEach { + list.add(it.bookSourceName) + } + if (list.isEmpty()) { + list.add("全部书源") + } + return list + } + + /** + * 搜索范围书源 + */ + fun getBookSources(): List { + val list = hashSetOf() + sources?.let { + list.addAll(sources) + } + groups?.forEach { group -> + appDb.bookSourceDao.getEnabledByGroup(group).let { + list.addAll(it) + } + } + if (list.isEmpty()) { + return appDb.bookSourceDao.allEnabled + } + return list.sortedBy { it.customOrder } + } + +} diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchScopeAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchScopeAdapter.kt new file mode 100644 index 000000000..4e85bdbb9 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchScopeAdapter.kt @@ -0,0 +1,31 @@ +package io.legado.app.ui.book.search + +import android.content.Context +import android.view.ViewGroup +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.RecyclerAdapter +import io.legado.app.databinding.ItemFilletTextBinding + +class SearchScopeAdapter(context: Context) : + RecyclerAdapter(context) { + + override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding { + return ItemFilletTextBinding.inflate(inflater, parent, false) + } + + override fun convert( + holder: ItemViewHolder, + binding: ItemFilletTextBinding, + item: String, + payloads: MutableList + ) { + binding.run { + textView.text = item + } + } + + override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt index fb8efc3c2..6a68ad846 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt @@ -23,7 +23,7 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope, true) /** * 搜索范围确认 */ - fun onSearchScopeOk() + fun onSearchScopeOk(searchScope: SearchScope) } 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 c56d5c8bd..d09364e90 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 @@ -34,6 +34,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { }) var searchFinishCallback: ((isEmpty: Boolean) -> Unit)? = null var isSearchLiveData = MutableLiveData() + var searchScope: SearchScope = SearchScope() var searchKey: String = "" private var searchID = 0L private var searchFlowCallBack: ((searchBooks: ArrayList) -> Unit)? = null diff --git a/app/src/main/res/layout/activity_book_search.xml b/app/src/main/res/layout/activity_book_search.xml index 50e9ccee3..8953199e9 100644 --- a/app/src/main/res/layout/activity_book_search.xml +++ b/app/src/main/res/layout/activity_book_search.xml @@ -31,7 +31,8 @@ + android:layout_height="match_parent" + tools:listitem="@layout/item_search" /> @@ -72,7 +73,9 @@ + android:layout_height="wrap_content" + android:orientation="horizontal" + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />