diff --git a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt index 5b3bb0992..9cd74b331 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt @@ -8,8 +8,8 @@ import kotlinx.android.parcel.Parcelize @Parcelize @Entity(tableName = "book_groups") data class BookGroup( - @PrimaryKey - var groupId: Int = 0, - var groupName: String, - var order: Int = 0 + @PrimaryKey + val groupId: Int = 0b1, + var groupName: String, + var order: Int = 0 ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 051081e10..2de19d314 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -181,7 +181,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private var isMoved = false override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList) { - with(holder.itemView) { + holder.itemView.apply { tv_group.text = item.groupName tv_edit.onClick { editGroup(item) } tv_del.onClick { viewModel.delGroup(item) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 570704f53..899f64c88 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -42,9 +42,10 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { companion object { const val tag = "groupSelectDialog" - fun show(manager: FragmentManager, requestCode: Int = -1) { + fun show(manager: FragmentManager, groupId: Int, requestCode: Int = -1) { val fragment = GroupSelectDialog().apply { val bundle = Bundle() + bundle.putInt("groupId", groupId) bundle.putInt("requestCode", requestCode) arguments = bundle } @@ -56,6 +57,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var viewModel: GroupViewModel private lateinit var adapter: GroupAdapter private var callBack: CallBack? = null + private var groupId = 0 override fun onStart() { super.onStart() @@ -76,8 +78,9 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) callBack = activity as? CallBack - arguments?.getInt("requestCode")?.let { - requestCode = it + arguments?.let { + groupId = it.getInt("groupId") + requestCode = it.getInt("requestCode", -1) } initData() } @@ -157,13 +160,19 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private var isMoved: Boolean = false override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList) { - with(holder.itemView) { + holder.itemView.apply { cb_group.text = item.groupName - tv_edit.onClick { editGroup(item) } - this.onClick { - callBack?.upGroup(requestCode, item) - dismiss() + cb_group.isChecked = (groupId or item.groupId) > 0 + cb_group.setOnCheckedChangeListener { buttonView, isChecked -> + if (buttonView.isPressed) { + groupId = if (isChecked) { + groupId + item.groupId + } else { + groupId - item.groupId + } + } } + tv_edit.onClick { editGroup(item) } } }