pull/736/head
gedoor 4 years ago
parent d6429d35b6
commit e99cfe1083
  1. 21
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  2. 21
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt

@ -208,21 +208,24 @@ class ChangeSourceDialog : BaseDialogFragment(),
*/ */
private fun upGroupMenu() { private fun upGroupMenu() {
val menu: Menu = binding.toolBar.menu val menu: Menu = binding.toolBar.menu
val selectedGroup = getPrefString("searchGroup") ?: "" val selectedGroup = getPrefString("searchGroup")
menu.removeGroup(R.id.source_group) menu.removeGroup(R.id.source_group)
var item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source)
if (selectedGroup == "") { var hasSelectedGroup = false
item?.isChecked = true
}
groups.sortedWith { o1, o2 -> groups.sortedWith { o1, o2 ->
o1.cnCompare(o2) o1.cnCompare(o2)
}.map { }.forEach { group ->
item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it) menu.add(R.id.source_group, Menu.NONE, Menu.NONE, group)?.let {
if (it == selectedGroup) { if (group == selectedGroup) {
item.isChecked = true it.isChecked = true
hasSelectedGroup = true
}
} }
} }
menu.setGroupCheckable(R.id.source_group, true, true) menu.setGroupCheckable(R.id.source_group, true, true)
if (!hasSelectedGroup) {
allItem.isChecked = true
}
} }
interface CallBack { interface CallBack {

@ -238,21 +238,24 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
* 更新分组菜单 * 更新分组菜单
*/ */
private fun upGroupMenu() = menu?.let { menu -> private fun upGroupMenu() = menu?.let { menu ->
val selectedGroup = getPrefString("searchGroup") ?: "" val selectedGroup = getPrefString("searchGroup")
menu.removeGroup(R.id.source_group) menu.removeGroup(R.id.source_group)
var item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source)
if (selectedGroup == "") { var hasSelectedGroup = false
item?.isChecked = true
}
groups.sortedWith { o1, o2 -> groups.sortedWith { o1, o2 ->
o1.cnCompare(o2) o1.cnCompare(o2)
}.map { }.forEach { group ->
item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it) menu.add(R.id.source_group, Menu.NONE, Menu.NONE, group)?.let {
if (it == selectedGroup) { if (group == selectedGroup) {
item?.isChecked = true it.isChecked = true
hasSelectedGroup = true
}
} }
} }
menu.setGroupCheckable(R.id.source_group, true, true) menu.setGroupCheckable(R.id.source_group, true, true)
if (!hasSelectedGroup) {
allItem.isChecked = true
}
} }
/** /**

Loading…
Cancel
Save