feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 24ce7364d0
commit 55a43999c0
  1. 8
      app/src/main/java/io/legado/app/data/entities/BookGroup.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  3. 25
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt

@ -8,8 +8,8 @@ import kotlinx.android.parcel.Parcelize
@Parcelize @Parcelize
@Entity(tableName = "book_groups") @Entity(tableName = "book_groups")
data class BookGroup( data class BookGroup(
@PrimaryKey @PrimaryKey
var groupId: Int = 0, val groupId: Int = 0b1,
var groupName: String, var groupName: String,
var order: Int = 0 var order: Int = 0
) : Parcelable ) : Parcelable

@ -181,7 +181,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private var isMoved = false private var isMoved = false
override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList<Any>) {
with(holder.itemView) { holder.itemView.apply {
tv_group.text = item.groupName tv_group.text = item.groupName
tv_edit.onClick { editGroup(item) } tv_edit.onClick { editGroup(item) }
tv_del.onClick { viewModel.delGroup(item) } tv_del.onClick { viewModel.delGroup(item) }

@ -42,9 +42,10 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
companion object { companion object {
const val tag = "groupSelectDialog" 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 fragment = GroupSelectDialog().apply {
val bundle = Bundle() val bundle = Bundle()
bundle.putInt("groupId", groupId)
bundle.putInt("requestCode", requestCode) bundle.putInt("requestCode", requestCode)
arguments = bundle arguments = bundle
} }
@ -56,6 +57,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: GroupViewModel private lateinit var viewModel: GroupViewModel
private lateinit var adapter: GroupAdapter private lateinit var adapter: GroupAdapter
private var callBack: CallBack? = null private var callBack: CallBack? = null
private var groupId = 0
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
@ -76,8 +78,9 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
callBack = activity as? CallBack callBack = activity as? CallBack
arguments?.getInt("requestCode")?.let { arguments?.let {
requestCode = it groupId = it.getInt("groupId")
requestCode = it.getInt("requestCode", -1)
} }
initData() initData()
} }
@ -157,13 +160,19 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private var isMoved: Boolean = false private var isMoved: Boolean = false
override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList<Any>) {
with(holder.itemView) { holder.itemView.apply {
cb_group.text = item.groupName cb_group.text = item.groupName
tv_edit.onClick { editGroup(item) } cb_group.isChecked = (groupId or item.groupId) > 0
this.onClick { cb_group.setOnCheckedChangeListener { buttonView, isChecked ->
callBack?.upGroup(requestCode, item) if (buttonView.isPressed) {
dismiss() groupId = if (isChecked) {
groupId + item.groupId
} else {
groupId - item.groupId
}
}
} }
tv_edit.onClick { editGroup(item) }
} }
} }

Loading…
Cancel
Save