make sure View Contact Details shows only the proper fields

This commit is contained in:
tibbi 2018-04-08 16:07:46 +02:00
parent cfcaa67ba9
commit d94dbde48e
3 changed files with 112 additions and 71 deletions

View File

@ -33,8 +33,9 @@ import java.text.SimpleDateFormat
import java.util.* import java.util.*
abstract class ContactActivity : SimpleActivity() { abstract class ContactActivity : SimpleActivity() {
var contact: Contact? = null protected var contact: Contact? = null
var currentContactPhotoPath = "" protected var currentContactPhotoPath = ""
protected var showFields = 0
fun showPhotoPlaceholder(photoView: ImageView) { fun showPhotoPlaceholder(photoView: ImageView) {
val placeholder = resources.getColoredBitmap(R.drawable.ic_person, config.primaryColor.getContrastColor()) val placeholder = resources.getColoredBitmap(R.drawable.ic_person, config.primaryColor.getContrastColor())

View File

@ -59,6 +59,7 @@ class EditContactActivity : ContactActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_edit_contact) setContentView(R.layout.activity_edit_contact)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross) supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
showFields = config.showContactFields
val action = intent.action val action = intent.action
isThirdPartyIntent = action == Intent.ACTION_EDIT || action == Intent.ACTION_INSERT_OR_EDIT || action == Intent.ACTION_INSERT isThirdPartyIntent = action == Intent.ACTION_EDIT || action == Intent.ACTION_INSERT_OR_EDIT || action == Intent.ACTION_INSERT

View File

@ -12,9 +12,7 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.extensions.* import com.simplemobiletools.contacts.extensions.*
import com.simplemobiletools.contacts.helpers.CONTACT_ID import com.simplemobiletools.contacts.helpers.*
import com.simplemobiletools.contacts.helpers.ContactsHelper
import com.simplemobiletools.contacts.helpers.IS_PRIVATE
import kotlinx.android.synthetic.main.activity_view_contact.* import kotlinx.android.synthetic.main.activity_view_contact.*
import kotlinx.android.synthetic.main.item_event.view.* import kotlinx.android.synthetic.main.item_event.view.*
import kotlinx.android.synthetic.main.item_view_address.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() { class ViewContactActivity : ContactActivity() {
private var isViewIntent = false private var isViewIntent = false
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)
showFields = config.showContactFields
} }
override fun onResume() { override fun onResume() {
@ -138,25 +138,33 @@ class ViewContactActivity : ContactActivity() {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
contact!!.apply { contact!!.apply {
contact_prefix.text = prefix 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.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.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.text = surname
contact_surname.beVisibleIf(surname.isNotEmpty()) contact_surname.beVisibleIf(surname.isNotEmpty() && showFields and SHOW_SURNAME_FIELD != 0)
contact_suffix.text = suffix 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_name_image.beInvisible()
(contact_photo.layoutParams as RelativeLayout.LayoutParams).bottomMargin = resources.getDimension(R.dimen.medium_margin).toInt() (contact_photo.layoutParams as RelativeLayout.LayoutParams).bottomMargin = resources.getDimension(R.dimen.medium_margin).toInt()
} }
if (showFields and SHOW_CONTACT_SOURCE_FIELD != 0) {
contact_source.text = getPublicContactSource(source) contact_source.text = getPublicContactSource(source)
contact_source_image.beVisible()
contact_source.beVisible()
} else {
contact_source_image.beGone()
contact_source.beGone()
}
} }
contact_toggle_favorite.apply { contact_toggle_favorite.apply {
@ -178,6 +186,7 @@ class ViewContactActivity : ContactActivity() {
private fun setupPhoneNumbers() { private fun setupPhoneNumbers() {
contact_numbers_holder.removeAllViews() contact_numbers_holder.removeAllViews()
val phoneNumbers = contact!!.phoneNumbers val phoneNumbers = contact!!.phoneNumbers
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 {
val phoneNumber = it val phoneNumber = it
@ -190,14 +199,18 @@ class ViewContactActivity : ContactActivity() {
} }
} }
} }
contact_number_image.beVisible()
contact_number_image.beVisibleIf(phoneNumbers.isNotEmpty()) contact_numbers_holder.beVisible()
contact_numbers_holder.beVisibleIf(phoneNumbers.isNotEmpty()) } else {
contact_number_image.beGone()
contact_numbers_holder.beGone()
}
} }
private fun setupEmails() { private fun setupEmails() {
contact_emails_holder.removeAllViews() contact_emails_holder.removeAllViews()
val emails = contact!!.emails val emails = contact!!.emails
if (emails.isNotEmpty() && showFields and SHOW_EMAILS_FIELD != 0) {
emails.forEach { emails.forEach {
layoutInflater.inflate(R.layout.item_view_email, contact_emails_holder, false).apply { layoutInflater.inflate(R.layout.item_view_email, contact_emails_holder, false).apply {
val email = it val email = it
@ -210,14 +223,18 @@ class ViewContactActivity : ContactActivity() {
} }
} }
} }
contact_email_image.beVisible()
contact_email_image.beVisibleIf(emails.isNotEmpty()) contact_emails_holder.beVisible()
contact_emails_holder.beVisibleIf(emails.isNotEmpty()) } else {
contact_email_image.beGone()
contact_emails_holder.beGone()
}
} }
private fun setupAddresses() { private fun setupAddresses() {
contact_addresses_holder.removeAllViews() contact_addresses_holder.removeAllViews()
val addresses = contact!!.addresses val addresses = contact!!.addresses
if (addresses.isNotEmpty() && showFields and SHOW_ADDRESSES_FIELD != 0) {
addresses.forEach { addresses.forEach {
layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply { layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply {
val address = it val address = it
@ -230,14 +247,18 @@ class ViewContactActivity : ContactActivity() {
} }
} }
} }
contact_address_image.beVisible()
contact_address_image.beVisibleIf(addresses.isNotEmpty()) contact_addresses_holder.beVisible()
contact_addresses_holder.beVisibleIf(addresses.isNotEmpty()) } else {
contact_address_image.beGone()
contact_addresses_holder.beGone()
}
} }
private fun setupEvents() { private fun setupEvents() {
contact_events_holder.removeAllViews() contact_events_holder.removeAllViews()
val events = contact!!.events val events = contact!!.events
if (events.isNotEmpty() && showFields and SHOW_EVENTS_FIELD != 0) {
events.forEach { events.forEach {
layoutInflater.inflate(R.layout.item_event, contact_events_holder, false).apply { layoutInflater.inflate(R.layout.item_event, contact_events_holder, false).apply {
contact_events_holder.addView(this) contact_events_holder.addView(this)
@ -247,30 +268,45 @@ class ViewContactActivity : ContactActivity() {
contact_event_remove.beGone() contact_event_remove.beGone()
} }
} }
contact_event_image.beVisible()
contact_event_image.beVisibleIf(events.isNotEmpty()) contact_events_holder.beVisible()
contact_events_holder.beVisibleIf(events.isNotEmpty()) } else {
contact_event_image.beGone()
contact_events_holder.beGone()
}
} }
private fun setupNotes() { private fun setupNotes() {
val notes = contact!!.notes val notes = contact!!.notes
if (notes.isNotEmpty() && showFields and SHOW_NOTES_FIELD != 0) {
contact_notes.text = notes contact_notes.text = notes
contact_notes_image.beVisibleIf(notes.isNotEmpty()) contact_notes_image.beVisible()
contact_notes.beVisibleIf(notes.isNotEmpty()) contact_notes.beVisible()
} else {
contact_notes_image.beGone()
contact_notes.beGone()
}
} }
private fun setupOrganization() { private fun setupOrganization() {
val organization = contact!!.organization val organization = contact!!.organization
if (!organization.isEmpty() && showFields and SHOW_ORGANIZATION_FIELD != 0) {
contact_organization_company.text = organization.company contact_organization_company.text = organization.company
contact_organization_job_position.text = organization.jobPosition contact_organization_job_position.text = organization.jobPosition
contact_organization_image.beGoneIf(organization.isEmpty()) contact_organization_image.beGoneIf(organization.isEmpty())
contact_organization_company.beGoneIf(organization.company.isEmpty()) contact_organization_company.beGoneIf(organization.company.isEmpty())
contact_organization_job_position.beGoneIf(organization.jobPosition.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() { private fun setupGroups() {
contact_groups_holder.removeAllViews() contact_groups_holder.removeAllViews()
val groups = contact!!.groups val groups = contact!!.groups
if (groups.isNotEmpty() && showFields and SHOW_GROUPS_FIELD != 0) {
groups.forEach { groups.forEach {
layoutInflater.inflate(R.layout.item_view_group, contact_groups_holder, false).apply { layoutInflater.inflate(R.layout.item_view_group, contact_groups_holder, false).apply {
val group = it val group = it
@ -278,9 +314,12 @@ class ViewContactActivity : ContactActivity() {
contact_group.text = group.title contact_group.text = group.title
} }
} }
contact_groups_image.beVisible()
contact_groups_image.beVisibleIf(groups.isNotEmpty()) contact_groups_holder.beVisible()
contact_groups_holder.beVisibleIf(groups.isNotEmpty()) } else {
contact_groups_image.beGone()
contact_groups_holder.beGone()
}
} }
private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_on_big else R.drawable.ic_star_off_big) private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_on_big else R.drawable.ic_star_off_big)