optimization on contacts selection

This commit is contained in:
Brice-W 2021-04-19 10:46:19 +10:00
parent 9ccd72bf33
commit 3c210ca437
2 changed files with 9 additions and 4 deletions

View File

@ -26,7 +26,7 @@ class SelectContactsAdapter(private val context: Context, private val glide: Gli
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val member = members[position]
viewHolder.view.setOnClickListener { onMemberClick(member) }
viewHolder.view.setOnClickListener { onMemberClick(viewHolder, member) }
val isSelected = selectedMembers.contains(member)
viewHolder.view.bind(Recipient.from(
context,
@ -36,13 +36,13 @@ class SelectContactsAdapter(private val context: Context, private val glide: Gli
isSelected)
}
private fun onMemberClick(member: String) {
private fun onMemberClick(viewHolder: ViewHolder, member: String) {
if (selectedMembers.contains(member)) {
selectedMembers.remove(member)
viewHolder.view.toggleCheckbox()
} else {
selectedMembers.add(member)
viewHolder.view.toggleCheckbox(true)
}
val index = members.indexOf(member)
notifyItemChanged(index)
}
}

View File

@ -82,6 +82,11 @@ class UserView : LinearLayout {
}
}
fun toggleCheckbox(isSelected: Boolean = false) {
actionIndicatorImageView.visibility = View.VISIBLE
actionIndicatorImageView.setImageResource(if (isSelected) R.drawable.ic_circle_check else R.drawable.ic_circle)
}
fun unbind() {
}