make sure only the proper fields are shown at Edit Contact screen

This commit is contained in:
tibbi 2018-04-08 17:44:23 +02:00
parent d94dbde48e
commit 510da6b140
4 changed files with 203 additions and 137 deletions

View File

@ -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,6 +312,7 @@ class EditContactActivity : ContactActivity() {
}
private fun setupPhoneNumbers() {
if (showFields and SHOW_PHONE_NUMBERS_FIELD != 0) {
contact!!.phoneNumbers.forEachIndexed { index, number ->
var numberHolder = contact_numbers_holder.getChildAt(index)
if (numberHolder == null) {
@ -273,8 +326,10 @@ class EditContactActivity : ContactActivity() {
}
}
}
}
private fun setupEmails() {
if (showFields and SHOW_EMAILS_FIELD != 0) {
contact!!.emails.forEachIndexed { index, email ->
var emailHolder = contact_emails_holder.getChildAt(index)
if (emailHolder == null) {
@ -288,8 +343,10 @@ class EditContactActivity : ContactActivity() {
}
}
}
}
private fun setupAddresses() {
if (showFields and SHOW_ADDRESSES_FIELD != 0) {
contact!!.addresses.forEachIndexed { index, address ->
var addressHolder = contact_addresses_holder.getChildAt(index)
if (addressHolder == null) {
@ -303,17 +360,23 @@ class EditContactActivity : ContactActivity() {
}
}
}
}
private fun setupNotes() {
if (showFields and SHOW_NOTES_FIELD != 0) {
contact_notes.setText(contact!!.notes)
}
}
private fun setupOrganization() {
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() {
if (showFields and SHOW_EVENTS_FIELD != 0) {
contact!!.events.forEachIndexed { index, event ->
var eventHolder = contact_events_holder.getChildAt(index)
if (eventHolder == null) {
@ -341,8 +404,10 @@ class EditContactActivity : ContactActivity() {
}
}
}
}
private fun setupGroups() {
if (showFields and SHOW_GROUPS_FIELD != 0) {
contact_groups_holder.removeAllViews()
val groups = contact!!.groups
groups.forEachIndexed { index, group ->
@ -391,9 +456,10 @@ class EditContactActivity : ContactActivity() {
}
}
}
}
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("", "")

View File

@ -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()
}
}

View File

@ -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"/>
<ImageView
android:id="@+id/contact_number_image"
android:id="@+id/contact_numbers_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_numbers_holder"
@ -185,8 +186,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_suffix"
android:layout_marginTop="@dimen/medium_margin"
android:layout_toRightOf="@+id/contact_number_image"
android:layout_marginBottom="@dimen/small_margin"
android:layout_toRightOf="@+id/contact_numbers_image"
android:orientation="vertical">
<include layout="@layout/item_edit_phone_number"/>
@ -194,21 +195,21 @@
</LinearLayout>
<ImageView
android:id="@+id/contact_number_add_new"
android:id="@+id/contact_numbers_add_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_numbers_holder"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/small_margin"
android:background="@drawable/button_background"
android:paddingBottom="@dimen/medium_margin"
android:layout_marginBottom="@dimen/medium_margin"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:src="@drawable/ic_plus"/>
<ImageView
android:id="@+id/contact_email_image"
android:id="@+id/contact_emails_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_emails_holder"
@ -222,8 +223,7 @@
android:id="@+id/contact_emails_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_number_add_new"
android:layout_marginTop="@dimen/medium_margin"
android:layout_below="@+id/contact_numbers_add_new"
android:layout_toRightOf="@+id/contact_name_image"
android:orientation="vertical">
@ -232,7 +232,7 @@
</LinearLayout>
<ImageView
android:id="@+id/contact_email_add_new"
android:id="@+id/contact_emails_add_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_emails_holder"
@ -246,7 +246,7 @@
android:src="@drawable/ic_plus"/>
<ImageView
android:id="@+id/contact_address_image"
android:id="@+id/contact_addresses_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_addresses_holder"
@ -260,7 +260,7 @@
android:id="@+id/contact_addresses_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_email_add_new"
android:layout_below="@+id/contact_emails_add_new"
android:layout_marginTop="@dimen/medium_margin"
android:layout_toRightOf="@+id/contact_name_image"
android:orientation="vertical">
@ -270,7 +270,7 @@
</LinearLayout>
<ImageView
android:id="@+id/contact_address_add_new"
android:id="@+id/contact_addresses_add_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_addresses_holder"
@ -284,7 +284,7 @@
android:src="@drawable/ic_plus"/>
<ImageView
android:id="@+id/contact_event_image"
android:id="@+id/contact_events_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_events_holder"
@ -298,7 +298,7 @@
android:id="@+id/contact_events_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_address_add_new"
android:layout_below="@+id/contact_addresses_add_new"
android:layout_marginTop="@dimen/medium_margin"
android:layout_toRightOf="@+id/contact_name_image"
android:orientation="vertical">
@ -308,7 +308,7 @@
</LinearLayout>
<ImageView
android:id="@+id/contact_event_add_new"
android:id="@+id/contact_events_add_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_events_holder"
@ -336,7 +336,7 @@
android:id="@+id/contact_notes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_event_add_new"
android:layout_below="@+id/contact_events_add_new"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/normal_margin"
android:layout_toRightOf="@+id/contact_notes_image"

View File

@ -167,7 +167,7 @@
android:textSize="@dimen/bigger_text_size"/>
<ImageView
android:id="@+id/contact_number_image"
android:id="@+id/contact_numbers_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_numbers_holder"
@ -182,12 +182,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_suffix"
android:layout_toRightOf="@+id/contact_number_image"
android:layout_toRightOf="@+id/contact_numbers_image"
android:orientation="vertical"
android:paddingLeft="@dimen/small_margin"/>
<ImageView
android:id="@+id/contact_email_image"
android:id="@+id/contact_emails_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_emails_holder"
@ -207,7 +207,7 @@
android:paddingLeft="@dimen/small_margin"/>
<ImageView
android:id="@+id/contact_address_image"
android:id="@+id/contact_addresses_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_addresses_holder"
@ -227,7 +227,7 @@
android:paddingLeft="@dimen/small_margin"/>
<ImageView
android:id="@+id/contact_event_image"
android:id="@+id/contact_events_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_events_holder"