pull/2468/head
kunfei 2 years ago
parent 4f741dff90
commit 717efff05c
  1. 20
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt

@ -116,26 +116,36 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
menu.removeGroup(R.id.menu_group_1) menu.removeGroup(R.id.menu_group_1)
menu.removeGroup(R.id.menu_group_2) menu.removeGroup(R.id.menu_group_2)
var hasChecked = false
val searchScopeNames = viewModel.searchScope.displayNames val searchScopeNames = viewModel.searchScope.displayNames
if (viewModel.searchScope.isSource()) { if (viewModel.searchScope.isSource()) {
menu.add(R.id.menu_group_1, Menu.NONE, Menu.NONE, searchScopeNames.first()).apply { menu.add(R.id.menu_group_1, Menu.NONE, Menu.NONE, searchScopeNames.first()).apply {
isChecked = true isChecked = true
hasChecked = true
} }
} }
menu.add(R.id.menu_group_2, R.id.menu_1, Menu.NONE, getString(R.string.all_source)).apply { val allSourceMenu =
if (searchScopeNames.isEmpty()) { menu.add(R.id.menu_group_2, R.id.menu_1, Menu.NONE, getString(R.string.all_source))
isChecked = true .apply {
} if (searchScopeNames.isEmpty()) {
} isChecked = true
hasChecked = true
}
}
groups?.forEach { groups?.forEach {
if (searchScopeNames.contains(it)) { if (searchScopeNames.contains(it)) {
menu.add(R.id.menu_group_1, Menu.NONE, Menu.NONE, it).apply { menu.add(R.id.menu_group_1, Menu.NONE, Menu.NONE, it).apply {
isChecked = true isChecked = true
hasChecked = true
} }
} else { } else {
menu.add(R.id.menu_group_2, Menu.NONE, Menu.NONE, it) menu.add(R.id.menu_group_2, Menu.NONE, Menu.NONE, it)
} }
} }
if (!hasChecked) {
viewModel.searchScope.update("")
allSourceMenu.isChecked = true
}
menu.setGroupCheckable(R.id.menu_group_1, true, false) menu.setGroupCheckable(R.id.menu_group_1, true, false)
menu.setGroupCheckable(R.id.menu_group_2, true, true) menu.setGroupCheckable(R.id.menu_group_2, true, true)
return super.onMenuOpened(featureId, menu) return super.onMenuOpened(featureId, menu)

Loading…
Cancel
Save