display custom phone number type label when appropriate

This commit is contained in:
tibbi 2018-09-02 21:12:39 +02:00
parent f74cc8cd31
commit ccd995dc44
3 changed files with 22 additions and 16 deletions

View File

@ -107,15 +107,21 @@ abstract class ContactActivity : SimpleActivity() {
}
}
fun getPhoneNumberTextId(type: Int) = when (type) {
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE -> R.string.mobile
ContactsContract.CommonDataKinds.Phone.TYPE_HOME -> R.string.home
ContactsContract.CommonDataKinds.Phone.TYPE_WORK -> R.string.work
ContactsContract.CommonDataKinds.Phone.TYPE_MAIN -> R.string.main_number
ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK -> R.string.work_fax
ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME -> R.string.home_fax
ContactsContract.CommonDataKinds.Phone.TYPE_PAGER -> R.string.pager
else -> R.string.other
fun getPhoneNumberText(type: Int, label: String): String {
return if (type == ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM) {
label
} else {
getString(when (type) {
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE -> R.string.mobile
ContactsContract.CommonDataKinds.Phone.TYPE_HOME -> R.string.home
ContactsContract.CommonDataKinds.Phone.TYPE_WORK -> R.string.work
ContactsContract.CommonDataKinds.Phone.TYPE_MAIN -> R.string.main_number
ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK -> R.string.work_fax
ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME -> R.string.home_fax
ContactsContract.CommonDataKinds.Phone.TYPE_PAGER -> R.string.pager
else -> R.string.other
})
}
}
fun getEmailTextId(type: Int) = when (type) {

View File

@ -361,7 +361,7 @@ class EditContactActivity : ContactActivity() {
numberHolder!!.apply {
contact_number.setText(number.value)
setupPhoneNumberTypePicker(contact_number_type, number.type)
setupPhoneNumberTypePicker(contact_number_type, number.type, number.label)
}
}
}
@ -514,7 +514,7 @@ class EditContactActivity : ContactActivity() {
if (contact!!.phoneNumbers.isEmpty()) {
val numberHolder = contact_numbers_holder.getChildAt(0)
(numberHolder as? ViewGroup)?.contact_number_type?.apply {
setupPhoneNumberTypePicker(this)
setupPhoneNumberTypePicker(this, DEFAULT_PHONE_NUMBER_TYPE, "")
}
}
@ -547,9 +547,9 @@ class EditContactActivity : ContactActivity() {
}
}
private fun setupPhoneNumberTypePicker(numberTypeField: TextView, type: Int = DEFAULT_PHONE_NUMBER_TYPE) {
private fun setupPhoneNumberTypePicker(numberTypeField: TextView, type: Int, label: String) {
numberTypeField.apply {
setText(getPhoneNumberTextId(type))
text = getPhoneNumberText(type, label)
setOnClickListener {
showNumberTypePicker(it as TextView)
}
@ -646,7 +646,7 @@ class EditContactActivity : ContactActivity() {
val currentNumberTypeId = getPhoneNumberTypeId(numberTypeField.value)
RadioGroupDialog(this, items, currentNumberTypeId) {
numberTypeField.setText(getPhoneNumberTextId(it as Int))
numberTypeField.text = getPhoneNumberText(it as Int, "")
}
}
@ -860,7 +860,7 @@ class EditContactActivity : ContactActivity() {
private fun addNewPhoneNumberField() {
val numberHolder = layoutInflater.inflate(R.layout.item_edit_phone_number, contact_numbers_holder, false) as ViewGroup
updateTextColors(numberHolder)
setupPhoneNumberTypePicker(numberHolder.contact_number_type)
setupPhoneNumberTypePicker(numberHolder.contact_number_type, DEFAULT_PHONE_NUMBER_TYPE, "")
contact_numbers_holder.addView(numberHolder)
contact_numbers_holder.onGlobalLayout {
numberHolder.contact_number.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.setText(getPhoneNumberTextId(phoneNumber.type))
contact_number_type.text = getPhoneNumberText(phoneNumber.type, phoneNumber.label)
setOnClickListener {
if (config.showCallConfirmation) {