pull/2424/head
kunfei 2 years ago
parent e5c2b9e180
commit e53e0b7dbb
  1. 22
      app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt
  2. 15
      app/src/main/res/menu/book_search_scope.xml

@ -14,6 +14,7 @@ import io.legado.app.databinding.DialogSearchScopeBinding
import io.legado.app.databinding.ItemCheckBoxBinding import io.legado.app.databinding.ItemCheckBoxBinding
import io.legado.app.databinding.ItemRadioButtonBinding import io.legado.app.databinding.ItemRadioButtonBinding
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.applyTint
import io.legado.app.utils.setLayout import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -24,8 +25,9 @@ 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 = arrayListOf<String>() var groups: List<String> = arrayListOf()
var sources = arrayListOf<BookSource>() var sources: List<BookSource> = arrayListOf()
val adapter by lazy { val adapter by lazy {
RecyclerAdapter() RecyclerAdapter()
@ -39,14 +41,20 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) {
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
initMenu()
initOtherView() initOtherView()
initData() initData()
upData() upData()
} }
private fun initMenu() {
binding.toolBar.inflateMenu(R.menu.change_source)
binding.toolBar.menu.applyTint(requireContext())
}
private fun initOtherView() { private fun initOtherView() {
binding.rgScope.setOnCheckedChangeListener { _, _ -> binding.rgScope.setOnCheckedChangeListener { group, checkedId ->
binding.toolBar.menu.findItem(R.id.menu_screen)?.isVisible = checkedId == R.id.rb_source
upData() upData()
} }
binding.tvCancel.setOnClickListener { binding.tvCancel.setOnClickListener {
@ -73,9 +81,11 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) {
private fun initData() { private fun initData() {
launch { launch {
withContext(IO) { groups = withContext(IO) {
groups.addAll(appDb.bookSourceDao.allGroups) appDb.bookSourceDao.allGroups
sources.addAll(appDb.bookSourceDao.allEnabled) }
sources = withContext(IO) {
appDb.bookSourceDao.allEnabled
} }
upData() upData()
} }

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_screen"
android:title="@string/screen"
android:icon="@drawable/ic_screen"
android:visible="false"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />
</menu>
Loading…
Cancel
Save