From 510da6b140afad83f5b59ea8730c83411ee8088f Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 8 Apr 2018 17:44:23 +0200 Subject: [PATCH] make sure only the proper fields are shown at Edit Contact screen --- .../activities/EditContactActivity.kt | 268 +++++++++++------- .../activities/ViewContactActivity.kt | 22 +- .../main/res/layout/activity_edit_contact.xml | 40 +-- .../main/res/layout/activity_view_contact.xml | 10 +- 4 files changed, 203 insertions(+), 137 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt index ffd03a4d..b709f418 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -170,24 +170,24 @@ class EditContactActivity : ContactActivity() { contact_start_call.applyColorFilter(textColor) contact_send_email.applyColorFilter(textColor) contact_name_image.applyColorFilter(textColor) - contact_number_image.applyColorFilter(textColor) - contact_email_image.applyColorFilter(textColor) - contact_address_image.applyColorFilter(textColor) - contact_event_image.applyColorFilter(textColor) + contact_numbers_image.applyColorFilter(textColor) + contact_emails_image.applyColorFilter(textColor) + contact_addresses_image.applyColorFilter(textColor) + contact_events_image.applyColorFilter(textColor) contact_notes_image.applyColorFilter(textColor) contact_source_image.applyColorFilter(textColor) contact_groups_image.applyColorFilter(textColor) contact_organization_image.applyColorFilter(textColor) val adjustedPrimaryColor = getAdjustedPrimaryColor() - contact_number_add_new.applyColorFilter(adjustedPrimaryColor) - contact_number_add_new.background.applyColorFilter(textColor) - contact_email_add_new.applyColorFilter(adjustedPrimaryColor) - contact_email_add_new.background.applyColorFilter(textColor) - contact_address_add_new.applyColorFilter(adjustedPrimaryColor) - contact_address_add_new.background.applyColorFilter(textColor) - contact_event_add_new.applyColorFilter(adjustedPrimaryColor) - contact_event_add_new.background.applyColorFilter(textColor) + contact_numbers_add_new.applyColorFilter(adjustedPrimaryColor) + contact_numbers_add_new.background.applyColorFilter(textColor) + contact_emails_add_new.applyColorFilter(adjustedPrimaryColor) + contact_emails_add_new.background.applyColorFilter(textColor) + contact_addresses_add_new.applyColorFilter(adjustedPrimaryColor) + contact_addresses_add_new.background.applyColorFilter(textColor) + contact_events_add_new.applyColorFilter(adjustedPrimaryColor) + contact_events_add_new.background.applyColorFilter(textColor) contact_groups_add_new.applyColorFilter(adjustedPrimaryColor) contact_groups_add_new.background.applyColorFilter(textColor) @@ -196,12 +196,14 @@ class EditContactActivity : ContactActivity() { contact_send_sms.setOnClickListener { trySendSMS() } contact_start_call.setOnClickListener { tryStartCall(contact!!) } contact_send_email.setOnClickListener { trySendEmail() } - contact_number_add_new.setOnClickListener { addNewPhoneNumberField() } - contact_email_add_new.setOnClickListener { addNewEmailField() } - contact_address_add_new.setOnClickListener { addNewAddressField() } - contact_event_add_new.setOnClickListener { addNewEventField() } + contact_numbers_add_new.setOnClickListener { addNewPhoneNumberField() } + contact_emails_add_new.setOnClickListener { addNewEmailField() } + contact_addresses_add_new.setOnClickListener { addNewAddressField() } + contact_events_add_new.setOnClickListener { addNewEventField() } contact_groups_add_new.setOnClickListener { showSelectGroupsDialog() } + setupFieldVisibility() + contact_toggle_favorite.apply { setImageDrawable(getStarDrawable(contact!!.starred == 1)) tag = contact!!.starred @@ -240,6 +242,55 @@ class EditContactActivity : ContactActivity() { } } + private fun setupFieldVisibility() { + if (showFields and (SHOW_PREFIX_FIELD or SHOW_FIRST_NAME_FIELD or SHOW_MIDDLE_NAME_FIELD or SHOW_SURNAME_FIELD or SHOW_SUFFIX_FIELD) == 0) { + contact_name_image.beInvisible() + } + + contact_prefix.beVisibleIf(showFields and SHOW_PREFIX_FIELD != 0) + contact_first_name.beVisibleIf(showFields and SHOW_FIRST_NAME_FIELD != 0) + contact_middle_name.beVisibleIf(showFields and SHOW_MIDDLE_NAME_FIELD != 0) + contact_surname.beVisibleIf(showFields and SHOW_SURNAME_FIELD != 0) + contact_suffix.beVisibleIf(showFields and SHOW_SUFFIX_FIELD != 0) + + contact_source.beVisibleIf(showFields and SHOW_CONTACT_SOURCE_FIELD != 0) + contact_source_image.beVisibleIf(showFields and SHOW_CONTACT_SOURCE_FIELD != 0) + + val arePhoneNumbersVisible = showFields and SHOW_PHONE_NUMBERS_FIELD != 0 + contact_numbers_image.beVisibleIf(arePhoneNumbersVisible) + contact_numbers_holder.beVisibleIf(arePhoneNumbersVisible) + contact_numbers_add_new.beVisibleIf(arePhoneNumbersVisible) + + val areEmailsVisible = showFields and SHOW_EMAILS_FIELD != 0 + contact_emails_image.beVisibleIf(areEmailsVisible) + contact_emails_holder.beVisibleIf(areEmailsVisible) + contact_emails_add_new.beVisibleIf(areEmailsVisible) + + val areAddressesVisible = showFields and SHOW_ADDRESSES_FIELD != 0 + contact_addresses_image.beVisibleIf(areAddressesVisible) + contact_addresses_holder.beVisibleIf(areAddressesVisible) + contact_addresses_add_new.beVisibleIf(areAddressesVisible) + + val isOrganizationVisible = showFields and SHOW_ORGANIZATION_FIELD != 0 + contact_organization_company.beVisibleIf(isOrganizationVisible) + contact_organization_job_position.beVisibleIf(isOrganizationVisible) + contact_organization_image.beVisibleIf(isOrganizationVisible) + + val areEventsVisible = showFields and SHOW_EVENTS_FIELD != 0 + contact_events_image.beVisibleIf(areEventsVisible) + contact_events_holder.beVisibleIf(areEventsVisible) + contact_events_add_new.beVisibleIf(areEventsVisible) + + val areGroupsVisible = showFields and SHOW_GROUPS_FIELD != 0 + contact_groups_image.beVisibleIf(areGroupsVisible) + contact_groups_holder.beVisibleIf(areGroupsVisible) + contact_groups_add_new.beVisibleIf(areGroupsVisible) + + val areNotesVisible = showFields and SHOW_NOTES_FIELD != 0 + contact_notes.beVisibleIf(areNotesVisible) + contact_notes_image.beVisibleIf(areNotesVisible) + } + private fun setupEditContact() { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) supportActionBar?.title = resources.getString(R.string.edit_contact) @@ -248,6 +299,7 @@ class EditContactActivity : ContactActivity() { contact_middle_name.setText(contact!!.middleName) contact_surname.setText(contact!!.surname) contact_suffix.setText(contact!!.suffix) + contact_source.text = getPublicContactSource(contact!!.source) setupPhoneNumbers() @@ -260,82 +312,94 @@ class EditContactActivity : ContactActivity() { } private fun setupPhoneNumbers() { - contact!!.phoneNumbers.forEachIndexed { index, number -> - var numberHolder = contact_numbers_holder.getChildAt(index) - if (numberHolder == null) { - numberHolder = layoutInflater.inflate(R.layout.item_edit_phone_number, contact_numbers_holder, false) - contact_numbers_holder.addView(numberHolder) - } + if (showFields and SHOW_PHONE_NUMBERS_FIELD != 0) { + contact!!.phoneNumbers.forEachIndexed { index, number -> + var numberHolder = contact_numbers_holder.getChildAt(index) + if (numberHolder == null) { + numberHolder = layoutInflater.inflate(R.layout.item_edit_phone_number, contact_numbers_holder, false) + contact_numbers_holder.addView(numberHolder) + } - numberHolder!!.apply { - contact_number.setText(number.value) - setupPhoneNumberTypePicker(contact_number_type, number.type) + numberHolder!!.apply { + contact_number.setText(number.value) + setupPhoneNumberTypePicker(contact_number_type, number.type) + } } } } private fun setupEmails() { - contact!!.emails.forEachIndexed { index, email -> - var emailHolder = contact_emails_holder.getChildAt(index) - if (emailHolder == null) { - emailHolder = layoutInflater.inflate(R.layout.item_edit_email, contact_emails_holder, false) - contact_emails_holder.addView(emailHolder) - } + if (showFields and SHOW_EMAILS_FIELD != 0) { + contact!!.emails.forEachIndexed { index, email -> + var emailHolder = contact_emails_holder.getChildAt(index) + if (emailHolder == null) { + emailHolder = layoutInflater.inflate(R.layout.item_edit_email, contact_emails_holder, false) + contact_emails_holder.addView(emailHolder) + } - emailHolder!!.apply { - contact_email.setText(email.value) - setupEmailTypePicker(contact_email_type, email.type) + emailHolder!!.apply { + contact_email.setText(email.value) + setupEmailTypePicker(contact_email_type, email.type) + } } } } private fun setupAddresses() { - contact!!.addresses.forEachIndexed { index, address -> - var addressHolder = contact_addresses_holder.getChildAt(index) - if (addressHolder == null) { - addressHolder = layoutInflater.inflate(R.layout.item_edit_address, contact_addresses_holder, false) - contact_addresses_holder.addView(addressHolder) - } + if (showFields and SHOW_ADDRESSES_FIELD != 0) { + contact!!.addresses.forEachIndexed { index, address -> + var addressHolder = contact_addresses_holder.getChildAt(index) + if (addressHolder == null) { + addressHolder = layoutInflater.inflate(R.layout.item_edit_address, contact_addresses_holder, false) + contact_addresses_holder.addView(addressHolder) + } - addressHolder!!.apply { - contact_address.setText(address.value) - setupAddressTypePicker(contact_address_type, address.type) + addressHolder!!.apply { + contact_address.setText(address.value) + setupAddressTypePicker(contact_address_type, address.type) + } } } } private fun setupNotes() { - contact_notes.setText(contact!!.notes) + if (showFields and SHOW_NOTES_FIELD != 0) { + contact_notes.setText(contact!!.notes) + } } private fun setupOrganization() { - contact_organization_company.setText(contact!!.organization.company) - contact_organization_job_position.setText(contact!!.organization.jobPosition) + if (showFields and SHOW_ORGANIZATION_FIELD != 0) { + contact_organization_company.setText(contact!!.organization.company) + contact_organization_job_position.setText(contact!!.organization.jobPosition) + } } private fun setupEvents() { - contact!!.events.forEachIndexed { index, event -> - var eventHolder = contact_events_holder.getChildAt(index) - if (eventHolder == null) { - eventHolder = layoutInflater.inflate(R.layout.item_event, contact_events_holder, false) - contact_events_holder.addView(eventHolder) - } - - (eventHolder as ViewGroup).apply { - val contactEvent = contact_event.apply { - getDateTime(event.value, this) - tag = event.value - alpha = 1f + if (showFields and SHOW_EVENTS_FIELD != 0) { + contact!!.events.forEachIndexed { index, event -> + var eventHolder = contact_events_holder.getChildAt(index) + if (eventHolder == null) { + eventHolder = layoutInflater.inflate(R.layout.item_event, contact_events_holder, false) + contact_events_holder.addView(eventHolder) } - setupEventTypePicker(this, event.type) + (eventHolder as ViewGroup).apply { + val contactEvent = contact_event.apply { + getDateTime(event.value, this) + tag = event.value + alpha = 1f + } - contact_event_remove.apply { - beVisible() - applyColorFilter(getAdjustedPrimaryColor()) - background.applyColorFilter(config.textColor) - setOnClickListener { - resetContactEvent(contactEvent, this) + setupEventTypePicker(this, event.type) + + contact_event_remove.apply { + beVisible() + applyColorFilter(getAdjustedPrimaryColor()) + background.applyColorFilter(config.textColor) + setOnClickListener { + resetContactEvent(contactEvent, this) + } } } } @@ -343,57 +407,59 @@ class EditContactActivity : ContactActivity() { } private fun setupGroups() { - contact_groups_holder.removeAllViews() - val groups = contact!!.groups - groups.forEachIndexed { index, group -> - var groupHolder = contact_groups_holder.getChildAt(index) - if (groupHolder == null) { - groupHolder = layoutInflater.inflate(R.layout.item_edit_group, contact_groups_holder, false) - contact_groups_holder.addView(groupHolder) - } - - (groupHolder as ViewGroup).apply { - contact_group.apply { - text = group.title - setTextColor(config.textColor) - tag = group.id - alpha = 1f + if (showFields and SHOW_GROUPS_FIELD != 0) { + contact_groups_holder.removeAllViews() + val groups = contact!!.groups + groups.forEachIndexed { index, group -> + var groupHolder = contact_groups_holder.getChildAt(index) + if (groupHolder == null) { + groupHolder = layoutInflater.inflate(R.layout.item_edit_group, contact_groups_holder, false) + contact_groups_holder.addView(groupHolder) } - setOnClickListener { - showSelectGroupsDialog() - } + (groupHolder as ViewGroup).apply { + contact_group.apply { + text = group.title + setTextColor(config.textColor) + tag = group.id + alpha = 1f + } - contact_group_remove.apply { - beVisible() - applyColorFilter(getAdjustedPrimaryColor()) - background.applyColorFilter(config.textColor) setOnClickListener { - removeGroup(group.id) + showSelectGroupsDialog() + } + + contact_group_remove.apply { + beVisible() + applyColorFilter(getAdjustedPrimaryColor()) + background.applyColorFilter(config.textColor) + setOnClickListener { + removeGroup(group.id) + } } } } - } - if (groups.isEmpty()) { - layoutInflater.inflate(R.layout.item_edit_group, contact_groups_holder, false).apply { - contact_group.apply { - alpha = 0.5f - text = getString(R.string.no_groups) - setTextColor(config.textColor) - } + if (groups.isEmpty()) { + layoutInflater.inflate(R.layout.item_edit_group, contact_groups_holder, false).apply { + contact_group.apply { + alpha = 0.5f + text = getString(R.string.no_groups) + setTextColor(config.textColor) + } - contact_groups_holder.addView(this) - contact_group_remove.beGone() - setOnClickListener { - showSelectGroupsDialog() + contact_groups_holder.addView(this) + contact_group_remove.beGone() + setOnClickListener { + showSelectGroupsDialog() + } } } } } private fun setupNewContact() { - window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) + //window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) supportActionBar?.title = resources.getString(R.string.new_contact) val contactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE val organization = Organization("", "") diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt index 9877d1c7..c337c600 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt @@ -118,9 +118,9 @@ class ViewContactActivity : ContactActivity() { contact_start_call.applyColorFilter(textColor) contact_send_email.applyColorFilter(textColor) contact_name_image.applyColorFilter(textColor) - contact_number_image.applyColorFilter(textColor) - contact_email_image.applyColorFilter(textColor) - contact_event_image.applyColorFilter(textColor) + contact_numbers_image.applyColorFilter(textColor) + contact_emails_image.applyColorFilter(textColor) + contact_events_image.applyColorFilter(textColor) contact_source_image.applyColorFilter(textColor) contact_notes_image.applyColorFilter(textColor) contact_organization_image.applyColorFilter(textColor) @@ -199,10 +199,10 @@ class ViewContactActivity : ContactActivity() { } } } - contact_number_image.beVisible() + contact_numbers_image.beVisible() contact_numbers_holder.beVisible() } else { - contact_number_image.beGone() + contact_numbers_image.beGone() contact_numbers_holder.beGone() } } @@ -223,10 +223,10 @@ class ViewContactActivity : ContactActivity() { } } } - contact_email_image.beVisible() + contact_emails_image.beVisible() contact_emails_holder.beVisible() } else { - contact_email_image.beGone() + contact_emails_image.beGone() contact_emails_holder.beGone() } } @@ -247,10 +247,10 @@ class ViewContactActivity : ContactActivity() { } } } - contact_address_image.beVisible() + contact_addresses_image.beVisible() contact_addresses_holder.beVisible() } else { - contact_address_image.beGone() + contact_addresses_image.beGone() contact_addresses_holder.beGone() } } @@ -268,10 +268,10 @@ class ViewContactActivity : ContactActivity() { contact_event_remove.beGone() } } - contact_event_image.beVisible() + contact_events_image.beVisible() contact_events_holder.beVisible() } else { - contact_event_image.beGone() + contact_events_image.beGone() contact_events_holder.beGone() } } diff --git a/app/src/main/res/layout/activity_edit_contact.xml b/app/src/main/res/layout/activity_edit_contact.xml index f8bf663a..68f6ac87 100644 --- a/app/src/main/res/layout/activity_edit_contact.xml +++ b/app/src/main/res/layout/activity_edit_contact.xml @@ -96,6 +96,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/contact_photo" android:layout_centerVertical="true" + android:layout_marginBottom="@dimen/normal_margin" android:layout_toRightOf="@+id/contact_name_image" android:hint="@string/prefix" android:inputType="textCapWords" @@ -111,7 +112,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/contact_prefix" android:layout_centerVertical="true" - android:layout_marginTop="@dimen/normal_margin" + android:layout_marginBottom="@dimen/normal_margin" android:layout_toRightOf="@+id/contact_name_image" android:hint="@string/first_name" android:inputType="textCapWords" @@ -127,7 +128,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/contact_first_name" android:layout_centerVertical="true" - android:layout_marginTop="@dimen/normal_margin" + android:layout_marginBottom="@dimen/normal_margin" android:layout_toRightOf="@+id/contact_name_image" android:hint="@string/middle_name" android:inputType="textCapWords" @@ -143,7 +144,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/contact_middle_name" android:layout_centerVertical="true" - android:layout_marginTop="@dimen/normal_margin" + android:layout_marginBottom="@dimen/normal_margin" android:layout_toRightOf="@+id/contact_name_image" android:hint="@string/surname" android:inputType="textCapWords" @@ -159,7 +160,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/contact_surname" android:layout_centerVertical="true" - android:layout_marginTop="@dimen/normal_margin" + android:layout_marginBottom="@dimen/medium_margin" android:layout_toRightOf="@+id/contact_name_image" android:hint="@string/suffix" android:inputType="textCapWords" @@ -170,7 +171,7 @@ android:textSize="@dimen/bigger_text_size"/> @@ -194,21 +195,21 @@ @@ -232,7 +232,7 @@ @@ -270,7 +270,7 @@ @@ -308,7 +308,7 @@