|
|
@ -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 = |
|
|
|
|
|
|
|
menu.add(R.id.menu_group_2, R.id.menu_1, Menu.NONE, getString(R.string.all_source)) |
|
|
|
|
|
|
|
.apply { |
|
|
|
if (searchScopeNames.isEmpty()) { |
|
|
|
if (searchScopeNames.isEmpty()) { |
|
|
|
isChecked = true |
|
|
|
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) |
|
|
|