Exclude existing group members from the add members screen

This commit is contained in:
nielsandriesse 2020-08-18 15:40:24 +10:00
parent a73acae952
commit 6e2cbb23cc
4 changed files with 9 additions and 4 deletions

View File

@ -66,7 +66,7 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), LoaderM
// region Updating // region Updating
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> { override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> {
return SelectContactsLoader(this) return SelectContactsLoader(this, setOf())
} }
override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) { override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) {

View File

@ -180,6 +180,7 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
private fun onAddMembersClick() { private fun onAddMembersClick() {
val intent = Intent(this@EditClosedGroupActivity, SelectContactsActivity::class.java) val intent = Intent(this@EditClosedGroupActivity, SelectContactsActivity::class.java)
intent.putExtra(SelectContactsActivity.Companion.usersToExcludeKey, members.toTypedArray())
startActivityForResult(intent, Companion.addUsersRequestCode) startActivityForResult(intent, Companion.addUsersRequestCode)
} }

View File

@ -18,12 +18,14 @@ import org.thoughtcrime.securesms.mms.GlideApp
class SelectContactsActivity : PassphraseRequiredActionBarActivity(), LoaderManager.LoaderCallbacks<List<String>> { class SelectContactsActivity : PassphraseRequiredActionBarActivity(), LoaderManager.LoaderCallbacks<List<String>> {
private var members = listOf<String>() private var members = listOf<String>()
set(value) { field = value; selectContactsAdapter.members = value } set(value) { field = value; selectContactsAdapter.members = value }
private lateinit var usersToExclude: Set<String>
private val selectContactsAdapter by lazy { private val selectContactsAdapter by lazy {
SelectContactsAdapter(this, GlideApp.with(this)) SelectContactsAdapter(this, GlideApp.with(this))
} }
companion object { companion object {
val usersToExcludeKey = "usersToExcludeKey"
val selectedContactsKey = "selectedContactsKey" val selectedContactsKey = "selectedContactsKey"
} }
@ -34,6 +36,8 @@ class SelectContactsActivity : PassphraseRequiredActionBarActivity(), LoaderMana
setContentView(R.layout.activity_select_contacts) setContentView(R.layout.activity_select_contacts)
supportActionBar!!.title = resources.getString(R.string.activity_select_contacts_title) supportActionBar!!.title = resources.getString(R.string.activity_select_contacts_title)
usersToExclude = intent.getStringArrayExtra(Companion.usersToExcludeKey)?.toSet() ?: setOf()
recyclerView.adapter = selectContactsAdapter recyclerView.adapter = selectContactsAdapter
recyclerView.layoutManager = LinearLayoutManager(this) recyclerView.layoutManager = LinearLayoutManager(this)
@ -48,7 +52,7 @@ class SelectContactsActivity : PassphraseRequiredActionBarActivity(), LoaderMana
// region Updating // region Updating
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> { override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> {
return SelectContactsLoader(this) return SelectContactsLoader(this, usersToExclude)
} }
override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) { override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) {

View File

@ -4,12 +4,12 @@ import android.content.Context
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 SelectContactsLoader(context: Context) : AsyncLoader<List<String>>(context) { class SelectContactsLoader(context: Context, val usersToExclude: Set<String>) : AsyncLoader<List<String>>(context) {
override fun loadInBackground(): List<String> { override fun loadInBackground(): List<String> {
val contacts = ContactUtilities.getAllContacts(context) val contacts = ContactUtilities.getAllContacts(context)
return contacts.filter { contact -> return contacts.filter { contact ->
!contact.recipient.isGroupRecipient && !contact.isOurDevice && !contact.isSlave !contact.recipient.isGroupRecipient && !contact.isOurDevice && !contact.isSlave && !usersToExclude.contains(contact.recipient.address.toPhoneString())
}.map { }.map {
it.recipient.address.toPhoneString() it.recipient.address.toPhoneString()
} }