mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
User cannot remove himself from the edit closed group activity.
This commit is contained in:
parent
b6b5282a51
commit
e4d2e572ca
@ -51,6 +51,7 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), LoaderM
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
|
||||
btnCreateNewPrivateChat.setOnClickListener { createNewPrivateChat() }
|
||||
|
||||
LoaderManager.getInstance(this).initLoader(0, null, this)
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol
|
||||
import org.thoughtcrime.securesms.mms.GlideApp
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.util.GroupUtil
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.loki.utilities.toHexString
|
||||
import java.io.IOException
|
||||
|
||||
@ -95,7 +96,7 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
||||
// Setup member list loader.
|
||||
LoaderManager.getInstance(this).initLoader(LOADER_ID_MEMBERS, null, object : LoaderManager.LoaderCallbacks<List<String>> {
|
||||
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> {
|
||||
return EditClosedGroupLoader(groupID, this@EditClosedGroupActivity)
|
||||
return EditClosedGroupLoader(this@EditClosedGroupActivity, groupID)
|
||||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) {
|
||||
@ -124,7 +125,11 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
||||
private fun updateMembers(members: Set<String>) {
|
||||
this.members.clear()
|
||||
this.members.addAll(members)
|
||||
this.memberListAdapter.setItems(members)
|
||||
this.memberListAdapter.setMembers(members)
|
||||
|
||||
val localUserPublicKey = TextSecurePreferences.getLocalNumber(this)
|
||||
this.memberListAdapter.setLockedMembers(arrayListOf(localUserPublicKey))
|
||||
|
||||
mainContentContainer.visibility = if (members.isEmpty()) View.GONE else View.VISIBLE
|
||||
emptyStateContainer.visibility = if (members.isEmpty()) View.VISIBLE else View.GONE
|
||||
invalidateOptionsMenu()
|
||||
|
@ -5,7 +5,10 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.loki.utilities.ContactUtilities
|
||||
import org.thoughtcrime.securesms.util.AsyncLoader
|
||||
|
||||
class EditClosedGroupLoader(val groupID: String, context: Context) : AsyncLoader<List<String>>(context) {
|
||||
class EditClosedGroupLoader(
|
||||
context: Context,
|
||||
val groupID: String
|
||||
) : AsyncLoader<List<String>>(context) {
|
||||
|
||||
override fun loadInBackground(): List<String> {
|
||||
val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupID, true)
|
||||
|
@ -14,17 +14,22 @@ class EditClosedGroupMembersAdapter(
|
||||
private val memberClickListener: ((String) -> Unit)? = null
|
||||
) : RecyclerView.Adapter<EditClosedGroupMembersAdapter.ViewHolder>() {
|
||||
|
||||
private val items = ArrayList<String>()
|
||||
private val members = ArrayList<String>()
|
||||
private val lockedMembers = HashSet<String>()
|
||||
|
||||
// private val selectedItems = mutableSetOf<String>()
|
||||
|
||||
fun setItems(items: Collection<String>) {
|
||||
this.items.clear()
|
||||
this.items.addAll(items)
|
||||
fun setMembers(members: Collection<String>) {
|
||||
this.members.clear()
|
||||
this.members.addAll(members)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
fun setLockedMembers(members: Collection<String>) {
|
||||
this.lockedMembers.clear()
|
||||
this.lockedMembers.addAll(members)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = members.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = UserView(context)
|
||||
@ -32,10 +37,19 @@ class EditClosedGroupMembersAdapter(
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||
val item = items[position]
|
||||
// val isSelected = selectedItems.contains(item)
|
||||
viewHolder.view.bind(Recipient.from(context, Address.fromSerialized(item), false), false, glide, true)
|
||||
viewHolder.view.setOnClickListener { this.memberClickListener?.invoke(item) }
|
||||
val member = members[position]
|
||||
|
||||
val lockedMember = lockedMembers.contains(member)
|
||||
|
||||
viewHolder.view.bind(Recipient.from(
|
||||
context,
|
||||
Address.fromSerialized(member), false),
|
||||
glide,
|
||||
(if (lockedMember) UserView.ActionIndicator.NONE else UserView.ActionIndicator.MENU))
|
||||
|
||||
if (!lockedMember) {
|
||||
viewHolder.view.setOnClickListener { this.memberClickListener?.invoke(member) }
|
||||
}
|
||||
}
|
||||
|
||||
class ViewHolder(val view: UserView) : RecyclerView.ViewHolder(view)
|
||||
|
@ -33,7 +33,12 @@ class SelectContactsAdapter(
|
||||
val member = members[position]
|
||||
viewHolder.view.setOnClickListener { onMemberClick(member) }
|
||||
val isSelected = selectedMembers.contains(member)
|
||||
viewHolder.view.bind(Recipient.from(context, Address.fromSerialized(member), false), isSelected, glide, false)
|
||||
viewHolder.view.bind(Recipient.from(
|
||||
context,
|
||||
Address.fromSerialized(member), false),
|
||||
glide,
|
||||
UserView.ActionIndicator.CHECK_BOX,
|
||||
isSelected)
|
||||
}
|
||||
|
||||
private fun onMemberClick(member: String) {
|
||||
|
@ -52,8 +52,11 @@ class ContactSelectionListAdapter(private val context: Context, private val mult
|
||||
item as ContactSelectionListItem.Contact
|
||||
viewHolder.view.setOnClickListener { contactClickListener?.onContactClick(item.recipient) }
|
||||
val isSelected = selectedContacts.contains(item.recipient)
|
||||
viewHolder.view.bind(item.recipient, isSelected, glide, false)
|
||||
viewHolder.view.setCheckBoxVisible(multiSelect)
|
||||
viewHolder.view.bind(
|
||||
item.recipient,
|
||||
glide,
|
||||
if (multiSelect) UserView.ActionIndicator.CHECK_BOX else UserView.ActionIndicator.NONE,
|
||||
isSelected)
|
||||
} else if (viewHolder is DividerViewHolder) {
|
||||
item as ContactSelectionListItem.Header
|
||||
viewHolder.view.label.text = item.name
|
||||
|
@ -40,11 +40,13 @@ class UserView : LinearLayout {
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
fun setCheckBoxVisible(visible: Boolean) {
|
||||
tickImageView.visibility = if (visible) View.VISIBLE else View.GONE
|
||||
enum class ActionIndicator {
|
||||
NONE,
|
||||
MENU,
|
||||
CHECK_BOX,
|
||||
}
|
||||
|
||||
fun bind(user: Recipient, isSelected: Boolean, glide: GlideRequests, isEditingGroup: Boolean) {
|
||||
fun bind(user: Recipient, glide: GlideRequests, actionIndicator: ActionIndicator, isSelected: Boolean = false) {
|
||||
val address = user.address.serialize()
|
||||
if (user.isGroupRecipient) {
|
||||
if ("Session Public Chat" == user.name || user.address.isRSSFeed) {
|
||||
@ -70,10 +72,19 @@ class UserView : LinearLayout {
|
||||
profilePictureView.glide = glide
|
||||
profilePictureView.update()
|
||||
nameTextView.text = user.name ?: "Unknown Contact"
|
||||
if (isEditingGroup) {
|
||||
tickImageView.setImageResource(R.drawable.ic_more_horiz_white)
|
||||
} else {
|
||||
tickImageView.setImageResource(if (isSelected) R.drawable.ic_circle_check else R.drawable.ic_circle)
|
||||
|
||||
when (actionIndicator) {
|
||||
ActionIndicator.NONE -> {
|
||||
tickImageView.visibility = View.GONE
|
||||
}
|
||||
ActionIndicator.MENU -> {
|
||||
tickImageView.visibility = View.VISIBLE
|
||||
tickImageView.setImageResource(R.drawable.ic_more_horiz_white)
|
||||
}
|
||||
ActionIndicator.CHECK_BOX -> {
|
||||
tickImageView.visibility = View.VISIBLE
|
||||
tickImageView.setImageResource(if (isSelected) R.drawable.ic_circle_check else R.drawable.ic_circle)
|
||||
}
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
|
Loading…
Reference in New Issue
Block a user