diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/GroupContactsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/GroupContactsActivity.kt index a3295dc4..56ae0909 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/GroupContactsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/GroupContactsActivity.kt @@ -5,10 +5,7 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.adapters.ContactsAdapter import com.simplemobiletools.contacts.dialogs.SelectContactsDialog -import com.simplemobiletools.contacts.extensions.config -import com.simplemobiletools.contacts.extensions.editContact -import com.simplemobiletools.contacts.extensions.tryStartCall -import com.simplemobiletools.contacts.extensions.viewContact +import com.simplemobiletools.contacts.extensions.* import com.simplemobiletools.contacts.helpers.* import com.simplemobiletools.contacts.interfaces.RefreshContactsListener import com.simplemobiletools.contacts.interfaces.RemoveFromGroupListener @@ -48,11 +45,11 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh private fun fabClicked() { SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts -> - ContactsHelper(this).apply { + Thread { addContactsToGroup(addedContacts, group.id) removeContactsFromGroup(removedContacts, group.id) - } - refreshContacts() + refreshContacts() + }.start() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt index aa551595..7cc74c73 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt @@ -21,6 +21,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.activities.SimpleActivity import com.simplemobiletools.contacts.dialogs.CreateNewGroupDialog +import com.simplemobiletools.contacts.extensions.addContactsToGroup import com.simplemobiletools.contacts.extensions.config import com.simplemobiletools.contacts.extensions.editContact import com.simplemobiletools.contacts.extensions.shareContacts @@ -197,13 +198,17 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList, groupId: Long) { + val publicContacts = contacts.filter { it.source != SMT_PRIVATE } + val privateContacts = contacts.filter { it.source == SMT_PRIVATE } + if (publicContacts.isNotEmpty()) { + ContactsHelper(this).addContactsToGroup(contacts, groupId) + } + + if (privateContacts.isNotEmpty()) { + dbHelper.addContactsToGroup(contacts, groupId) + } +} + +fun BaseSimpleActivity.removeContactsFromGroup(contacts: ArrayList, groupId: Long) { + val publicContacts = contacts.filter { it.source != SMT_PRIVATE } + val privateContacts = contacts.filter { it.source == SMT_PRIVATE } + if (publicContacts.isNotEmpty()) { + ContactsHelper(this).removeContactsFromGroup(contacts, groupId) + } + + if (privateContacts.isNotEmpty()) { + dbHelper.removeContactsFromGroup(contacts, groupId) + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt index 78760c3d..b2cddb09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt @@ -193,6 +193,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } } + fun addContactsToGroup(contacts: ArrayList, groupId: Long) { + + } + + fun removeContactsFromGroup(contacts: ArrayList, groupId: Long) { + + } + fun getContacts(activity: BaseSimpleActivity, selection: String? = null, selectionArgs: Array? = null): ArrayList { val storedGroups = ContactsHelper(activity).getStoredGroups() val contacts = ArrayList()