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 b2f63fe9..f6ec49a5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ContactActivity.kt @@ -19,15 +19,12 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS import com.simplemobiletools.contacts.R -import com.simplemobiletools.contacts.R.string.email import com.simplemobiletools.contacts.extensions.config -import com.simplemobiletools.contacts.extensions.sendEmailIntent -import com.simplemobiletools.contacts.extensions.sendSMSIntent -import com.simplemobiletools.contacts.extensions.startCallIntent 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() { @@ -73,8 +70,8 @@ class ContactActivity : SimpleActivity() { setupEditContact() } - contact_send_sms.beVisibleIf(contact!!.number.isNotEmpty()) - contact_start_call.beVisibleIf(contact!!.number.isNotEmpty()) + //contact_send_sms.beVisibleIf(contact!!.number.isNotEmpty()) + //contact_start_call.beVisibleIf(contact!!.number.isNotEmpty()) //contact_send_email.beVisibleIf(contact!!.email.isNotEmpty()) contact_photo.background = ColorDrawable(config.primaryColor) @@ -110,8 +107,8 @@ class ContactActivity : SimpleActivity() { contact_source_image.applyColorFilter(textColor) contact_photo.setOnClickListener { } - contact_send_sms.setOnClickListener { sendSMSIntent(contact!!.number) } - contact_start_call.setOnClickListener { startCallIntent(contact!!.number) } + //contact_send_sms.setOnClickListener { sendSMSIntent(contact!!.number) } + //contact_start_call.setOnClickListener { startCallIntent(contact!!.number) } //contact_send_email.setOnClickListener { sendEmailIntent(contact!!.email) } contact_source.setOnClickListener { showAccountSourcePicker() } contact_number_type.setOnClickListener { } @@ -145,7 +142,7 @@ class ContactActivity : SimpleActivity() { contact_first_name.setText(contact!!.firstName) contact_middle_name.setText(contact!!.middleName) contact_surname.setText(contact!!.surname) - contact_number.setText(contact!!.number) + //contact_number.setText(contact!!.number) //contact_email.setText(contact!!.email) contact_source.text = contact!!.source } @@ -153,7 +150,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, "", "", "", "", "", Emails(), "") + contact = Contact(0, "", "", "", "", PhoneNumbers(), Emails(), "") } private fun applyPhotoPlaceholder() { @@ -168,7 +165,7 @@ class ContactActivity : SimpleActivity() { firstName = contact_first_name.value middleName = contact_middle_name.value surname = contact_surname.value - number = contact_number.value + //number = contact_number.value //email = contact_email.value if (ContactsHelper(this@ContactActivity).updateContact(this)) { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt index bc4691be..177e5386 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt @@ -164,7 +164,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { if (currAdapter == null) { ContactsAdapter(this, contacts, this, contacts_list) { if (config.callContact) { - startCallIntent((it as Contact).number) + //startCallIntent((it as Contact).number) } else { openContact(it as Contact) } 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 aac1ecd5..4b3ad346 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> { - val pairs = ArrayList>() + 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, - ContactsContract.CommonDataKinds.Phone.NUMBER + ContactsContract.CommonDataKinds.Phone.NUMBER, + ContactsContract.CommonDataKinds.Phone.TYPE ) + + val selection = if (contactId == null) null else "${ContactsContract.CommonDataKinds.Phone.CONTACT_ID} = ?" + val selectionArgs = if (contactId == null) null else arrayOf(contactId.toString()) + var cursor: Cursor? = null try { - cursor = activity.contentResolver.query(uri, projection, null, null, null) + cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) if (cursor?.moveToFirst() == true) { do { val id = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.CONTACT_ID) val number = cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.NUMBER) - pairs.add(Pair(id, number)) + val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.TYPE) + + if (phoneNumbers[id] == null) { + phoneNumbers.put(id, PhoneNumbers()) + } + + phoneNumbers[id].phoneNumbers.add(PhoneNumber(number, type)) } while (cursor.moveToNext()) } } finally { cursor?.close() } - return pairs + return phoneNumbers } fun getContactNumber(id: Int): String { @@ -207,7 +219,7 @@ 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 = getContactNumber(id) + val number = getPhoneNumbers(id)[id] ?: PhoneNumbers() val emails = getEmails(id)[id] ?: Emails() 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 b0a081d5..a6c82b78 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt @@ -4,7 +4,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 -data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String, var number: String, +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 { companion object { var sorting: Int = 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumber.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumber.kt new file mode 100644 index 00000000..e1eee4cf --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumber.kt @@ -0,0 +1,3 @@ +package com.simplemobiletools.contacts.models + +data class PhoneNumber(var value: String, var type: Int) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumbers.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumbers.kt index 6c640337..a2ea4e30 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumbers.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/models/PhoneNumbers.kt @@ -1,4 +1,3 @@ package com.simplemobiletools.contacts.models -data class PhoneNumbers(var home: String, var work: String, var mobile: String, var main: String, var work_fax: String, var home_fax: String, - var pager: String, var other: String) +data class PhoneNumbers(var phoneNumbers: ArrayList = ArrayList()) diff --git a/app/src/main/res/layout/dialog_change_sorting.xml b/app/src/main/res/layout/dialog_change_sorting.xml index e31b07b3..cbc6504b 100644 --- a/app/src/main/res/layout/dialog_change_sorting.xml +++ b/app/src/main/res/layout/dialog_change_sorting.xml @@ -44,14 +44,6 @@ android:paddingTop="@dimen/medium_margin" android:text="@string/surname"/> - -