From 97bd5dacefdc0f4a5f16d454ab6e832db83d4f36 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 13 Apr 2018 13:46:31 +0200 Subject: [PATCH] add websites to the Edit screen too --- .../activities/EditContactActivity.kt | 40 ++++++++++++++++-- .../main/res/layout/activity_edit_contact.xml | 42 ++++++++++++++++++- app/src/main/res/layout/item_edit_website.xml | 21 ++++++++++ 3 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/layout/item_edit_website.xml 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 6ba8d2f0..4f34e043 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -29,6 +29,7 @@ import kotlinx.android.synthetic.main.item_edit_address.view.* import kotlinx.android.synthetic.main.item_edit_email.view.* import kotlinx.android.synthetic.main.item_edit_group.view.* import kotlinx.android.synthetic.main.item_edit_phone_number.view.* +import kotlinx.android.synthetic.main.item_edit_website.view.* import kotlinx.android.synthetic.main.item_event.view.* import org.joda.time.DateTime import org.joda.time.format.DateTimeFormat @@ -179,9 +180,10 @@ class EditContactActivity : ContactActivity() { 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) + contact_websites_image.applyColorFilter(textColor) + contact_groups_image.applyColorFilter(textColor) + contact_source_image.applyColorFilter(textColor) val adjustedPrimaryColor = getAdjustedPrimaryColor() contact_numbers_add_new.applyColorFilter(adjustedPrimaryColor) @@ -192,6 +194,8 @@ class EditContactActivity : ContactActivity() { contact_addresses_add_new.background.applyColorFilter(textColor) contact_events_add_new.applyColorFilter(adjustedPrimaryColor) contact_events_add_new.background.applyColorFilter(textColor) + contact_websites_add_new.applyColorFilter(adjustedPrimaryColor) + contact_websites_add_new.background.applyColorFilter(textColor) contact_groups_add_new.applyColorFilter(adjustedPrimaryColor) contact_groups_add_new.background.applyColorFilter(textColor) @@ -204,6 +208,7 @@ class EditContactActivity : ContactActivity() { contact_emails_add_new.setOnClickListener { addNewEmailField() } contact_addresses_add_new.setOnClickListener { addNewAddressField() } contact_events_add_new.setOnClickListener { addNewEventField() } + contact_websites_add_new.setOnClickListener { addNewWebsiteField() } contact_groups_add_new.setOnClickListener { showSelectGroupsDialog() } setupFieldVisibility() @@ -285,6 +290,11 @@ class EditContactActivity : ContactActivity() { contact_events_holder.beVisibleIf(areEventsVisible) contact_events_add_new.beVisibleIf(areEventsVisible) + val areWebsitesVisible = showFields and SHOW_WEBSITES_FIELD != 0 + contact_websites_image.beVisibleIf(areWebsitesVisible) + contact_websites_holder.beVisibleIf(areWebsitesVisible) + contact_websites_add_new.beVisibleIf(areWebsitesVisible) + val areGroupsVisible = showFields and SHOW_GROUPS_FIELD != 0 contact_groups_image.beVisibleIf(areGroupsVisible) contact_groups_holder.beVisibleIf(areGroupsVisible) @@ -311,6 +321,7 @@ class EditContactActivity : ContactActivity() { setupAddresses() setupNotes() setupOrganization() + setupWebsites() setupEvents() setupGroups() } @@ -379,6 +390,20 @@ class EditContactActivity : ContactActivity() { } } + private fun setupWebsites() { + if (showFields and SHOW_WEBSITES_FIELD != 0) { + contact!!.websites.forEachIndexed { index, website -> + var websitesHolder = contact_websites_holder.getChildAt(index) + if (websitesHolder == null) { + websitesHolder = layoutInflater.inflate(R.layout.item_edit_website, contact_websites_holder, false) + contact_websites_holder.addView(websitesHolder) + } + + websitesHolder!!.contact_website.setText(website) + } + } + } + private fun setupEvents() { if (showFields and SHOW_EVENTS_FIELD != 0) { contact!!.events.forEachIndexed { index, event -> @@ -463,7 +488,6 @@ class EditContactActivity : ContactActivity() { } private fun setupNewContact() { - //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("", "") @@ -844,6 +868,16 @@ class EditContactActivity : ContactActivity() { } } + private fun addNewWebsiteField() { + val websitesHolder = layoutInflater.inflate(R.layout.item_edit_website, contact_websites_holder, false) as ViewGroup + updateTextColors(websitesHolder) + contact_websites_holder.addView(websitesHolder) + contact_websites_holder.onGlobalLayout { + websitesHolder.contact_website.requestFocus() + showKeyboard(websitesHolder.contact_website) + } + } + private fun isContactStarred() = contact_toggle_favorite.tag == 1 private fun getStarDrawable(on: Boolean) = resources.getDrawable(if (on) R.drawable.ic_star_on_big else R.drawable.ic_star_off_big) diff --git a/app/src/main/res/layout/activity_edit_contact.xml b/app/src/main/res/layout/activity_edit_contact.xml index 68f6ac87..9cfce75f 100644 --- a/app/src/main/res/layout/activity_edit_contact.xml +++ b/app/src/main/res/layout/activity_edit_contact.xml @@ -200,9 +200,9 @@ android:layout_height="wrap_content" android:layout_below="@+id/contact_numbers_holder" android:layout_centerHorizontal="true" + android:layout_marginBottom="@dimen/medium_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" @@ -386,6 +386,44 @@ android:textCursorDrawable="@null" android:textSize="@dimen/bigger_text_size"/> + + + + + + + + + + diff --git a/app/src/main/res/layout/item_edit_website.xml b/app/src/main/res/layout/item_edit_website.xml new file mode 100644 index 00000000..8eda6c0c --- /dev/null +++ b/app/src/main/res/layout/item_edit_website.xml @@ -0,0 +1,21 @@ + + + + + +