mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Merge pull request #506 from Brice-W/group-creation-ui
Improvement to the Group creation UI
This commit is contained in:
commit
72f9bb8f4b
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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() {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user