retrieve Custom type labels at phone number, email, address
This commit is contained in:
parent
5a0ebde4d3
commit
f74cc8cd31
|
@ -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)) {
|
||||
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() ?: ""
|
||||
|
||||
|
@ -754,7 +754,7 @@ class EditContactActivity : ContactActivity() {
|
|||
val numberType = getPhoneNumberTypeId(numberHolder.contact_number_type.value)
|
||||
|
||||
if (number.isNotEmpty()) {
|
||||
phoneNumbers.add(PhoneNumber(number, numberType))
|
||||
phoneNumbers.add(PhoneNumber(number, numberType, ""))
|
||||
}
|
||||
}
|
||||
return phoneNumbers
|
||||
|
@ -769,7 +769,7 @@ class EditContactActivity : ContactActivity() {
|
|||
val emailType = getEmailTypeId(emailHolder.contact_email_type.value)
|
||||
|
||||
if (email.isNotEmpty()) {
|
||||
emails.add(Email(email, emailType))
|
||||
emails.add(Email(email, emailType, ""))
|
||||
}
|
||||
}
|
||||
return emails
|
||||
|
@ -784,7 +784,7 @@ class EditContactActivity : ContactActivity() {
|
|||
val addressType = getAddressTypeId(addressHolder.contact_address_type.value)
|
||||
|
||||
if (address.isNotEmpty()) {
|
||||
addresses.add(Address(address, addressType))
|
||||
addresses.add(Address(address, addressType, ""))
|
||||
}
|
||||
}
|
||||
return addresses
|
||||
|
@ -955,7 +955,7 @@ class EditContactActivity : ContactActivity() {
|
|||
private fun parseEmail(contentValues: ContentValues) {
|
||||
val type = contentValues.getAsInteger(CommonDataKinds.Email.DATA2) ?: DEFAULT_EMAIL_TYPE
|
||||
val emailValue = contentValues.getAsString(CommonDataKinds.Email.DATA1) ?: return
|
||||
val email = Email(emailValue, type)
|
||||
val email = Email(emailValue, type, "")
|
||||
contact!!.emails.add(email)
|
||||
}
|
||||
|
||||
|
@ -963,7 +963,7 @@ class EditContactActivity : ContactActivity() {
|
|||
val type = contentValues.getAsInteger(CommonDataKinds.StructuredPostal.DATA2) ?: DEFAULT_ADDRESS_TYPE
|
||||
val addressValue = contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA4)
|
||||
?: contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA1) ?: return
|
||||
val address = Address(addressValue, type)
|
||||
val address = Address(addressValue, type, "")
|
||||
contact!!.addresses.add(address)
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,6 @@ class ViewContactActivity : ContactActivity() {
|
|||
return true
|
||||
}
|
||||
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (contact == null) {
|
||||
return true
|
||||
|
|
|
@ -202,7 +202,8 @@ class ContactsHelper(val activity: Activity) {
|
|||
val projection = arrayOf(
|
||||
ContactsContract.Data.RAW_CONTACT_ID,
|
||||
CommonDataKinds.Phone.NUMBER,
|
||||
CommonDataKinds.Phone.TYPE
|
||||
CommonDataKinds.Phone.TYPE,
|
||||
CommonDataKinds.Phone.LABEL
|
||||
)
|
||||
|
||||
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 number = cursor.getStringValue(CommonDataKinds.Phone.NUMBER) ?: continue
|
||||
val type = cursor.getIntValue(CommonDataKinds.Phone.TYPE)
|
||||
val label = cursor.getStringValue(CommonDataKinds.Phone.LABEL) ?: ""
|
||||
|
||||
if (phoneNumbers[id] == null) {
|
||||
phoneNumbers.put(id, ArrayList())
|
||||
}
|
||||
|
||||
val phoneNumber = PhoneNumber(number, type)
|
||||
val phoneNumber = PhoneNumber(number, type, label)
|
||||
phoneNumbers[id].add(phoneNumber)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
|
@ -270,7 +272,8 @@ class ContactsHelper(val activity: Activity) {
|
|||
val projection = arrayOf(
|
||||
ContactsContract.Data.RAW_CONTACT_ID,
|
||||
CommonDataKinds.Email.DATA,
|
||||
CommonDataKinds.Email.TYPE
|
||||
CommonDataKinds.Email.TYPE,
|
||||
CommonDataKinds.Email.LABEL
|
||||
)
|
||||
|
||||
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 email = cursor.getStringValue(CommonDataKinds.Email.DATA) ?: continue
|
||||
val type = cursor.getIntValue(CommonDataKinds.Email.TYPE)
|
||||
val label = cursor.getStringValue(CommonDataKinds.Email.LABEL) ?: ""
|
||||
|
||||
if (emails[id] == null) {
|
||||
emails.put(id, ArrayList())
|
||||
}
|
||||
|
||||
emails[id]!!.add(Email(email, type))
|
||||
emails[id]!!.add(Email(email, type, label))
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -307,7 +311,8 @@ class ContactsHelper(val activity: Activity) {
|
|||
val projection = arrayOf(
|
||||
ContactsContract.Data.RAW_CONTACT_ID,
|
||||
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} = ?"
|
||||
|
@ -321,12 +326,13 @@ class ContactsHelper(val activity: Activity) {
|
|||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
||||
val address = cursor.getStringValue(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS) ?: continue
|
||||
val type = cursor.getIntValue(CommonDataKinds.StructuredPostal.TYPE)
|
||||
val label = cursor.getStringValue(CommonDataKinds.StructuredPostal.LABEL) ?: ""
|
||||
|
||||
if (addresses[id] == null) {
|
||||
addresses.put(id, ArrayList())
|
||||
}
|
||||
|
||||
addresses[id]!!.add(Address(address, type))
|
||||
addresses[id]!!.add(Address(address, type, label))
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -50,14 +50,14 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||
ezContact.telephoneNumbers.forEach {
|
||||
val type = getPhoneNumberTypeId(it.types.firstOrNull()?.value ?: MOBILE)
|
||||
val number = it.text
|
||||
phoneNumbers.add(PhoneNumber(number, type))
|
||||
phoneNumbers.add(PhoneNumber(number, type, ""))
|
||||
}
|
||||
|
||||
val emails = ArrayList<Email>()
|
||||
ezContact.emails.forEach {
|
||||
val type = getEmailTypeId(it.types.firstOrNull()?.value ?: HOME)
|
||||
val email = it.value
|
||||
emails.add(Email(email, type))
|
||||
emails.add(Email(email, type, ""))
|
||||
}
|
||||
|
||||
val addresses = ArrayList<Address>()
|
||||
|
@ -65,7 +65,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||
val type = getAddressTypeId(it.types.firstOrNull()?.value ?: HOME)
|
||||
val address = it.streetAddress
|
||||
if (address?.isNotEmpty() == true) {
|
||||
addresses.add(Address(address, type))
|
||||
addresses.add(Address(address, type, ""))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
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)
|
||||
|
|
|
@ -94,10 +94,10 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m
|
|||
|
||||
fun getHashToCompare(): Int {
|
||||
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>()
|
||||
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 = "",
|
||||
phoneNumbers = newPhoneNumbers, events = ArrayList(), addresses = ArrayList(), emails = newEmails, source = "", starred = 0,
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
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)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue