removing a magic number at adding phone numbers

This commit is contained in:
tibbi 2019-09-15 11:32:34 +02:00
parent 128f191264
commit f9bd62b2a7
1 changed files with 6 additions and 6 deletions

View File

@ -36,6 +36,8 @@ class ViewContactActivity : ContactActivity() {
private var duplicateContacts = ArrayList<Contact>() private var duplicateContacts = ArrayList<Contact>()
private var showFields = 0 private var showFields = 0
private val COMPARABLE_PHONE_NUMBER_LENGTH = 7
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_view_contact) setContentView(R.layout.activity_view_contact)
@ -278,22 +280,20 @@ class ViewContactActivity : ContactActivity() {
} }
private fun setupPhoneNumbers() { private fun setupPhoneNumbers() {
contact_numbers_holder.removeAllViews()
var phoneNumbers = contact!!.phoneNumbers.toMutableSet() as LinkedHashSet<PhoneNumber> var phoneNumbers = contact!!.phoneNumbers.toMutableSet() as LinkedHashSet<PhoneNumber>
duplicateContacts.forEach { duplicateContacts.forEach {
it.phoneNumbers.forEach { phoneNumbers.addAll(it.phoneNumbers)
phoneNumbers.add(it)
}
} }
phoneNumbers = phoneNumbers.distinctBy { phoneNumbers = phoneNumbers.distinctBy {
if (it.normalizedNumber != null && it.normalizedNumber!!.length >= 7) { if (it.normalizedNumber != null && it.normalizedNumber!!.length >= COMPARABLE_PHONE_NUMBER_LENGTH) {
it.normalizedNumber?.substring(it.normalizedNumber!!.length - 7) it.normalizedNumber?.substring(it.normalizedNumber!!.length - COMPARABLE_PHONE_NUMBER_LENGTH)
} else { } else {
it.normalizedNumber it.normalizedNumber
} }
}.toMutableSet() as LinkedHashSet<PhoneNumber> }.toMutableSet() as LinkedHashSet<PhoneNumber>
contact_numbers_holder.removeAllViews()
if (phoneNumbers.isNotEmpty() && showFields and SHOW_PHONE_NUMBERS_FIELD != 0) { if (phoneNumbers.isNotEmpty() && showFields and SHOW_PHONE_NUMBERS_FIELD != 0) {
phoneNumbers.forEach { phoneNumbers.forEach {
layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply { layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply {