properly fill all required fields at Sharing from View screen

This commit is contained in:
tibbi 2019-09-15 23:39:09 +02:00
parent cf2b6b6d5e
commit 209dbc799b

View File

@ -284,49 +284,45 @@ class ViewContactActivity : ContactActivity() {
} }
private fun setupPhoneNumbers() { private fun setupPhoneNumbers() {
contact_numbers_holder.removeAllViews() var phoneNumbers = contact!!.phoneNumbers.toMutableSet() as LinkedHashSet<PhoneNumber>
if (showFields and SHOW_PHONE_NUMBERS_FIELD != 0) { duplicateContacts.forEach {
var phoneNumbers = contact!!.phoneNumbers.toMutableSet() as LinkedHashSet<PhoneNumber> phoneNumbers.addAll(it.phoneNumbers)
duplicateContacts.forEach { }
phoneNumbers.addAll(it.phoneNumbers)
phoneNumbers = phoneNumbers.distinctBy {
if (it.normalizedNumber != null && it.normalizedNumber!!.length >= COMPARABLE_PHONE_NUMBER_LENGTH) {
it.normalizedNumber?.substring(it.normalizedNumber!!.length - COMPARABLE_PHONE_NUMBER_LENGTH)
} else {
it.normalizedNumber
} }
}.toMutableSet() as LinkedHashSet<PhoneNumber>
phoneNumbers = phoneNumbers.distinctBy { phoneNumbers = phoneNumbers.sortedBy { it.type }.toMutableSet() as LinkedHashSet<PhoneNumber>
if (it.normalizedNumber != null && it.normalizedNumber!!.length >= COMPARABLE_PHONE_NUMBER_LENGTH) { fullContact!!.phoneNumbers = phoneNumbers.toMutableList() as ArrayList<PhoneNumber>
it.normalizedNumber?.substring(it.normalizedNumber!!.length - COMPARABLE_PHONE_NUMBER_LENGTH) contact_numbers_holder.removeAllViews()
} else {
it.normalizedNumber
}
}.toMutableSet() as LinkedHashSet<PhoneNumber>
phoneNumbers = phoneNumbers.sortedBy { it.type }.toMutableSet() as LinkedHashSet<PhoneNumber> if (phoneNumbers.isNotEmpty() && showFields and SHOW_PHONE_NUMBERS_FIELD != 0) {
fullContact!!.phoneNumbers = phoneNumbers.toMutableList() as ArrayList<PhoneNumber> phoneNumbers.forEach {
if (phoneNumbers.isNotEmpty()) { layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply {
phoneNumbers.forEach { val phoneNumber = it
layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply { contact_numbers_holder.addView(this)
val phoneNumber = it contact_number.text = phoneNumber.value
contact_numbers_holder.addView(this) contact_number_type.text = getPhoneNumberTypeText(phoneNumber.type, phoneNumber.label)
contact_number.text = phoneNumber.value copyOnLongClick(phoneNumber.value)
contact_number_type.text = getPhoneNumberTypeText(phoneNumber.type, phoneNumber.label)
copyOnLongClick(phoneNumber.value)
setOnClickListener { setOnClickListener {
if (config.showCallConfirmation) { if (config.showCallConfirmation) {
CallConfirmationDialog(this@ViewContactActivity, phoneNumber.value) { CallConfirmationDialog(this@ViewContactActivity, phoneNumber.value) {
startCallIntent(phoneNumber.value)
}
} else {
startCallIntent(phoneNumber.value) startCallIntent(phoneNumber.value)
} }
} else {
startCallIntent(phoneNumber.value)
} }
} }
} }
contact_numbers_image.beVisible()
contact_numbers_holder.beVisible()
} else {
contact_numbers_image.beGone()
contact_numbers_holder.beGone()
} }
contact_numbers_image.beVisible()
contact_numbers_holder.beVisible()
} else { } else {
contact_numbers_image.beGone() contact_numbers_image.beGone()
contact_numbers_holder.beGone() contact_numbers_holder.beGone()
@ -360,35 +356,31 @@ class ViewContactActivity : ContactActivity() {
} }
private fun setupAddresses() { private fun setupAddresses() {
var addresses = contact!!.addresses.toMutableSet() as LinkedHashSet<Address>
duplicateContacts.forEach {
addresses.addAll(it.addresses)
}
addresses = addresses.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Address>
fullContact!!.addresses = addresses.toMutableList() as ArrayList<Address>
contact_addresses_holder.removeAllViews() contact_addresses_holder.removeAllViews()
if (showFields and SHOW_ADDRESSES_FIELD != 0) {
var addresses = contact!!.addresses.toMutableSet() as LinkedHashSet<Address>
duplicateContacts.forEach {
addresses.addAll(it.addresses)
}
addresses = addresses.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Address> if (addresses.isNotEmpty() && showFields and SHOW_ADDRESSES_FIELD != 0) {
fullContact!!.addresses = addresses.toMutableList() as ArrayList<Address> addresses.forEach {
if (addresses.isNotEmpty()) { layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply {
addresses.forEach { val address = it
layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply { contact_addresses_holder.addView(this)
val address = it contact_address.text = address.value
contact_addresses_holder.addView(this) contact_address_type.text = getAddressTypeText(address.type, address.label)
contact_address.text = address.value copyOnLongClick(address.value)
contact_address_type.text = getAddressTypeText(address.type, address.label)
copyOnLongClick(address.value)
setOnClickListener { setOnClickListener {
sendAddressIntent(address.value) sendAddressIntent(address.value)
}
} }
} }
contact_addresses_image.beVisible()
contact_addresses_holder.beVisible()
} else {
contact_addresses_image.beGone()
contact_addresses_holder.beGone()
} }
contact_addresses_image.beVisible()
contact_addresses_holder.beVisible()
} else { } else {
contact_addresses_image.beGone() contact_addresses_image.beGone()
contact_addresses_holder.beGone() contact_addresses_holder.beGone()
@ -396,31 +388,27 @@ class ViewContactActivity : ContactActivity() {
} }
private fun setupIMs() { private fun setupIMs() {
contact_ims_holder.removeAllViews() var IMs = contact!!.IMs.toMutableSet() as LinkedHashSet<IM>
if (showFields and SHOW_IMS_FIELD != 0) { duplicateContacts.forEach {
var IMs = contact!!.IMs.toMutableSet() as LinkedHashSet<IM> IMs.addAll(it.IMs)
duplicateContacts.forEach { }
IMs.addAll(it.IMs)
}
IMs = IMs.sortedBy { it.type }.toMutableSet() as LinkedHashSet<IM> IMs = IMs.sortedBy { it.type }.toMutableSet() as LinkedHashSet<IM>
fullContact!!.IMs = IMs.toMutableList() as ArrayList<IM> fullContact!!.IMs = IMs.toMutableList() as ArrayList<IM>
if (IMs.isNotEmpty()) { contact_ims_holder.removeAllViews()
IMs.forEach {
layoutInflater.inflate(R.layout.item_view_im, contact_ims_holder, false).apply { if (IMs.isNotEmpty() && showFields and SHOW_IMS_FIELD != 0) {
val IM = it IMs.forEach {
contact_ims_holder.addView(this) layoutInflater.inflate(R.layout.item_view_im, contact_ims_holder, false).apply {
contact_im.text = IM.value val IM = it
contact_im_type.text = getIMTypeText(IM.type, IM.label) contact_ims_holder.addView(this)
copyOnLongClick(IM.value) contact_im.text = IM.value
} contact_im_type.text = getIMTypeText(IM.type, IM.label)
copyOnLongClick(IM.value)
} }
contact_ims_image.beVisible()
contact_ims_holder.beVisible()
} else {
contact_ims_image.beGone()
contact_ims_holder.beGone()
} }
contact_ims_image.beVisible()
contact_ims_holder.beVisible()
} else { } else {
contact_ims_image.beGone() contact_ims_image.beGone()
contact_ims_holder.beGone() contact_ims_holder.beGone()
@ -428,30 +416,26 @@ class ViewContactActivity : ContactActivity() {
} }
private fun setupEvents() { private fun setupEvents() {
contact_events_holder.removeAllViews() var events = contact!!.events.toMutableSet() as LinkedHashSet<Event>
if (showFields and SHOW_EVENTS_FIELD != 0) { duplicateContacts.forEach {
var events = contact!!.events.toMutableSet() as LinkedHashSet<Event> events.addAll(it.events)
duplicateContacts.forEach { }
events.addAll(it.events)
}
events = events.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Event> events = events.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Event>
fullContact!!.events = events.toMutableList() as ArrayList<Event> fullContact!!.events = events.toMutableList() as ArrayList<Event>
if (events.isNotEmpty()) { contact_events_holder.removeAllViews()
events.forEach {
layoutInflater.inflate(R.layout.item_view_event, contact_events_holder, false).apply { if (events.isNotEmpty() && showFields and SHOW_EVENTS_FIELD != 0) {
contact_events_holder.addView(this) events.forEach {
it.value.getDateTimeFromDateString(contact_event) layoutInflater.inflate(R.layout.item_view_event, contact_events_holder, false).apply {
contact_event_type.setText(getEventTextId(it.type)) contact_events_holder.addView(this)
copyOnLongClick(it.value) it.value.getDateTimeFromDateString(contact_event)
} contact_event_type.setText(getEventTextId(it.type))
copyOnLongClick(it.value)
} }
contact_events_image.beVisible()
contact_events_holder.beVisible()
} else {
contact_events_image.beGone()
contact_events_holder.beGone()
} }
contact_events_image.beVisible()
contact_events_holder.beVisible()
} else { } else {
contact_events_image.beGone() contact_events_image.beGone()
contact_events_holder.beGone() contact_events_holder.beGone()
@ -493,34 +477,30 @@ class ViewContactActivity : ContactActivity() {
} }
private fun setupWebsites() { private fun setupWebsites() {
var websites = contact!!.websites.toMutableSet() as LinkedHashSet<String>
duplicateContacts.forEach {
websites.addAll(it.websites)
}
websites = websites.sorted().toMutableSet() as LinkedHashSet<String>
fullContact!!.websites = websites.toMutableList() as ArrayList<String>
contact_websites_holder.removeAllViews() contact_websites_holder.removeAllViews()
if (showFields and SHOW_WEBSITES_FIELD != 0) {
var websites = contact!!.websites.toMutableSet() as LinkedHashSet<String>
duplicateContacts.forEach {
websites.addAll(it.websites)
}
websites = websites.sorted().toMutableSet() as LinkedHashSet<String> if (websites.isNotEmpty() && showFields and SHOW_WEBSITES_FIELD != 0) {
fullContact!!.websites = websites.toMutableList() as ArrayList<String> websites.forEach {
if (websites.isNotEmpty()) { val url = it
websites.forEach { layoutInflater.inflate(R.layout.item_website, contact_websites_holder, false).apply {
val url = it contact_websites_holder.addView(this)
layoutInflater.inflate(R.layout.item_website, contact_websites_holder, false).apply { contact_website.text = url
contact_websites_holder.addView(this) copyOnLongClick(url)
contact_website.text = url
copyOnLongClick(url)
setOnClickListener { setOnClickListener {
openWebsiteIntent(url) openWebsiteIntent(url)
}
} }
} }
contact_websites_image.beVisible()
contact_websites_holder.beVisible()
} else {
contact_websites_image.beGone()
contact_websites_holder.beGone()
} }
contact_websites_image.beVisible()
contact_websites_holder.beVisible()
} else { } else {
contact_websites_image.beGone() contact_websites_image.beGone()
contact_websites_holder.beGone() contact_websites_holder.beGone()
@ -528,30 +508,26 @@ class ViewContactActivity : ContactActivity() {
} }
private fun setupGroups() { private fun setupGroups() {
contact_groups_holder.removeAllViews() var groups = contact!!.groups.toMutableSet() as LinkedHashSet<Group>
if (showFields and SHOW_GROUPS_FIELD != 0) { duplicateContacts.forEach {
var groups = contact!!.groups.toMutableSet() as LinkedHashSet<Group> groups.addAll(it.groups)
duplicateContacts.forEach { }
groups.addAll(it.groups)
}
groups = groups.sortedBy { it.title }.toMutableSet() as LinkedHashSet<Group> groups = groups.sortedBy { it.title }.toMutableSet() as LinkedHashSet<Group>
fullContact!!.groups = groups.toMutableList() as ArrayList<Group> fullContact!!.groups = groups.toMutableList() as ArrayList<Group>
if (groups.isNotEmpty()) { contact_groups_holder.removeAllViews()
groups.forEach {
layoutInflater.inflate(R.layout.item_view_group, contact_groups_holder, false).apply { if (groups.isNotEmpty() && showFields and SHOW_GROUPS_FIELD != 0) {
val group = it groups.forEach {
contact_groups_holder.addView(this) layoutInflater.inflate(R.layout.item_view_group, contact_groups_holder, false).apply {
contact_group.text = group.title val group = it
copyOnLongClick(group.title) contact_groups_holder.addView(this)
} contact_group.text = group.title
copyOnLongClick(group.title)
} }
contact_groups_image.beVisible()
contact_groups_holder.beVisible()
} else {
contact_groups_image.beGone()
contact_groups_holder.beGone()
} }
contact_groups_image.beVisible()
contact_groups_holder.beVisible()
} else { } else {
contact_groups_image.beGone() contact_groups_image.beGone()
contact_groups_holder.beGone() contact_groups_holder.beGone()