diff --git a/src/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt index f4efe23150..2282860b69 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt @@ -51,6 +51,7 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), LoaderM recyclerView.layoutManager = LinearLayoutManager(this) btnCreateNewPrivateChat.setOnClickListener { createNewPrivateChat() } + LoaderManager.getInstance(this).initLoader(0, null, this) } diff --git a/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt index 4a35a912b2..cb6e80f5ea 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupActivity.kt @@ -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> { override fun onCreateLoader(id: Int, bundle: Bundle?): Loader> { - return EditClosedGroupLoader(groupID, this@EditClosedGroupActivity) + return EditClosedGroupLoader(this@EditClosedGroupActivity, groupID) } override fun onLoadFinished(loader: Loader>, members: List) { @@ -124,7 +125,11 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() { private fun updateMembers(members: Set) { 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() diff --git a/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupLoader.kt b/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupLoader.kt index 467423ac90..32a7d32e44 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupLoader.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupLoader.kt @@ -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>(context) { +class EditClosedGroupLoader( + context: Context, + val groupID: String +) : AsyncLoader>(context) { override fun loadInBackground(): List { val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupID, true) diff --git a/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupMembersAdapter.kt b/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupMembersAdapter.kt index 965018f51a..f394a7aa3a 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupMembersAdapter.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/EditClosedGroupMembersAdapter.kt @@ -14,17 +14,22 @@ class EditClosedGroupMembersAdapter( private val memberClickListener: ((String) -> Unit)? = null ) : RecyclerView.Adapter() { - private val items = ArrayList() + private val members = ArrayList() + private val lockedMembers = HashSet() -// private val selectedItems = mutableSetOf() - - fun setItems(items: Collection) { - this.items.clear() - this.items.addAll(items) + fun setMembers(members: Collection) { + this.members.clear() + this.members.addAll(members) notifyDataSetChanged() } - override fun getItemCount(): Int = items.size + fun setLockedMembers(members: Collection) { + 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) diff --git a/src/org/thoughtcrime/securesms/loki/activities/SelectContactsAdapter.kt b/src/org/thoughtcrime/securesms/loki/activities/SelectContactsAdapter.kt index 01278737e4..aa908154ac 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/SelectContactsAdapter.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/SelectContactsAdapter.kt @@ -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) { diff --git a/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListAdapter.kt b/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListAdapter.kt index 5c7b85fa25..fb1e5c54d3 100644 --- a/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListAdapter.kt +++ b/src/org/thoughtcrime/securesms/loki/fragments/ContactSelectionListAdapter.kt @@ -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 diff --git a/src/org/thoughtcrime/securesms/loki/views/UserView.kt b/src/org/thoughtcrime/securesms/loki/views/UserView.kt index 98e4a77955..da549f654b 100644 --- a/src/org/thoughtcrime/securesms/loki/views/UserView.kt +++ b/src/org/thoughtcrime/securesms/loki/views/UserView.kt @@ -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