diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index d0f79f980..ef0d4661f 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -208,21 +208,24 @@ class ChangeSourceDialog : BaseDialogFragment(), */ private fun upGroupMenu() { val menu: Menu = binding.toolBar.menu - val selectedGroup = getPrefString("searchGroup") ?: "" + val selectedGroup = getPrefString("searchGroup") menu.removeGroup(R.id.source_group) - var item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) - if (selectedGroup == "") { - item?.isChecked = true - } + val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) + var hasSelectedGroup = false groups.sortedWith { o1, o2 -> o1.cnCompare(o2) - }.map { - item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it) - if (it == selectedGroup) { - item.isChecked = true + }.forEach { group -> + menu.add(R.id.source_group, Menu.NONE, Menu.NONE, group)?.let { + if (group == selectedGroup) { + it.isChecked = true + hasSelectedGroup = true + } } } menu.setGroupCheckable(R.id.source_group, true, true) + if (!hasSelectedGroup) { + allItem.isChecked = true + } } interface CallBack { diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 0db6df716..74bd36c27 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -238,21 +238,24 @@ class SearchActivity : VMBaseActivity - val selectedGroup = getPrefString("searchGroup") ?: "" + val selectedGroup = getPrefString("searchGroup") menu.removeGroup(R.id.source_group) - var item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) - if (selectedGroup == "") { - item?.isChecked = true - } + val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) + var hasSelectedGroup = false groups.sortedWith { o1, o2 -> o1.cnCompare(o2) - }.map { - item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it) - if (it == selectedGroup) { - item?.isChecked = true + }.forEach { group -> + menu.add(R.id.source_group, Menu.NONE, Menu.NONE, group)?.let { + if (group == selectedGroup) { + it.isChecked = true + hasSelectedGroup = true + } } } menu.setGroupCheckable(R.id.source_group, true, true) + if (!hasSelectedGroup) { + allItem.isChecked = true + } } /**