diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ContactActivity.kt index f6ec49a5..1c955ce7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ContactActivity.kt @@ -23,8 +23,6 @@ import com.simplemobiletools.contacts.extensions.config import com.simplemobiletools.contacts.helpers.CONTACT_ID import com.simplemobiletools.contacts.helpers.ContactsHelper import com.simplemobiletools.contacts.models.Contact -import com.simplemobiletools.contacts.models.Emails -import com.simplemobiletools.contacts.models.PhoneNumbers import kotlinx.android.synthetic.main.activity_contact.* class ContactActivity : SimpleActivity() { @@ -150,7 +148,7 @@ class ContactActivity : SimpleActivity() { private fun setupNewContact() { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) supportActionBar?.title = resources.getString(R.string.new_contact) - contact = Contact(0, "", "", "", "", PhoneNumbers(), Emails(), "") + contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), "") } private fun applyPhotoPlaceholder() { 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 4b3ad346..84917ba0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt @@ -113,7 +113,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList() // proper value is obtained below + val emails = ArrayList() // proper value is obtained below val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, accountName) contacts.put(id, contact) @@ -115,8 +117,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) { } } - private fun getEmails(contactId: Int? = null): SparseArray { - val emails = SparseArray() + private fun getEmails(contactId: Int? = null): SparseArray> { + val emails = SparseArray>() val uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI val projection = arrayOf( ContactsContract.CommonDataKinds.Email.CONTACT_ID, @@ -137,10 +139,10 @@ class ContactsHelper(val activity: BaseSimpleActivity) { val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Email.TYPE) if (emails[id] == null) { - emails.put(id, Emails()) + emails.put(id, ArrayList()) } - emails[id]!!.emails.add(Email(email, type)) + emails[id]!!.add(Email(email, type)) } while (cursor.moveToNext()) } } finally { @@ -150,8 +152,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) { return emails } - private fun getPhoneNumbers(contactId: Int? = null): SparseArray { - val phoneNumbers = SparseArray() + private fun getPhoneNumbers(contactId: Int? = null): SparseArray> { + val phoneNumbers = SparseArray>() val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI val projection = arrayOf( ContactsContract.CommonDataKinds.Phone.CONTACT_ID, @@ -172,10 +174,10 @@ class ContactsHelper(val activity: BaseSimpleActivity) { val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.TYPE) if (phoneNumbers[id] == null) { - phoneNumbers.put(id, PhoneNumbers()) + phoneNumbers.put(id, ArrayList()) } - phoneNumbers[id].phoneNumbers.add(PhoneNumber(number, type)) + phoneNumbers[id].add(PhoneNumber(number, type)) } while (cursor.moveToNext()) } } finally { @@ -184,24 +186,6 @@ class ContactsHelper(val activity: BaseSimpleActivity) { return phoneNumbers } - fun getContactNumber(id: Int): String { - val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI - val projection = arrayOf(ContactsContract.CommonDataKinds.Phone.NUMBER) - val selection = "${ContactsContract.CommonDataKinds.Phone.CONTACT_ID} = ?" - val selectionArgs = arrayOf(id.toString()) - var cursor: Cursor? = null - try { - cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) - if (cursor?.moveToFirst() == true) { - return cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.NUMBER) - } - } finally { - cursor?.close() - } - - return "" - } - fun getContactWithId(id: Int): Contact? { if (id == 0) { return null @@ -219,8 +203,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) { val middleName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME) ?: "" val surname = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: "" val photoUri = cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.PHOTO_URI) ?: "" - val number = getPhoneNumbers(id)[id] ?: PhoneNumbers() - val emails = getEmails(id)[id] ?: Emails() + val number = getPhoneNumbers(id)[id] ?: ArrayList() + val emails = getEmails(id)[id] ?: ArrayList() val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) return Contact(id, firstName, middleName, surname, photoUri, number, emails, accountName) } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt index a6c82b78..49b4c549 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt @@ -4,8 +4,8 @@ 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 -data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String, var phoneNumbers: PhoneNumbers, - var emails: Emails, var source: String) : Comparable { +data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String, + var phoneNumbers: ArrayList, var emails: ArrayList, var source: String) : Comparable { companion object { var sorting: Int = 0 } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Emails.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Emails.kt deleted file mode 100644 index 7089a81c..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Emails.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.simplemobiletools.contacts.models - -data class Emails(var emails: ArrayList = ArrayList()) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumbers.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumbers.kt deleted file mode 100644 index a2ea4e30..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumbers.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.simplemobiletools.contacts.models - -data class PhoneNumbers(var phoneNumbers: ArrayList = ArrayList())