折叠换源分组菜单,修复自动换组UI不更新。

This commit is contained in:
Jason Yao 2022-02-03 22:52:33 -05:00
parent bb70568b3e
commit c40aedfb77
4 changed files with 74 additions and 53 deletions

2
.gitignore vendored
View File

@ -12,3 +12,5 @@ node_modules/
/app/google
/app/gradle.properties
package-lock.json
.idea/*

View File

@ -32,7 +32,14 @@ import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.ui.widget.dialog.WaitDialog
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.StartActivityContract
import io.legado.app.utils.applyTint
import io.legado.app.utils.cnCompare
import io.legado.app.utils.dpToPx
import io.legado.app.utils.observeEvent
import io.legado.app.utils.setLayout
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate
@ -72,6 +79,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
cancelButton()
okButton {
AppConfig.searchGroup = ""
upGroupMenu()
viewModel.startSearch()
}
}
@ -233,8 +241,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
R.id.menu_start_stop -> viewModel.startOrStopSearch()
R.id.menu_source_manage -> startActivity<BookSourceActivity>()
R.id.menu_refresh_list -> viewModel.startRefreshList()
else -> if (item?.groupId == R.id.source_group) {
if (!item.isChecked) {
else -> if (item?.groupId == R.id.source_group && !item.isChecked) {
item.isChecked = true
if (item.title.toString() == getString(R.string.all_source)) {
AppConfig.searchGroup = ""
@ -245,7 +252,6 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
viewModel.refresh()
}
}
}
return false
}
@ -339,7 +345,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
* 更新分组菜单
*/
private fun upGroupMenu() {
val menu: Menu = binding.toolBar.menu
binding.toolBar.menu.findItem(R.id.menu_group)?.subMenu?.let { menu ->
val selectedGroup = AppConfig.searchGroup
menu.removeGroup(R.id.source_group)
val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source)
@ -359,6 +365,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
allItem.isChecked = true
}
}
}
override fun observeLiveBus() {
observeEvent<String>(EventBus.SOURCE_CHANGED) {

View File

@ -97,6 +97,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
noButton()
yesButton {
AppConfig.searchGroup = ""
upGroupMenu()
viewModel.startSearch()
}
}
@ -262,8 +263,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
}
R.id.menu_start_stop -> viewModel.startOrStopSearch()
R.id.menu_source_manage -> startActivity<BookSourceActivity>()
else -> if (item?.groupId == R.id.source_group) {
if (!item.isChecked) {
else -> if (item?.groupId == R.id.source_group && !item.isChecked) {
item.isChecked = true
if (item.title.toString() == getString(R.string.all_source)) {
AppConfig.searchGroup = ""
@ -274,7 +274,6 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
viewModel.refresh()
}
}
}
return false
}
@ -359,7 +358,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
* 更新分组菜单
*/
private fun upGroupMenu() {
val menu: Menu = binding.toolBar.menu
binding.toolBar.menu.findItem(R.id.menu_group)?.subMenu?.let { menu ->
val selectedGroup = AppConfig.searchGroup
menu.removeGroup(R.id.source_group)
val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source)
@ -379,6 +378,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
allItem.isChecked = true
}
}
}
override fun observeLiveBus() {
observeEvent<String>(EventBus.SOURCE_CHANGED) {

View File

@ -51,5 +51,17 @@
android:title="@string/load_toc"
android:checkable="true"
app:showAsAction="never" />
<item
android:id="@+id/menu_group"
android:title="@string/group">
<menu>
<group
android:id="@+id/source_group"
android:checkableBehavior="single">
</group>
</menu>
</item>
</menu>