add a helper function for checking if a contact is private
This commit is contained in:
parent
a8c3dcf23a
commit
12973ac57c
|
@ -91,7 +91,7 @@ class EditContactActivity : ContactActivity() {
|
|||
if (wasActivityInitialized) {
|
||||
menu.findItem(R.id.delete).isVisible = contact?.id != 0
|
||||
menu.findItem(R.id.share).isVisible = contact?.id != 0
|
||||
menu.findItem(R.id.open_with).isVisible = contact?.id != 0 && contact?.source != SMT_PRIVATE
|
||||
menu.findItem(R.id.open_with).isVisible = contact?.id != 0 && contact?.isPrivate() == false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ class InsertOrEditContactActivity : SimpleActivity() {
|
|||
data = getContactPublicUri(contact)
|
||||
action = ADD_NEW_CONTACT_NUMBER
|
||||
putExtra(KEY_PHONE, getPhoneNumberFromIntent(intent))
|
||||
putExtra(IS_PRIVATE, contact.source == SMT_PRIVATE)
|
||||
putExtra(IS_PRIVATE, contact.isPrivate())
|
||||
startActivityForResult(this, START_EDIT_ACTIVITY)
|
||||
}
|
||||
}.apply {
|
||||
|
|
|
@ -17,7 +17,6 @@ import com.simplemobiletools.contacts.pro.extensions.config
|
|||
import com.simplemobiletools.contacts.pro.extensions.getContactPublicUri
|
||||
import com.simplemobiletools.contacts.pro.extensions.getVisibleContactSources
|
||||
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
|
||||
import com.simplemobiletools.contacts.pro.models.Contact
|
||||
import kotlinx.android.synthetic.main.activity_select_contact.*
|
||||
|
||||
|
@ -90,7 +89,7 @@ class SelectContactActivity : SimpleActivity() {
|
|||
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE -> it.phoneNumbers.isNotEmpty()
|
||||
else -> true
|
||||
}
|
||||
it.source != SMT_PRIVATE && hasRequiredValues
|
||||
!it.isPrivate() && hasRequiredValues
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class ViewContactActivity : ContactActivity() {
|
|||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_view_contact, menu)
|
||||
menu.apply {
|
||||
findItem(R.id.open_with).isVisible = contact?.source != SMT_PRIVATE
|
||||
findItem(R.id.open_with).isVisible = contact?.isPrivate() == false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ fun Context.getEmptyContact(): Contact {
|
|||
fun Context.viewContact(contact: Contact) {
|
||||
Intent(applicationContext, ViewContactActivity::class.java).apply {
|
||||
putExtra(CONTACT_ID, contact.id)
|
||||
putExtra(IS_PRIVATE, contact.source == SMT_PRIVATE)
|
||||
putExtra(IS_PRIVATE, contact.isPrivate())
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ fun Context.viewContact(contact: Contact) {
|
|||
fun Context.editContact(contact: Contact) {
|
||||
Intent(applicationContext, EditContactActivity::class.java).apply {
|
||||
putExtra(CONTACT_ID, contact.id)
|
||||
putExtra(IS_PRIVATE, contact.source == SMT_PRIVATE)
|
||||
putExtra(IS_PRIVATE, contact.isPrivate())
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
|
@ -254,8 +254,8 @@ fun Context.getTempFile(): File? {
|
|||
}
|
||||
|
||||
fun Context.addContactsToGroup(contacts: ArrayList<Contact>, groupId: Long) {
|
||||
val publicContacts = contacts.filter { it.source != SMT_PRIVATE }.toMutableList() as ArrayList<Contact>
|
||||
val privateContacts = contacts.filter { it.source == SMT_PRIVATE }.toMutableList() as ArrayList<Contact>
|
||||
val publicContacts = contacts.filter { !it.isPrivate() }.toMutableList() as ArrayList<Contact>
|
||||
val privateContacts = contacts.filter { it.isPrivate() }.toMutableList() as ArrayList<Contact>
|
||||
if (publicContacts.isNotEmpty()) {
|
||||
ContactsHelper(this).addContactsToGroup(publicContacts, groupId)
|
||||
}
|
||||
|
@ -266,8 +266,8 @@ fun Context.addContactsToGroup(contacts: ArrayList<Contact>, groupId: Long) {
|
|||
}
|
||||
|
||||
fun Context.removeContactsFromGroup(contacts: ArrayList<Contact>, groupId: Long) {
|
||||
val publicContacts = contacts.filter { it.source != SMT_PRIVATE }.toMutableList() as ArrayList<Contact>
|
||||
val privateContacts = contacts.filter { it.source == SMT_PRIVATE }.toMutableList() as ArrayList<Contact>
|
||||
val publicContacts = contacts.filter { !it.isPrivate() }.toMutableList() as ArrayList<Contact>
|
||||
val privateContacts = contacts.filter { it.isPrivate() }.toMutableList() as ArrayList<Contact>
|
||||
if (publicContacts.isNotEmpty() && hasContactPermissions()) {
|
||||
ContactsHelper(this).removeContactsFromGroup(publicContacts, groupId)
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ fun Context.removeContactsFromGroup(contacts: ArrayList<Contact>, groupId: Long)
|
|||
}
|
||||
|
||||
fun Context.getContactPublicUri(contact: Contact): Uri {
|
||||
val lookupKey = if (contact.source == SMT_PRIVATE) {
|
||||
val lookupKey = if (contact.isPrivate()) {
|
||||
"local_${contact.id}"
|
||||
} else {
|
||||
ContactsHelper(this).getContactLookupKey(contact.id.toString())
|
||||
|
|
|
@ -910,7 +910,7 @@ class ContactsHelper(val context: Context) {
|
|||
|
||||
fun updateContact(contact: Contact, photoUpdateStatus: Int): Boolean {
|
||||
context.toast(R.string.updating)
|
||||
if (contact.source == SMT_PRIVATE) {
|
||||
if (contact.isPrivate()) {
|
||||
return LocalContactsHelper(context).insertOrUpdateContact(contact)
|
||||
}
|
||||
|
||||
|
@ -1222,7 +1222,7 @@ class ContactsHelper(val context: Context) {
|
|||
}
|
||||
|
||||
fun insertContact(contact: Contact): Boolean {
|
||||
if (contact.source == SMT_PRIVATE) {
|
||||
if (contact.isPrivate()) {
|
||||
return LocalContactsHelper(context).insertOrUpdateContact(contact)
|
||||
}
|
||||
|
||||
|
@ -1477,7 +1477,7 @@ class ContactsHelper(val context: Context) {
|
|||
private fun toggleFavorites(contacts: ArrayList<Contact>, addToFavorites: Boolean) {
|
||||
try {
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
contacts.filter { it.source != SMT_PRIVATE }.map { it.contactId.toString() }.forEach {
|
||||
contacts.filter { !it.isPrivate() }.map { it.contactId.toString() }.forEach {
|
||||
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, it)
|
||||
ContentProviderOperation.newUpdate(uri).apply {
|
||||
withValue(ContactsContract.Contacts.STARRED, if (addToFavorites) 1 else 0)
|
||||
|
@ -1496,13 +1496,13 @@ class ContactsHelper(val context: Context) {
|
|||
}
|
||||
|
||||
private fun toggleLocalFavorites(contacts: ArrayList<Contact>, addToFavorites: Boolean) {
|
||||
val localContacts = contacts.filter { it.source == SMT_PRIVATE }.map { it.id }.toTypedArray()
|
||||
val localContacts = contacts.filter { it.isPrivate() }.map { it.id }.toTypedArray()
|
||||
LocalContactsHelper(context).toggleFavorites(localContacts, addToFavorites)
|
||||
}
|
||||
|
||||
fun deleteContact(contact: Contact) {
|
||||
Thread {
|
||||
if (contact.source == SMT_PRIVATE) {
|
||||
if (contact.isPrivate()) {
|
||||
context.contactsDB.deleteContactId(contact.id)
|
||||
} else {
|
||||
deleteContacts(arrayListOf(contact))
|
||||
|
@ -1511,13 +1511,13 @@ class ContactsHelper(val context: Context) {
|
|||
}
|
||||
|
||||
fun deleteContacts(contacts: ArrayList<Contact>) {
|
||||
val localContacts = contacts.filter { it.source == SMT_PRIVATE }.map { it.id }.toTypedArray()
|
||||
val localContacts = contacts.filter { it.isPrivate() }.map { it.id }.toTypedArray()
|
||||
LocalContactsHelper(context).deleteContactIds(localContacts)
|
||||
|
||||
try {
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
val selection = "${ContactsContract.RawContacts._ID} = ?"
|
||||
contacts.filter { it.source != SMT_PRIVATE }.forEach {
|
||||
contacts.filter { !it.isPrivate() }.forEach {
|
||||
ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).apply {
|
||||
val selectionArgs = arrayOf(it.id.toString())
|
||||
withSelection(selection, selectionArgs)
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
|||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
import com.simplemobiletools.contacts.pro.extensions.normalizeNumber
|
||||
import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
|
||||
|
||||
data class Contact(var id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String, var nickname: String,
|
||||
var photoUri: String, var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var addresses: ArrayList<Address>,
|
||||
|
@ -132,4 +133,6 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun isPrivate() = source == SMT_PRIVATE
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue