show custom email labels as appropriate

This commit is contained in:
tibbi 2018-09-02 21:19:17 +02:00
parent ccd995dc44
commit a96949ffb5
3 changed files with 26 additions and 20 deletions

View File

@ -107,7 +107,7 @@ abstract class ContactActivity : SimpleActivity() {
}
}
fun getPhoneNumberText(type: Int, label: String): String {
fun getPhoneNumberTypeText(type: Int, label: String): String {
return if (type == ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM) {
label
} else {
@ -124,14 +124,20 @@ abstract class ContactActivity : SimpleActivity() {
}
}
fun getEmailTextId(type: Int) = when (type) {
ContactsContract.CommonDataKinds.Email.TYPE_HOME -> R.string.home
ContactsContract.CommonDataKinds.Email.TYPE_WORK -> R.string.work
ContactsContract.CommonDataKinds.Email.TYPE_MOBILE -> R.string.mobile
else -> R.string.other
fun getEmailTypeText(type: Int, label: String): String {
return if (type == ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM) {
label
} else {
getString(when (type) {
ContactsContract.CommonDataKinds.Email.TYPE_HOME -> R.string.home
ContactsContract.CommonDataKinds.Email.TYPE_WORK -> R.string.work
ContactsContract.CommonDataKinds.Email.TYPE_MOBILE -> R.string.mobile
else -> R.string.other
})
}
}
fun getAddressTextId(type: Int) = when (type) {
fun getAddressTypeText(type: Int) = when (type) {
ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME -> R.string.home
ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK -> R.string.work
else -> R.string.other

View File

@ -376,7 +376,7 @@ class EditContactActivity : ContactActivity() {
emailHolder!!.apply {
contact_email.setText(email.value)
setupEmailTypePicker(contact_email_type, email.type)
setupEmailTypePicker(contact_email_type, email.type, email.label)
}
}
}
@ -521,7 +521,7 @@ class EditContactActivity : ContactActivity() {
if (contact!!.emails.isEmpty()) {
val emailHolder = contact_emails_holder.getChildAt(0)
(emailHolder as? ViewGroup)?.contact_email_type?.apply {
setupEmailTypePicker(this)
setupEmailTypePicker(this, DEFAULT_EMAIL_TYPE, "")
}
}
@ -549,16 +549,16 @@ class EditContactActivity : ContactActivity() {
private fun setupPhoneNumberTypePicker(numberTypeField: TextView, type: Int, label: String) {
numberTypeField.apply {
text = getPhoneNumberText(type, label)
text = getPhoneNumberTypeText(type, label)
setOnClickListener {
showNumberTypePicker(it as TextView)
}
}
}
private fun setupEmailTypePicker(emailTypeField: TextView, type: Int = DEFAULT_EMAIL_TYPE) {
private fun setupEmailTypePicker(emailTypeField: TextView, type: Int, label: String) {
emailTypeField.apply {
setText(getEmailTextId(type))
text = getEmailTypeText(type, label)
setOnClickListener {
showEmailTypePicker(it as TextView)
}
@ -567,7 +567,7 @@ class EditContactActivity : ContactActivity() {
private fun setupAddressTypePicker(addressTypeField: TextView, type: Int = DEFAULT_ADDRESS_TYPE) {
addressTypeField.apply {
setText(getAddressTextId(type))
setText(getAddressTypeText(type))
setOnClickListener {
showAddressTypePicker(it as TextView)
}
@ -646,7 +646,7 @@ class EditContactActivity : ContactActivity() {
val currentNumberTypeId = getPhoneNumberTypeId(numberTypeField.value)
RadioGroupDialog(this, items, currentNumberTypeId) {
numberTypeField.text = getPhoneNumberText(it as Int, "")
numberTypeField.text = getPhoneNumberTypeText(it as Int, "")
}
}
@ -660,7 +660,7 @@ class EditContactActivity : ContactActivity() {
val currentEmailTypeId = getEmailTypeId(emailTypeField.value)
RadioGroupDialog(this, items, currentEmailTypeId) {
emailTypeField.setText(getEmailTextId(it as Int))
emailTypeField.setText(getEmailTypeText(it as Int, ""))
}
}
@ -673,7 +673,7 @@ class EditContactActivity : ContactActivity() {
val currentAddressTypeId = getAddressTypeId(addressTypeField.value)
RadioGroupDialog(this, items, currentAddressTypeId) {
addressTypeField.setText(getAddressTextId(it as Int))
addressTypeField.setText(getAddressTypeText(it as Int))
}
}
@ -871,7 +871,7 @@ class EditContactActivity : ContactActivity() {
private fun addNewEmailField() {
val emailHolder = layoutInflater.inflate(R.layout.item_edit_email, contact_emails_holder, false) as ViewGroup
updateTextColors(emailHolder)
setupEmailTypePicker(emailHolder.contact_email_type)
setupEmailTypePicker(emailHolder.contact_email_type, DEFAULT_EMAIL_TYPE, "")
contact_emails_holder.addView(emailHolder)
contact_emails_holder.onGlobalLayout {
emailHolder.contact_email.requestFocus()

View File

@ -222,7 +222,7 @@ class ViewContactActivity : ContactActivity() {
val phoneNumber = it
contact_numbers_holder.addView(this)
contact_number.text = phoneNumber.value
contact_number_type.text = getPhoneNumberText(phoneNumber.type, phoneNumber.label)
contact_number_type.text = getPhoneNumberTypeText(phoneNumber.type, phoneNumber.label)
setOnClickListener {
if (config.showCallConfirmation) {
@ -252,7 +252,7 @@ class ViewContactActivity : ContactActivity() {
val email = it
contact_emails_holder.addView(this)
contact_email.text = email.value
contact_email_type.setText(getEmailTextId(email.type))
contact_email_type.text = getEmailTypeText(email.type, email.label)
setOnClickListener {
sendEmailIntent(email.value)
@ -276,7 +276,7 @@ class ViewContactActivity : ContactActivity() {
val address = it
contact_addresses_holder.addView(this)
contact_address.text = address.value
contact_address_type.setText(getAddressTextId(address.type))
contact_address_type.setText(getAddressTypeText(address.type))
setOnClickListener {
sendAddressIntent(address.value)