fix #182, ignore hidden fields during editing instead of removing them

This commit is contained in:
tibbi
2018-06-19 15:39:26 +02:00
parent 15316f0103
commit 824a8d18f0
3 changed files with 93 additions and 109 deletions

View File

@ -35,7 +35,6 @@ import java.util.*
abstract class ContactActivity : SimpleActivity() { abstract class ContactActivity : SimpleActivity() {
protected var contact: Contact? = null protected var contact: Contact? = null
protected 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

@ -58,7 +58,6 @@ 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
@ -272,6 +271,7 @@ class EditContactActivity : ContactActivity() {
} }
private fun setupFieldVisibility() { private fun setupFieldVisibility() {
val showFields = config.showContactFields
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) { 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_name_image.beInvisible()
} }
@ -352,7 +352,6 @@ class EditContactActivity : ContactActivity() {
} }
private fun setupPhoneNumbers() { private fun setupPhoneNumbers() {
if (showFields and SHOW_PHONE_NUMBERS_FIELD != 0) {
contact!!.phoneNumbers.forEachIndexed { index, number -> contact!!.phoneNumbers.forEachIndexed { index, number ->
var numberHolder = contact_numbers_holder.getChildAt(index) var numberHolder = contact_numbers_holder.getChildAt(index)
if (numberHolder == null) { if (numberHolder == null) {
@ -366,10 +365,8 @@ class EditContactActivity : ContactActivity() {
} }
} }
} }
}
private fun setupEmails() { private fun setupEmails() {
if (showFields and SHOW_EMAILS_FIELD != 0) {
contact!!.emails.forEachIndexed { index, email -> contact!!.emails.forEachIndexed { index, email ->
var emailHolder = contact_emails_holder.getChildAt(index) var emailHolder = contact_emails_holder.getChildAt(index)
if (emailHolder == null) { if (emailHolder == null) {
@ -383,10 +380,8 @@ class EditContactActivity : ContactActivity() {
} }
} }
} }
}
private fun setupAddresses() { private fun setupAddresses() {
if (showFields and SHOW_ADDRESSES_FIELD != 0) {
contact!!.addresses.forEachIndexed { index, address -> contact!!.addresses.forEachIndexed { index, address ->
var addressHolder = contact_addresses_holder.getChildAt(index) var addressHolder = contact_addresses_holder.getChildAt(index)
if (addressHolder == null) { if (addressHolder == null) {
@ -400,23 +395,17 @@ class EditContactActivity : ContactActivity() {
} }
} }
} }
}
private fun setupNotes() { private fun setupNotes() {
if (showFields and SHOW_NOTES_FIELD != 0) {
contact_notes.setText(contact!!.notes) contact_notes.setText(contact!!.notes)
} }
}
private fun setupOrganization() { private fun setupOrganization() {
if (showFields and SHOW_ORGANIZATION_FIELD != 0) {
contact_organization_company.setText(contact!!.organization.company) contact_organization_company.setText(contact!!.organization.company)
contact_organization_job_position.setText(contact!!.organization.jobPosition) contact_organization_job_position.setText(contact!!.organization.jobPosition)
} }
}
private fun setupWebsites() { private fun setupWebsites() {
if (showFields and SHOW_WEBSITES_FIELD != 0) {
contact!!.websites.forEachIndexed { index, website -> contact!!.websites.forEachIndexed { index, website ->
var websitesHolder = contact_websites_holder.getChildAt(index) var websitesHolder = contact_websites_holder.getChildAt(index)
if (websitesHolder == null) { if (websitesHolder == null) {
@ -427,10 +416,8 @@ class EditContactActivity : ContactActivity() {
websitesHolder!!.contact_website.setText(website) websitesHolder!!.contact_website.setText(website)
} }
} }
}
private fun setupEvents() { private fun setupEvents() {
if (showFields and SHOW_EVENTS_FIELD != 0) {
contact!!.events.forEachIndexed { index, event -> contact!!.events.forEachIndexed { index, event ->
var eventHolder = contact_events_holder.getChildAt(index) var eventHolder = contact_events_holder.getChildAt(index)
if (eventHolder == null) { if (eventHolder == null) {
@ -458,10 +445,8 @@ class EditContactActivity : ContactActivity() {
} }
} }
} }
}
private fun setupGroups() { private fun setupGroups() {
if (showFields and SHOW_GROUPS_FIELD != 0) {
contact_groups_holder.removeAllViews() contact_groups_holder.removeAllViews()
val groups = contact!!.groups val groups = contact!!.groups
groups.forEachIndexed { index, group -> groups.forEachIndexed { index, group ->
@ -510,7 +495,6 @@ class EditContactActivity : ContactActivity() {
} }
} }
} }
}
private fun setupContactSource() { private fun setupContactSource() {
contact_source.text = getPublicContactSource(contact!!.source) contact_source.text = getPublicContactSource(contact!!.source)

View File

@ -23,6 +23,7 @@ import kotlinx.android.synthetic.main.item_website.view.*
class ViewContactActivity : ContactActivity() { class ViewContactActivity : ContactActivity() {
private var isViewIntent = false private var isViewIntent = false
private var showFields = 0
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)