pull/2425/head
kunfei 2 years ago
parent 72b6d34096
commit 91111c9b76
  1. 43
      app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt

@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
@ -25,9 +26,10 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) {
private val binding by viewBinding(DialogSearchScopeBinding::bind) private val binding by viewBinding(DialogSearchScopeBinding::bind)
val callback: Callback get() = parentFragment as? Callback ?: activity as Callback val callback: Callback get() = parentFragment as? Callback ?: activity as Callback
var groups: List<String> = arrayListOf() var groups: List<String> = emptyList()
var sources: List<BookSource> = arrayListOf() var sources: List<BookSource> = emptyList()
val screenSources = arrayListOf<BookSource>()
var screenText: String? = null
val adapter by lazy { val adapter by lazy {
RecyclerAdapter() RecyclerAdapter()
@ -42,6 +44,7 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
initMenu() initMenu()
initSearchView()
initOtherView() initOtherView()
initData() initData()
upData() upData()
@ -52,6 +55,22 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) {
binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.menu.applyTint(requireContext())
} }
private fun initSearchView() {
val searchView = binding.toolBar.menu.findItem(R.id.menu_screen).actionView as SearchView
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
screenText = newText
upData()
return false
}
})
}
private fun initOtherView() { private fun initOtherView() {
binding.rgScope.setOnCheckedChangeListener { group, checkedId -> binding.rgScope.setOnCheckedChangeListener { group, checkedId ->
binding.toolBar.menu.findItem(R.id.menu_screen)?.isVisible = checkedId == R.id.rb_source binding.toolBar.menu.findItem(R.id.menu_screen)?.isVisible = checkedId == R.id.rb_source
@ -94,6 +113,18 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) {
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
private fun upData() { private fun upData() {
launch { launch {
withContext(IO) {
if (binding.rbSource.isChecked) {
sources.filter { source ->
screenText?.let { screenText ->
source.bookSourceName.contains(screenText)
} ?: true
}.let {
screenSources.clear()
screenSources.addAll(it)
}
}
}
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
} }
} }
@ -135,7 +166,7 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) {
} }
} }
is ItemRadioButtonBinding -> { is ItemRadioButtonBinding -> {
sources.getOrNull(position)?.let { screenSources.getOrNull(position)?.let {
holder.binding.radioButton.isChecked = selectSource == it holder.binding.radioButton.isChecked = selectSource == it
holder.binding.radioButton.text = it.bookSourceName holder.binding.radioButton.text = it.bookSourceName
} }
@ -163,7 +194,7 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) {
} }
} }
is ItemRadioButtonBinding -> { is ItemRadioButtonBinding -> {
sources.getOrNull(position)?.let { screenSources.getOrNull(position)?.let {
holder.binding.radioButton.isChecked = selectSource == it holder.binding.radioButton.isChecked = selectSource == it
holder.binding.radioButton.text = it.bookSourceName holder.binding.radioButton.text = it.bookSourceName
holder.binding.radioButton.setOnCheckedChangeListener { buttonView, isChecked -> holder.binding.radioButton.setOnCheckedChangeListener { buttonView, isChecked ->
@ -181,7 +212,7 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) {
override fun getItemCount(): Int { override fun getItemCount(): Int {
return if (binding.rbSource.isChecked) { return if (binding.rbSource.isChecked) {
sources.size screenSources.size
} else { } else {
groups.size groups.size
} }

Loading…
Cancel
Save