feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 77adb5702c
commit eac9a7e561
  1. 41
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt

@ -49,29 +49,40 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
} }
tv_author.text = getGroupName(item.group) tv_author.text = getGroupName(item.group)
checkbox.isChecked = selectedBooks.contains(item) checkbox.isChecked = selectedBooks.contains(item)
checkbox.onClick { checkbox.setOnCheckedChangeListener { buttonView, isChecked ->
if (checkbox.isChecked) { getItem(holder.layoutPosition)?.let {
selectedBooks.add(item) if (buttonView.isPressed) {
} else { if (isChecked) {
selectedBooks.remove(item) selectedBooks.add(it)
} else {
selectedBooks.remove(it)
}
callBack.upSelectCount()
}
} }
callBack.upSelectCount()
} }
onClick { onClick {
checkbox.isChecked = !checkbox.isChecked getItem(holder.layoutPosition)?.let {
if (checkbox.isChecked) { checkbox.isChecked = !checkbox.isChecked
selectedBooks.add(item) if (checkbox.isChecked) {
} else { selectedBooks.add(it)
selectedBooks.remove(item) } else {
selectedBooks.remove(it)
}
callBack.upSelectCount()
} }
callBack.upSelectCount()
} }
tv_delete.onClick { tv_delete.onClick {
callBack.deleteBook(item) getItem(holder.layoutPosition)?.let {
callBack.deleteBook(it)
}
} }
tv_group.onClick { tv_group.onClick {
actionItem = item getItem(holder.layoutPosition)?.let {
callBack.selectGroup(item.group, groupRequestCode) actionItem = it
callBack.selectGroup(it.group, groupRequestCode)
}
} }
} }
} }

Loading…
Cancel
Save