mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
add helper functions to handle contact adding and removing from groups
This commit is contained in:
@ -5,10 +5,7 @@ import com.simplemobiletools.commons.extensions.*
|
|||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
||||||
import com.simplemobiletools.contacts.dialogs.SelectContactsDialog
|
import com.simplemobiletools.contacts.dialogs.SelectContactsDialog
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.*
|
||||||
import com.simplemobiletools.contacts.extensions.editContact
|
|
||||||
import com.simplemobiletools.contacts.extensions.tryStartCall
|
|
||||||
import com.simplemobiletools.contacts.extensions.viewContact
|
|
||||||
import com.simplemobiletools.contacts.helpers.*
|
import com.simplemobiletools.contacts.helpers.*
|
||||||
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
||||||
import com.simplemobiletools.contacts.interfaces.RemoveFromGroupListener
|
import com.simplemobiletools.contacts.interfaces.RemoveFromGroupListener
|
||||||
@ -48,11 +45,11 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
|
|||||||
|
|
||||||
private fun fabClicked() {
|
private fun fabClicked() {
|
||||||
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
|
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
|
||||||
ContactsHelper(this).apply {
|
Thread {
|
||||||
addContactsToGroup(addedContacts, group.id)
|
addContactsToGroup(addedContacts, group.id)
|
||||||
removeContactsFromGroup(removedContacts, group.id)
|
removeContactsFromGroup(removedContacts, group.id)
|
||||||
}
|
refreshContacts()
|
||||||
refreshContacts()
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import com.simplemobiletools.commons.views.MyRecyclerView
|
|||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||||
import com.simplemobiletools.contacts.dialogs.CreateNewGroupDialog
|
import com.simplemobiletools.contacts.dialogs.CreateNewGroupDialog
|
||||||
|
import com.simplemobiletools.contacts.extensions.addContactsToGroup
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.extensions.editContact
|
import com.simplemobiletools.contacts.extensions.editContact
|
||||||
import com.simplemobiletools.contacts.extensions.shareContacts
|
import com.simplemobiletools.contacts.extensions.shareContacts
|
||||||
@ -197,13 +198,17 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||||||
RadioGroupDialog(activity, items, 0) {
|
RadioGroupDialog(activity, items, 0) {
|
||||||
if (it as Int == NEW_GROUP_ID) {
|
if (it as Int == NEW_GROUP_ID) {
|
||||||
CreateNewGroupDialog(activity) {
|
CreateNewGroupDialog(activity) {
|
||||||
ContactsHelper(activity).addContactsToGroup(selectedContacts, it.id)
|
Thread {
|
||||||
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
|
activity.addContactsToGroup(selectedContacts, it.id)
|
||||||
|
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
|
||||||
|
}.start()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ContactsHelper(activity).addContactsToGroup(selectedContacts, it.toLong())
|
Thread {
|
||||||
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
|
activity.addContactsToGroup(selectedContacts, it.toLong())
|
||||||
|
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
|
||||||
|
}.start()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,3 +108,27 @@ fun BaseSimpleActivity.getTempFile(): File? {
|
|||||||
|
|
||||||
return File(folder, "contacts.vcf")
|
return File(folder, "contacts.vcf")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun BaseSimpleActivity.addContactsToGroup(contacts: ArrayList<Contact>, 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<Contact>, 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -193,6 +193,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addContactsToGroup(contacts: ArrayList<Contact>, groupId: Long) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeContactsFromGroup(contacts: ArrayList<Contact>, groupId: Long) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fun getContacts(activity: BaseSimpleActivity, selection: String? = null, selectionArgs: Array<String>? = null): ArrayList<Contact> {
|
fun getContacts(activity: BaseSimpleActivity, selection: String? = null, selectionArgs: Array<String>? = null): ArrayList<Contact> {
|
||||||
val storedGroups = ContactsHelper(activity).getStoredGroups()
|
val storedGroups = ContactsHelper(activity).getStoredGroups()
|
||||||
val contacts = ArrayList<Contact>()
|
val contacts = ArrayList<Contact>()
|
||||||
|
Reference in New Issue
Block a user