mirror of
				https://github.com/SimpleMobileTools/Simple-Contacts.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	allow changing the contact source at the edit screen
This commit is contained in:
		| @@ -52,6 +52,7 @@ class EditContactActivity : ContactActivity() { | |||||||
|     private var lastPhotoIntentUri: Uri? = null |     private var lastPhotoIntentUri: Uri? = null | ||||||
|     private var isSaving = false |     private var isSaving = false | ||||||
|     private var isThirdPartyIntent = false |     private var isThirdPartyIntent = false | ||||||
|  |     private var originalContactSource = "" | ||||||
|  |  | ||||||
|     override fun onCreate(savedInstanceState: Bundle?) { |     override fun onCreate(savedInstanceState: Bundle?) { | ||||||
|         super.onCreate(savedInstanceState) |         super.onCreate(savedInstanceState) | ||||||
| @@ -212,6 +213,7 @@ class EditContactActivity : ContactActivity() { | |||||||
|         contact_events_add_new.setOnClickListener { addNewEventField() } |         contact_events_add_new.setOnClickListener { addNewEventField() } | ||||||
|         contact_websites_add_new.setOnClickListener { addNewWebsiteField() } |         contact_websites_add_new.setOnClickListener { addNewWebsiteField() } | ||||||
|         contact_groups_add_new.setOnClickListener { showSelectGroupsDialog() } |         contact_groups_add_new.setOnClickListener { showSelectGroupsDialog() } | ||||||
|  |         contact_source.setOnClickListener { showSelectContactSourceDialog() } | ||||||
|  |  | ||||||
|         setupFieldVisibility() |         setupFieldVisibility() | ||||||
|  |  | ||||||
| @@ -504,21 +506,16 @@ class EditContactActivity : ContactActivity() { | |||||||
|  |  | ||||||
|     private fun setupContactSource() { |     private fun setupContactSource() { | ||||||
|         contact_source.text = getPublicContactSource(contact!!.source) |         contact_source.text = getPublicContactSource(contact!!.source) | ||||||
|  |         originalContactSource = contact!!.source | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun setupNewContact() { |     private fun setupNewContact() { | ||||||
|         supportActionBar?.title = resources.getString(R.string.new_contact) |         supportActionBar?.title = resources.getString(R.string.new_contact) | ||||||
|         val contactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE |         originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE | ||||||
|         val organization = Organization("", "") |         val organization = Organization("", "") | ||||||
|         contact = Contact(0, "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), contactSource, 0, 0, "", null, "", |         contact = Contact(0, "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), originalContactSource, 0, 0, "", null, "", | ||||||
|                 ArrayList(), organization, ArrayList()) |                 ArrayList(), organization, ArrayList()) | ||||||
|         contact_source.text = getPublicContactSource(contact!!.source) |         contact_source.text = getPublicContactSource(contact!!.source) | ||||||
|         contact_source.setOnClickListener { |  | ||||||
|             showContactSourcePicker(contact!!.source) { |  | ||||||
|                 contact!!.source = if (it == getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it |  | ||||||
|                 contact_source.text = getPublicContactSource(it) |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun setupTypePickers() { |     private fun setupTypePickers() { | ||||||
| @@ -708,6 +705,13 @@ class EditContactActivity : ContactActivity() { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private fun showSelectContactSourceDialog() { | ||||||
|  |         showContactSourcePicker(contact!!.source) { | ||||||
|  |             contact!!.source = if (it == getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it | ||||||
|  |             contact_source.text = getPublicContactSource(it) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private fun saveContact() { |     private fun saveContact() { | ||||||
|         if (isSaving || contact == null) { |         if (isSaving || contact == null) { | ||||||
|             return |             return | ||||||
| @@ -726,7 +730,6 @@ class EditContactActivity : ContactActivity() { | |||||||
|             emails = getFilledEmails() |             emails = getFilledEmails() | ||||||
|             addresses = getFilledAddresses() |             addresses = getFilledAddresses() | ||||||
|             events = getFilledEvents() |             events = getFilledEvents() | ||||||
|             source = contact!!.source |  | ||||||
|             starred = if (isContactStarred()) 1 else 0 |             starred = if (isContactStarred()) 1 else 0 | ||||||
|             notes = contact_notes.value |             notes = contact_notes.value | ||||||
|             websites = getFilledWebsites() |             websites = getFilledWebsites() | ||||||
| @@ -737,12 +740,14 @@ class EditContactActivity : ContactActivity() { | |||||||
|  |  | ||||||
|             Thread { |             Thread { | ||||||
|                 config.lastUsedContactSource = source |                 config.lastUsedContactSource = source | ||||||
|                 if (id == 0) { |                 when { | ||||||
|                     insertNewContact() |                     id == 0 -> insertNewContact(false) | ||||||
|                 } else { |                     originalContactSource != source -> insertNewContact(true) | ||||||
|  |                     else -> { | ||||||
|                         val photoUpdateStatus = getPhotoUpdateStatus(oldPhotoUri, photoUri) |                         val photoUpdateStatus = getPhotoUpdateStatus(oldPhotoUri, photoUri) | ||||||
|                         updateContact(photoUpdateStatus) |                         updateContact(photoUpdateStatus) | ||||||
|                     } |                     } | ||||||
|  |                 } | ||||||
|             }.start() |             }.start() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -821,10 +826,17 @@ class EditContactActivity : ContactActivity() { | |||||||
|         return websites |         return websites | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun insertNewContact() { |     private fun insertNewContact(deleteCurrentContact: Boolean) { | ||||||
|         isSaving = true |         isSaving = true | ||||||
|  |         if (!deleteCurrentContact) { | ||||||
|             toast(R.string.inserting) |             toast(R.string.inserting) | ||||||
|  |         } | ||||||
|  |  | ||||||
|         if (ContactsHelper(this@EditContactActivity).insertContact(contact!!)) { |         if (ContactsHelper(this@EditContactActivity).insertContact(contact!!)) { | ||||||
|  |             if (deleteCurrentContact) { | ||||||
|  |                 contact!!.source = originalContactSource | ||||||
|  |                 ContactsHelper(this).deleteContact(contact!!) | ||||||
|  |             } | ||||||
|             finish() |             finish() | ||||||
|         } else { |         } else { | ||||||
|             toast(R.string.unknown_error_occurred) |             toast(R.string.unknown_error_occurred) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user