make sure View Contact Details shows only the proper fields
This commit is contained in:
parent
cfcaa67ba9
commit
d94dbde48e
|
@ -33,8 +33,9 @@ import java.text.SimpleDateFormat
|
|||
import java.util.*
|
||||
|
||||
abstract class ContactActivity : SimpleActivity() {
|
||||
var contact: Contact? = null
|
||||
var currentContactPhotoPath = ""
|
||||
protected var contact: Contact? = null
|
||||
protected var currentContactPhotoPath = ""
|
||||
protected var showFields = 0
|
||||
|
||||
fun showPhotoPlaceholder(photoView: ImageView) {
|
||||
val placeholder = resources.getColoredBitmap(R.drawable.ic_person, config.primaryColor.getContrastColor())
|
||||
|
|
|
@ -59,6 +59,7 @@ class EditContactActivity : ContactActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_edit_contact)
|
||||
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
|
||||
showFields = config.showContactFields
|
||||
|
||||
val action = intent.action
|
||||
isThirdPartyIntent = action == Intent.ACTION_EDIT || action == Intent.ACTION_INSERT_OR_EDIT || action == Intent.ACTION_INSERT
|
||||
|
|
|
@ -12,9 +12,7 @@ import com.simplemobiletools.commons.extensions.*
|
|||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.extensions.*
|
||||
import com.simplemobiletools.contacts.helpers.CONTACT_ID
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.IS_PRIVATE
|
||||
import com.simplemobiletools.contacts.helpers.*
|
||||
import kotlinx.android.synthetic.main.activity_view_contact.*
|
||||
import kotlinx.android.synthetic.main.item_event.view.*
|
||||
import kotlinx.android.synthetic.main.item_view_address.view.*
|
||||
|
@ -24,9 +22,11 @@ import kotlinx.android.synthetic.main.item_view_phone_number.view.*
|
|||
|
||||
class ViewContactActivity : ContactActivity() {
|
||||
private var isViewIntent = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_view_contact)
|
||||
showFields = config.showContactFields
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -138,25 +138,33 @@ class ViewContactActivity : ContactActivity() {
|
|||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
||||
contact!!.apply {
|
||||
contact_prefix.text = prefix
|
||||
contact_prefix.beVisibleIf(prefix.isNotEmpty())
|
||||
contact_prefix.beVisibleIf(prefix.isNotEmpty() && showFields and SHOW_PREFIX_FIELD != 0)
|
||||
|
||||
contact_first_name.text = firstName
|
||||
contact_first_name.beVisibleIf(firstName.isNotEmpty())
|
||||
contact_first_name.beVisibleIf(firstName.isNotEmpty() && showFields and SHOW_FIRST_NAME_FIELD != 0)
|
||||
|
||||
contact_middle_name.text = middleName
|
||||
contact_middle_name.beVisibleIf(middleName.isNotEmpty())
|
||||
contact_middle_name.beVisibleIf(middleName.isNotEmpty() && showFields and SHOW_MIDDLE_NAME_FIELD != 0)
|
||||
|
||||
contact_surname.text = surname
|
||||
contact_surname.beVisibleIf(surname.isNotEmpty())
|
||||
contact_surname.beVisibleIf(surname.isNotEmpty() && showFields and SHOW_SURNAME_FIELD != 0)
|
||||
|
||||
contact_suffix.text = suffix
|
||||
contact_suffix.beVisibleIf(suffix.isNotEmpty())
|
||||
contact_suffix.beVisibleIf(suffix.isNotEmpty() && showFields and SHOW_SUFFIX_FIELD != 0)
|
||||
|
||||
if (prefix.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty() && suffix.isEmpty()) {
|
||||
if (contact_prefix.isGone() && contact_first_name.isGone() && contact_middle_name.isGone() && contact_surname.isGone() && contact_suffix.isGone()) {
|
||||
contact_name_image.beInvisible()
|
||||
(contact_photo.layoutParams as RelativeLayout.LayoutParams).bottomMargin = resources.getDimension(R.dimen.medium_margin).toInt()
|
||||
}
|
||||
contact_source.text = getPublicContactSource(source)
|
||||
|
||||
if (showFields and SHOW_CONTACT_SOURCE_FIELD != 0) {
|
||||
contact_source.text = getPublicContactSource(source)
|
||||
contact_source_image.beVisible()
|
||||
contact_source.beVisible()
|
||||
} else {
|
||||
contact_source_image.beGone()
|
||||
contact_source.beGone()
|
||||
}
|
||||
}
|
||||
|
||||
contact_toggle_favorite.apply {
|
||||
|
@ -178,109 +186,140 @@ class ViewContactActivity : ContactActivity() {
|
|||
private fun setupPhoneNumbers() {
|
||||
contact_numbers_holder.removeAllViews()
|
||||
val phoneNumbers = contact!!.phoneNumbers
|
||||
phoneNumbers.forEach {
|
||||
layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply {
|
||||
val phoneNumber = it
|
||||
contact_numbers_holder.addView(this)
|
||||
contact_number.text = phoneNumber.value
|
||||
contact_number_type.setText(getPhoneNumberTextId(phoneNumber.type))
|
||||
if (phoneNumbers.isNotEmpty() && showFields and SHOW_PHONE_NUMBERS_FIELD != 0) {
|
||||
phoneNumbers.forEach {
|
||||
layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply {
|
||||
val phoneNumber = it
|
||||
contact_numbers_holder.addView(this)
|
||||
contact_number.text = phoneNumber.value
|
||||
contact_number_type.setText(getPhoneNumberTextId(phoneNumber.type))
|
||||
|
||||
setOnClickListener {
|
||||
startCallIntent(phoneNumber.value)
|
||||
setOnClickListener {
|
||||
startCallIntent(phoneNumber.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
contact_number_image.beVisible()
|
||||
contact_numbers_holder.beVisible()
|
||||
} else {
|
||||
contact_number_image.beGone()
|
||||
contact_numbers_holder.beGone()
|
||||
}
|
||||
|
||||
contact_number_image.beVisibleIf(phoneNumbers.isNotEmpty())
|
||||
contact_numbers_holder.beVisibleIf(phoneNumbers.isNotEmpty())
|
||||
}
|
||||
|
||||
private fun setupEmails() {
|
||||
contact_emails_holder.removeAllViews()
|
||||
val emails = contact!!.emails
|
||||
emails.forEach {
|
||||
layoutInflater.inflate(R.layout.item_view_email, contact_emails_holder, false).apply {
|
||||
val email = it
|
||||
contact_emails_holder.addView(this)
|
||||
contact_email.text = email.value
|
||||
contact_email_type.setText(getEmailTextId(email.type))
|
||||
if (emails.isNotEmpty() && showFields and SHOW_EMAILS_FIELD != 0) {
|
||||
emails.forEach {
|
||||
layoutInflater.inflate(R.layout.item_view_email, contact_emails_holder, false).apply {
|
||||
val email = it
|
||||
contact_emails_holder.addView(this)
|
||||
contact_email.text = email.value
|
||||
contact_email_type.setText(getEmailTextId(email.type))
|
||||
|
||||
setOnClickListener {
|
||||
sendEmailIntent(email.value)
|
||||
setOnClickListener {
|
||||
sendEmailIntent(email.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
contact_email_image.beVisible()
|
||||
contact_emails_holder.beVisible()
|
||||
} else {
|
||||
contact_email_image.beGone()
|
||||
contact_emails_holder.beGone()
|
||||
}
|
||||
|
||||
contact_email_image.beVisibleIf(emails.isNotEmpty())
|
||||
contact_emails_holder.beVisibleIf(emails.isNotEmpty())
|
||||
}
|
||||
|
||||
private fun setupAddresses() {
|
||||
contact_addresses_holder.removeAllViews()
|
||||
val addresses = contact!!.addresses
|
||||
addresses.forEach {
|
||||
layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply {
|
||||
val address = it
|
||||
contact_addresses_holder.addView(this)
|
||||
contact_address.text = address.value
|
||||
contact_address_type.setText(getAddressTextId(address.type))
|
||||
if (addresses.isNotEmpty() && showFields and SHOW_ADDRESSES_FIELD != 0) {
|
||||
addresses.forEach {
|
||||
layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply {
|
||||
val address = it
|
||||
contact_addresses_holder.addView(this)
|
||||
contact_address.text = address.value
|
||||
contact_address_type.setText(getAddressTextId(address.type))
|
||||
|
||||
setOnClickListener {
|
||||
sendAddressIntent(address.value)
|
||||
setOnClickListener {
|
||||
sendAddressIntent(address.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
contact_address_image.beVisible()
|
||||
contact_addresses_holder.beVisible()
|
||||
} else {
|
||||
contact_address_image.beGone()
|
||||
contact_addresses_holder.beGone()
|
||||
}
|
||||
|
||||
contact_address_image.beVisibleIf(addresses.isNotEmpty())
|
||||
contact_addresses_holder.beVisibleIf(addresses.isNotEmpty())
|
||||
}
|
||||
|
||||
private fun setupEvents() {
|
||||
contact_events_holder.removeAllViews()
|
||||
val events = contact!!.events
|
||||
events.forEach {
|
||||
layoutInflater.inflate(R.layout.item_event, contact_events_holder, false).apply {
|
||||
contact_events_holder.addView(this)
|
||||
contact_event.alpha = 1f
|
||||
getDateTime(it.value, contact_event)
|
||||
contact_event_type.setText(getEventTextId(it.type))
|
||||
contact_event_remove.beGone()
|
||||
if (events.isNotEmpty() && showFields and SHOW_EVENTS_FIELD != 0) {
|
||||
events.forEach {
|
||||
layoutInflater.inflate(R.layout.item_event, contact_events_holder, false).apply {
|
||||
contact_events_holder.addView(this)
|
||||
contact_event.alpha = 1f
|
||||
getDateTime(it.value, contact_event)
|
||||
contact_event_type.setText(getEventTextId(it.type))
|
||||
contact_event_remove.beGone()
|
||||
}
|
||||
}
|
||||
contact_event_image.beVisible()
|
||||
contact_events_holder.beVisible()
|
||||
} else {
|
||||
contact_event_image.beGone()
|
||||
contact_events_holder.beGone()
|
||||
}
|
||||
|
||||
contact_event_image.beVisibleIf(events.isNotEmpty())
|
||||
contact_events_holder.beVisibleIf(events.isNotEmpty())
|
||||
}
|
||||
|
||||
private fun setupNotes() {
|
||||
val notes = contact!!.notes
|
||||
contact_notes.text = notes
|
||||
contact_notes_image.beVisibleIf(notes.isNotEmpty())
|
||||
contact_notes.beVisibleIf(notes.isNotEmpty())
|
||||
if (notes.isNotEmpty() && showFields and SHOW_NOTES_FIELD != 0) {
|
||||
contact_notes.text = notes
|
||||
contact_notes_image.beVisible()
|
||||
contact_notes.beVisible()
|
||||
} else {
|
||||
contact_notes_image.beGone()
|
||||
contact_notes.beGone()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupOrganization() {
|
||||
val organization = contact!!.organization
|
||||
contact_organization_company.text = organization.company
|
||||
contact_organization_job_position.text = organization.jobPosition
|
||||
contact_organization_image.beGoneIf(organization.isEmpty())
|
||||
contact_organization_company.beGoneIf(organization.company.isEmpty())
|
||||
contact_organization_job_position.beGoneIf(organization.jobPosition.isEmpty())
|
||||
if (!organization.isEmpty() && showFields and SHOW_ORGANIZATION_FIELD != 0) {
|
||||
contact_organization_company.text = organization.company
|
||||
contact_organization_job_position.text = organization.jobPosition
|
||||
contact_organization_image.beGoneIf(organization.isEmpty())
|
||||
contact_organization_company.beGoneIf(organization.company.isEmpty())
|
||||
contact_organization_job_position.beGoneIf(organization.jobPosition.isEmpty())
|
||||
} else {
|
||||
contact_organization_image.beGone()
|
||||
contact_organization_company.beGone()
|
||||
contact_organization_job_position.beGone()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupGroups() {
|
||||
contact_groups_holder.removeAllViews()
|
||||
val groups = contact!!.groups
|
||||
groups.forEach {
|
||||
layoutInflater.inflate(R.layout.item_view_group, contact_groups_holder, false).apply {
|
||||
val group = it
|
||||
contact_groups_holder.addView(this)
|
||||
contact_group.text = group.title
|
||||
if (groups.isNotEmpty() && showFields and SHOW_GROUPS_FIELD != 0) {
|
||||
groups.forEach {
|
||||
layoutInflater.inflate(R.layout.item_view_group, contact_groups_holder, false).apply {
|
||||
val group = it
|
||||
contact_groups_holder.addView(this)
|
||||
contact_group.text = group.title
|
||||
}
|
||||
}
|
||||
contact_groups_image.beVisible()
|
||||
contact_groups_holder.beVisible()
|
||||
} else {
|
||||
contact_groups_image.beGone()
|
||||
contact_groups_holder.beGone()
|
||||
}
|
||||
|
||||
contact_groups_image.beVisibleIf(groups.isNotEmpty())
|
||||
contact_groups_holder.beVisibleIf(groups.isNotEmpty())
|
||||
}
|
||||
|
||||
private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_on_big else R.drawable.ic_star_off_big)
|
||||
|
|
Loading…
Reference in New Issue