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) { return if (type == ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM) {
label label
} else { } else {
@ -124,14 +124,20 @@ abstract class ContactActivity : SimpleActivity() {
} }
} }
fun getEmailTextId(type: Int) = when (type) { fun getEmailTypeText(type: Int, label: String): String {
ContactsContract.CommonDataKinds.Email.TYPE_HOME -> R.string.home return if (type == ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM) {
ContactsContract.CommonDataKinds.Email.TYPE_WORK -> R.string.work label
ContactsContract.CommonDataKinds.Email.TYPE_MOBILE -> R.string.mobile } else {
else -> R.string.other 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_HOME -> R.string.home
ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK -> R.string.work ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK -> R.string.work
else -> R.string.other else -> R.string.other

View File

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

View File

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