mirror of
				https://github.com/SimpleMobileTools/Simple-Contacts.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	use raw contact id everywhere
This commit is contained in:
		| @@ -119,12 +119,12 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | |||||||
|         val emails = SparseArray<ArrayList<Email>>() |         val emails = SparseArray<ArrayList<Email>>() | ||||||
|         val uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI |         val uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI | ||||||
|         val projection = arrayOf( |         val projection = arrayOf( | ||||||
|                 ContactsContract.CommonDataKinds.Email.CONTACT_ID, |                 ContactsContract.Data.RAW_CONTACT_ID, | ||||||
|                 ContactsContract.CommonDataKinds.Email.DATA, |                 ContactsContract.CommonDataKinds.Email.DATA, | ||||||
|                 ContactsContract.CommonDataKinds.Email.TYPE |                 ContactsContract.CommonDataKinds.Email.TYPE | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         val selection = if (contactId == null) null else "${ContactsContract.CommonDataKinds.Email.CONTACT_ID} = ?" |         val selection = if (contactId == null) null else "${ContactsContract.Data.RAW_CONTACT_ID} = ?" | ||||||
|         val selectionArgs = if (contactId == null) null else arrayOf(contactId.toString()) |         val selectionArgs = if (contactId == null) null else arrayOf(contactId.toString()) | ||||||
|  |  | ||||||
|         var cursor: Cursor? = null |         var cursor: Cursor? = null | ||||||
| @@ -132,7 +132,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | |||||||
|             cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) |             cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) | ||||||
|             if (cursor?.moveToFirst() == true) { |             if (cursor?.moveToFirst() == true) { | ||||||
|                 do { |                 do { | ||||||
|                     val id = cursor.getIntValue(ContactsContract.CommonDataKinds.Email.CONTACT_ID) |                     val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) | ||||||
|                     val email = cursor.getStringValue(ContactsContract.CommonDataKinds.Email.DATA) |                     val email = cursor.getStringValue(ContactsContract.CommonDataKinds.Email.DATA) | ||||||
|                     val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Email.TYPE) |                     val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Email.TYPE) | ||||||
|  |  | ||||||
| @@ -154,12 +154,12 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | |||||||
|         val phoneNumbers = SparseArray<ArrayList<PhoneNumber>>() |         val phoneNumbers = SparseArray<ArrayList<PhoneNumber>>() | ||||||
|         val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI |         val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI | ||||||
|         val projection = arrayOf( |         val projection = arrayOf( | ||||||
|                 ContactsContract.CommonDataKinds.Phone.CONTACT_ID, |                 ContactsContract.Data.RAW_CONTACT_ID, | ||||||
|                 ContactsContract.CommonDataKinds.Phone.NUMBER, |                 ContactsContract.CommonDataKinds.Phone.NUMBER, | ||||||
|                 ContactsContract.CommonDataKinds.Phone.TYPE |                 ContactsContract.CommonDataKinds.Phone.TYPE | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         val selection = if (contactId == null) null else "${ContactsContract.CommonDataKinds.Phone.CONTACT_ID} = ?" |         val selection = if (contactId == null) null else "${ContactsContract.Data.RAW_CONTACT_ID} = ?" | ||||||
|         val selectionArgs = if (contactId == null) null else arrayOf(contactId.toString()) |         val selectionArgs = if (contactId == null) null else arrayOf(contactId.toString()) | ||||||
|  |  | ||||||
|         var cursor: Cursor? = null |         var cursor: Cursor? = null | ||||||
| @@ -167,7 +167,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | |||||||
|             cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) |             cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) | ||||||
|             if (cursor?.moveToFirst() == true) { |             if (cursor?.moveToFirst() == true) { | ||||||
|                 do { |                 do { | ||||||
|                     val id = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.CONTACT_ID) |                     val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) | ||||||
|                     val number = cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.NUMBER) |                     val number = cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.NUMBER) | ||||||
|                     val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.TYPE) |                     val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.TYPE) | ||||||
|  |  | ||||||
| @@ -234,6 +234,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | |||||||
|         if (sorting and SORT_DESCENDING != 0) { |         if (sorting and SORT_DESCENDING != 0) { | ||||||
|             sort += " DESC" |             sort += " DESC" | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return sort |         return sort | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -450,7 +451,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | |||||||
|     fun deleteContacts(contacts: ArrayList<Contact>) { |     fun deleteContacts(contacts: ArrayList<Contact>) { | ||||||
|         try { |         try { | ||||||
|             val operations = ArrayList<ContentProviderOperation>() |             val operations = ArrayList<ContentProviderOperation>() | ||||||
|             val selection = "${ContactsContract.CommonDataKinds.Phone.CONTACT_ID} = ?" |             val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ?" | ||||||
|             contacts.forEach { |             contacts.forEach { | ||||||
|                 val selectionArgs = arrayOf(it.id.toString()) |                 val selectionArgs = arrayOf(it.id.toString()) | ||||||
|                 operations.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(selection, selectionArgs).build()) |                 operations.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(selection, selectionArgs).build()) | ||||||
| @@ -461,20 +462,6 @@ class ContactsHelper(val activity: BaseSimpleActivity) { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun doesSourceContainContacts(source: String): Boolean { |  | ||||||
|         val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI |  | ||||||
|         val projection = arrayOf(ContactsContract.CommonDataKinds.Email.CONTACT_ID) |  | ||||||
|         val selection = "${ContactsContract.RawContacts.ACCOUNT_NAME} = ?" |  | ||||||
|         val selectionArgs = arrayOf(source) |  | ||||||
|         var cursor: Cursor? = null |  | ||||||
|         try { |  | ||||||
|             cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) |  | ||||||
|             return (cursor?.moveToFirst() == true) |  | ||||||
|         } finally { |  | ||||||
|             cursor?.close() |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun getThumbnailSize(): Int { |     private fun getThumbnailSize(): Int { | ||||||
|         val uri = ContactsContract.DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI |         val uri = ContactsContract.DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI | ||||||
|         val projection = arrayOf(ContactsContract.DisplayPhoto.THUMBNAIL_MAX_DIM) |         val projection = arrayOf(ContactsContract.DisplayPhoto.THUMBNAIL_MAX_DIM) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user