mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
搜索添加搜索范围可选择单个书源和分组,未完成
This commit is contained in:
@@ -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<ActivityBookSearchBinding, SearchViewModel
|
||||
setHasStableIds(true)
|
||||
}
|
||||
}
|
||||
private val searchScopeAdapter by lazy {
|
||||
SearchScopeAdapter(this)
|
||||
}
|
||||
private val historyKeyAdapter by lazy {
|
||||
HistoryKeyAdapter(this, this).apply {
|
||||
setHasStableIds(true)
|
||||
@@ -181,8 +185,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
|
||||
private fun initRecyclerView() {
|
||||
binding.recyclerView.setEdgeEffectColor(primaryColor)
|
||||
binding.rvSearchScope.setEdgeEffectColor(primaryColor)
|
||||
binding.rvBookshelfSearch.setEdgeEffectColor(primaryColor)
|
||||
binding.rvHistoryKey.setEdgeEffectColor(primaryColor)
|
||||
binding.rvSearchScope.adapter = searchScopeAdapter
|
||||
binding.rvBookshelfSearch.layoutManager = FlexboxLayoutManager(this)
|
||||
binding.rvBookshelfSearch.adapter = bookAdapter
|
||||
binding.rvHistoryKey.layoutManager = FlexboxLayoutManager(this)
|
||||
@@ -230,6 +236,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
searchScopeAdapter.setItems(viewModel.searchScope.getShowNames())
|
||||
viewModel.isSearchLiveData.observe(this) {
|
||||
if (it) {
|
||||
startSearch()
|
||||
@@ -253,6 +260,12 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
}
|
||||
|
||||
private fun receiptIntent(intent: Intent? = null) {
|
||||
val searchScopeKey = intent?.getStringExtra("searchScopeKey")
|
||||
searchScopeKey?.let {
|
||||
IntentData.get<SearchScope>(searchScopeKey)?.let { searchScope ->
|
||||
viewModel.searchScope = searchScope
|
||||
}
|
||||
}
|
||||
val key = intent?.getStringExtra("key")
|
||||
if (key.isNullOrBlank()) {
|
||||
searchView.findViewById<TextView>(androidx.appcompat.R.id.search_src_text)
|
||||
@@ -411,8 +424,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
}
|
||||
|
||||
|
||||
override fun onSearchScopeOk() {
|
||||
|
||||
override fun onSearchScopeOk(searchScope: SearchScope) {
|
||||
viewModel.searchScope = searchScope
|
||||
}
|
||||
|
||||
private fun alertSearchScope() {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.legado.app.ui.book.search
|
||||
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.BookSource
|
||||
|
||||
/**
|
||||
* 搜索范围
|
||||
*/
|
||||
data class SearchScope(
|
||||
private val groups: List<String>? = null,
|
||||
private val sources: List<BookSource>? = null
|
||||
) {
|
||||
|
||||
/**
|
||||
* 搜索范围显示
|
||||
*/
|
||||
fun getShowNames(): List<String> {
|
||||
val list = arrayListOf<String>()
|
||||
groups?.let {
|
||||
list.addAll(it)
|
||||
}
|
||||
sources?.forEach {
|
||||
list.add(it.bookSourceName)
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
list.add("全部书源")
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索范围书源
|
||||
*/
|
||||
fun getBookSources(): List<BookSource> {
|
||||
val list = hashSetOf<BookSource>()
|
||||
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 }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String, ItemFilletTextBinding>(context) {
|
||||
|
||||
override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding {
|
||||
return ItemFilletTextBinding.inflate(inflater, parent, false)
|
||||
}
|
||||
|
||||
override fun convert(
|
||||
holder: ItemViewHolder,
|
||||
binding: ItemFilletTextBinding,
|
||||
item: String,
|
||||
payloads: MutableList<Any>
|
||||
) {
|
||||
binding.run {
|
||||
textView.text = item
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope, true)
|
||||
/**
|
||||
* 搜索范围确认
|
||||
*/
|
||||
fun onSearchScopeOk()
|
||||
fun onSearchScopeOk(searchScope: SearchScope)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
|
||||
})
|
||||
var searchFinishCallback: ((isEmpty: Boolean) -> Unit)? = null
|
||||
var isSearchLiveData = MutableLiveData<Boolean>()
|
||||
var searchScope: SearchScope = SearchScope()
|
||||
var searchKey: String = ""
|
||||
private var searchID = 0L
|
||||
private var searchFlowCallBack: ((searchBooks: ArrayList<SearchBook>) -> Unit)? = null
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/item_search" />
|
||||
|
||||
</io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout>
|
||||
|
||||
@@ -72,7 +73,9 @@
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_search_scope"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_book_show"
|
||||
|
||||
Reference in New Issue
Block a user