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