retrieve Custom type labels at phone number, email, address

This commit is contained in:
tibbi 2018-09-02 12:39:07 +02:00
parent 5a0ebde4d3
commit f74cc8cd31
8 changed files with 26 additions and 21 deletions

View File

@ -150,7 +150,7 @@ class EditContactActivity : ContactActivity() {
if (contact!!.id == 0 && intent.extras?.containsKey(KEY_PHONE) == true && (action == Intent.ACTION_INSERT_OR_EDIT || action == Intent.ACTION_INSERT)) { if (contact!!.id == 0 && intent.extras?.containsKey(KEY_PHONE) == true && (action == Intent.ACTION_INSERT_OR_EDIT || action == Intent.ACTION_INSERT)) {
val phoneNumber = intent.extras.get(KEY_PHONE)?.toString() ?: "" val phoneNumber = intent.extras.get(KEY_PHONE)?.toString() ?: ""
contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE)) contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE, ""))
contact!!.firstName = intent.extras.get(KEY_NAME)?.toString() ?: "" contact!!.firstName = intent.extras.get(KEY_NAME)?.toString() ?: ""
@ -754,7 +754,7 @@ class EditContactActivity : ContactActivity() {
val numberType = getPhoneNumberTypeId(numberHolder.contact_number_type.value) val numberType = getPhoneNumberTypeId(numberHolder.contact_number_type.value)
if (number.isNotEmpty()) { if (number.isNotEmpty()) {
phoneNumbers.add(PhoneNumber(number, numberType)) phoneNumbers.add(PhoneNumber(number, numberType, ""))
} }
} }
return phoneNumbers return phoneNumbers
@ -769,7 +769,7 @@ class EditContactActivity : ContactActivity() {
val emailType = getEmailTypeId(emailHolder.contact_email_type.value) val emailType = getEmailTypeId(emailHolder.contact_email_type.value)
if (email.isNotEmpty()) { if (email.isNotEmpty()) {
emails.add(Email(email, emailType)) emails.add(Email(email, emailType, ""))
} }
} }
return emails return emails
@ -784,7 +784,7 @@ class EditContactActivity : ContactActivity() {
val addressType = getAddressTypeId(addressHolder.contact_address_type.value) val addressType = getAddressTypeId(addressHolder.contact_address_type.value)
if (address.isNotEmpty()) { if (address.isNotEmpty()) {
addresses.add(Address(address, addressType)) addresses.add(Address(address, addressType, ""))
} }
} }
return addresses return addresses
@ -955,7 +955,7 @@ class EditContactActivity : ContactActivity() {
private fun parseEmail(contentValues: ContentValues) { private fun parseEmail(contentValues: ContentValues) {
val type = contentValues.getAsInteger(CommonDataKinds.Email.DATA2) ?: DEFAULT_EMAIL_TYPE val type = contentValues.getAsInteger(CommonDataKinds.Email.DATA2) ?: DEFAULT_EMAIL_TYPE
val emailValue = contentValues.getAsString(CommonDataKinds.Email.DATA1) ?: return val emailValue = contentValues.getAsString(CommonDataKinds.Email.DATA1) ?: return
val email = Email(emailValue, type) val email = Email(emailValue, type, "")
contact!!.emails.add(email) contact!!.emails.add(email)
} }
@ -963,7 +963,7 @@ class EditContactActivity : ContactActivity() {
val type = contentValues.getAsInteger(CommonDataKinds.StructuredPostal.DATA2) ?: DEFAULT_ADDRESS_TYPE val type = contentValues.getAsInteger(CommonDataKinds.StructuredPostal.DATA2) ?: DEFAULT_ADDRESS_TYPE
val addressValue = contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA4) val addressValue = contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA4)
?: contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA1) ?: return ?: contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA1) ?: return
val address = Address(addressValue, type) val address = Address(addressValue, type, "")
contact!!.addresses.add(address) contact!!.addresses.add(address)
} }

View File

@ -57,7 +57,6 @@ class ViewContactActivity : ContactActivity() {
return true return true
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (contact == null) { if (contact == null) {
return true return true

View File

@ -202,7 +202,8 @@ class ContactsHelper(val activity: Activity) {
val projection = arrayOf( val projection = arrayOf(
ContactsContract.Data.RAW_CONTACT_ID, ContactsContract.Data.RAW_CONTACT_ID,
CommonDataKinds.Phone.NUMBER, CommonDataKinds.Phone.NUMBER,
CommonDataKinds.Phone.TYPE CommonDataKinds.Phone.TYPE,
CommonDataKinds.Phone.LABEL
) )
val selection = if (contactId == null) getSourcesSelection() else "${ContactsContract.Data.RAW_CONTACT_ID} = ?" val selection = if (contactId == null) getSourcesSelection() else "${ContactsContract.Data.RAW_CONTACT_ID} = ?"
@ -216,12 +217,13 @@ class ContactsHelper(val activity: Activity) {
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
val number = cursor.getStringValue(CommonDataKinds.Phone.NUMBER) ?: continue val number = cursor.getStringValue(CommonDataKinds.Phone.NUMBER) ?: continue
val type = cursor.getIntValue(CommonDataKinds.Phone.TYPE) val type = cursor.getIntValue(CommonDataKinds.Phone.TYPE)
val label = cursor.getStringValue(CommonDataKinds.Phone.LABEL) ?: ""
if (phoneNumbers[id] == null) { if (phoneNumbers[id] == null) {
phoneNumbers.put(id, ArrayList()) phoneNumbers.put(id, ArrayList())
} }
val phoneNumber = PhoneNumber(number, type) val phoneNumber = PhoneNumber(number, type, label)
phoneNumbers[id].add(phoneNumber) phoneNumbers[id].add(phoneNumber)
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }
@ -270,7 +272,8 @@ class ContactsHelper(val activity: Activity) {
val projection = arrayOf( val projection = arrayOf(
ContactsContract.Data.RAW_CONTACT_ID, ContactsContract.Data.RAW_CONTACT_ID,
CommonDataKinds.Email.DATA, CommonDataKinds.Email.DATA,
CommonDataKinds.Email.TYPE CommonDataKinds.Email.TYPE,
CommonDataKinds.Email.LABEL
) )
val selection = if (contactId == null) getSourcesSelection() else "${ContactsContract.Data.RAW_CONTACT_ID} = ?" val selection = if (contactId == null) getSourcesSelection() else "${ContactsContract.Data.RAW_CONTACT_ID} = ?"
@ -284,12 +287,13 @@ class ContactsHelper(val activity: Activity) {
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
val email = cursor.getStringValue(CommonDataKinds.Email.DATA) ?: continue val email = cursor.getStringValue(CommonDataKinds.Email.DATA) ?: continue
val type = cursor.getIntValue(CommonDataKinds.Email.TYPE) val type = cursor.getIntValue(CommonDataKinds.Email.TYPE)
val label = cursor.getStringValue(CommonDataKinds.Email.LABEL) ?: ""
if (emails[id] == null) { if (emails[id] == null) {
emails.put(id, ArrayList()) emails.put(id, ArrayList())
} }
emails[id]!!.add(Email(email, type)) emails[id]!!.add(Email(email, type, label))
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -307,7 +311,8 @@ class ContactsHelper(val activity: Activity) {
val projection = arrayOf( val projection = arrayOf(
ContactsContract.Data.RAW_CONTACT_ID, ContactsContract.Data.RAW_CONTACT_ID,
CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS, CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS,
CommonDataKinds.StructuredPostal.TYPE CommonDataKinds.StructuredPostal.TYPE,
CommonDataKinds.StructuredPostal.LABEL
) )
val selection = if (contactId == null) getSourcesSelection() else "${ContactsContract.Data.RAW_CONTACT_ID} = ?" val selection = if (contactId == null) getSourcesSelection() else "${ContactsContract.Data.RAW_CONTACT_ID} = ?"
@ -321,12 +326,13 @@ class ContactsHelper(val activity: Activity) {
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
val address = cursor.getStringValue(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS) ?: continue val address = cursor.getStringValue(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS) ?: continue
val type = cursor.getIntValue(CommonDataKinds.StructuredPostal.TYPE) val type = cursor.getIntValue(CommonDataKinds.StructuredPostal.TYPE)
val label = cursor.getStringValue(CommonDataKinds.StructuredPostal.LABEL) ?: ""
if (addresses[id] == null) { if (addresses[id] == null) {
addresses.put(id, ArrayList()) addresses.put(id, ArrayList())
} }
addresses[id]!!.add(Address(address, type)) addresses[id]!!.add(Address(address, type, label))
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -50,14 +50,14 @@ class VcfImporter(val activity: SimpleActivity) {
ezContact.telephoneNumbers.forEach { ezContact.telephoneNumbers.forEach {
val type = getPhoneNumberTypeId(it.types.firstOrNull()?.value ?: MOBILE) val type = getPhoneNumberTypeId(it.types.firstOrNull()?.value ?: MOBILE)
val number = it.text val number = it.text
phoneNumbers.add(PhoneNumber(number, type)) phoneNumbers.add(PhoneNumber(number, type, ""))
} }
val emails = ArrayList<Email>() val emails = ArrayList<Email>()
ezContact.emails.forEach { ezContact.emails.forEach {
val type = getEmailTypeId(it.types.firstOrNull()?.value ?: HOME) val type = getEmailTypeId(it.types.firstOrNull()?.value ?: HOME)
val email = it.value val email = it.value
emails.add(Email(email, type)) emails.add(Email(email, type, ""))
} }
val addresses = ArrayList<Address>() val addresses = ArrayList<Address>()
@ -65,7 +65,7 @@ class VcfImporter(val activity: SimpleActivity) {
val type = getAddressTypeId(it.types.firstOrNull()?.value ?: HOME) val type = getAddressTypeId(it.types.firstOrNull()?.value ?: HOME)
val address = it.streetAddress val address = it.streetAddress
if (address?.isNotEmpty() == true) { if (address?.isNotEmpty() == true) {
addresses.add(Address(address, type)) addresses.add(Address(address, type, ""))
} }
} }

View File

@ -1,3 +1,3 @@
package com.simplemobiletools.contacts.models package com.simplemobiletools.contacts.models
data class Address(var value: String, var type: Int) data class Address(var value: String, var type: Int, var label: String)

View File

@ -94,10 +94,10 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m
fun getHashToCompare(): Int { fun getHashToCompare(): Int {
val newPhoneNumbers = ArrayList<PhoneNumber>() val newPhoneNumbers = ArrayList<PhoneNumber>()
phoneNumbers.mapTo(newPhoneNumbers) { PhoneNumber(it.value.replace(PHONE_NUMBER_PATTERN.toRegex(), ""), 0) } phoneNumbers.mapTo(newPhoneNumbers) { PhoneNumber(it.value.replace(PHONE_NUMBER_PATTERN.toRegex(), ""), 0, "") }
val newEmails = ArrayList<Email>() val newEmails = ArrayList<Email>()
emails.mapTo(newEmails) { Email(it.value, 0) } emails.mapTo(newEmails) { Email(it.value, 0, "") }
return copy(id = 0, prefix = "", firstName = getFullName().toLowerCase(), middleName = "", surname = "", suffix = "", nickname = "", photoUri = "", return copy(id = 0, prefix = "", firstName = getFullName().toLowerCase(), middleName = "", surname = "", suffix = "", nickname = "", photoUri = "",
phoneNumbers = newPhoneNumbers, events = ArrayList(), addresses = ArrayList(), emails = newEmails, source = "", starred = 0, phoneNumbers = newPhoneNumbers, events = ArrayList(), addresses = ArrayList(), emails = newEmails, source = "", starred = 0,

View File

@ -1,3 +1,3 @@
package com.simplemobiletools.contacts.models package com.simplemobiletools.contacts.models
data class Email(var value: String, var type: Int) data class Email(var value: String, var type: Int, var label: String)

View File

@ -1,3 +1,3 @@
package com.simplemobiletools.contacts.models package com.simplemobiletools.contacts.models
data class PhoneNumber(var value: String, var type: Int) data class PhoneNumber(var value: String, var type: Int, var label: String)