Merge pull request #506 from Brice-W/group-creation-ui

Improvement to the Group creation UI
This commit is contained in:
Niels Andriesse 2021-04-21 12:47:58 +10:00 committed by GitHub
commit 72f9bb8f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 4 deletions

View File

@ -32,6 +32,10 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), LoaderM
set(newValue) { field = newValue; invalidateOptionsMenu() }
private var members = listOf<String>()
set(value) { field = value; selectContactsAdapter.members = value }
private val publicKey: String
get() {
return TextSecurePreferences.getLocalNumber(this)!!
}
private val selectContactsAdapter by lazy {
SelectContactsAdapter(this, GlideApp.with(this))
@ -72,7 +76,8 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), LoaderM
}
private fun update(members: List<String>) {
this.members = members
//if there is a Note to self conversation, it loads self in the list, so we need to remove it here
this.members = members.minus(publicKey)
mainContentContainer.visibility = if (members.isEmpty()) View.GONE else View.VISIBLE
emptyStateContainer.visibility = if (members.isEmpty()) View.VISIBLE else View.GONE
invalidateOptionsMenu()

View File

@ -36,6 +36,27 @@ class SelectContactsAdapter(private val context: Context, private val glide: Gli
isSelected)
}
override fun onBindViewHolder(viewHolder: ViewHolder,
position: Int,
payloads: MutableList<Any>) {
if (payloads.isNotEmpty()) {
// Because these updates can be batched,
// there can be multiple payloads for a single bind
when (payloads[0]) {
Payload.MEMBER_CLICKED -> {
val member = members[position]
val isSelected = selectedMembers.contains(member)
viewHolder.view.toggleCheckbox(isSelected)
}
}
} else {
// When payload list is empty,
// or we don't have logic to handle a given type,
// default to full bind:
this.onBindViewHolder(viewHolder, position)
}
}
private fun onMemberClick(member: String) {
if (selectedMembers.contains(member)) {
selectedMembers.remove(member)
@ -43,6 +64,11 @@ class SelectContactsAdapter(private val context: Context, private val glide: Gli
selectedMembers.add(member)
}
val index = members.indexOf(member)
notifyItemChanged(index)
notifyItemChanged(index, Payload.MEMBER_CLICKED)
}
}
// define below the different events used to notify the adapter
enum class Payload {
MEMBER_CLICKED
}
}

View File

@ -82,8 +82,13 @@ 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() {
}
// endregion
}
}