improve contact sharing, merge all available contact source values

This commit is contained in:
tibbi
2019-09-15 22:36:02 +02:00
parent 6b26ec4199
commit e078fbf0a6
3 changed files with 13 additions and 4 deletions

View File

@ -84,8 +84,8 @@ abstract class ContactActivity : SimpleActivity() {
} }
} }
fun shareContact() { fun shareContact(contact: Contact) {
shareContacts(arrayListOf(contact!!)) shareContacts(arrayListOf(contact))
} }
fun trySendSMS() { fun trySendSMS() {

View File

@ -108,7 +108,7 @@ class EditContactActivity : ContactActivity() {
when (item.itemId) { when (item.itemId) {
R.id.save -> saveContact() R.id.save -> saveContact()
R.id.share -> shareContact() R.id.share -> shareContact(contact!!)
R.id.open_with -> openWith() R.id.open_with -> openWith()
R.id.delete -> deleteContact() R.id.delete -> deleteContact()
else -> return super.onOptionsItemSelected(item) else -> return super.onOptionsItemSelected(item)

View File

@ -34,6 +34,7 @@ class ViewContactActivity : ContactActivity() {
private var duplicateContacts = ArrayList<Contact>() private var duplicateContacts = ArrayList<Contact>()
private var contactSources = ArrayList<ContactSource>() private var contactSources = ArrayList<ContactSource>()
private var showFields = 0 private var showFields = 0
private var fullContact: Contact? = null // contact with all fields filled from duplicates
private val COMPARABLE_PHONE_NUMBER_LENGTH = 7 private val COMPARABLE_PHONE_NUMBER_LENGTH = 7
@ -85,7 +86,7 @@ class ViewContactActivity : ContactActivity() {
when (item.itemId) { when (item.itemId) {
R.id.edit -> launchEditContact(contact!!) R.id.edit -> launchEditContact(contact!!)
R.id.share -> shareContact() R.id.share -> shareContact(fullContact!!)
R.id.open_with -> openWith() R.id.open_with -> openWith()
R.id.delete -> deleteContactFromAllSources() R.id.delete -> deleteContactFromAllSources()
else -> return super.onOptionsItemSelected(item) else -> return super.onOptionsItemSelected(item)
@ -103,6 +104,7 @@ class ViewContactActivity : ContactActivity() {
val lookupKey = getLookupKeyFromUri(data) val lookupKey = getLookupKeyFromUri(data)
if (lookupKey != null) { if (lookupKey != null) {
contact = ContactsHelper(this).getContactWithLookupKey(lookupKey) contact = ContactsHelper(this).getContactWithLookupKey(lookupKey)
fullContact = contact
wasLookupKeyUsed = true wasLookupKeyUsed = true
} }
@ -119,6 +121,7 @@ class ViewContactActivity : ContactActivity() {
if (contactId != 0 && !wasLookupKeyUsed) { if (contactId != 0 && !wasLookupKeyUsed) {
contact = ContactsHelper(this).getContactWithId(contactId, intent.getBooleanExtra(IS_PRIVATE, false)) contact = ContactsHelper(this).getContactWithId(contactId, intent.getBooleanExtra(IS_PRIVATE, false))
fullContact = contact
if (contact == null) { if (contact == null) {
if (!wasEditLaunched) { if (!wasEditLaunched) {
@ -297,6 +300,7 @@ class ViewContactActivity : ContactActivity() {
}.toMutableSet() as LinkedHashSet<PhoneNumber> }.toMutableSet() as LinkedHashSet<PhoneNumber>
phoneNumbers = phoneNumbers.sortedBy { it.type }.toMutableSet() as LinkedHashSet<PhoneNumber> phoneNumbers = phoneNumbers.sortedBy { it.type }.toMutableSet() as LinkedHashSet<PhoneNumber>
fullContact!!.phoneNumbers = phoneNumbers.toMutableList() as ArrayList<PhoneNumber>
if (phoneNumbers.isNotEmpty()) { if (phoneNumbers.isNotEmpty()) {
phoneNumbers.forEach { phoneNumbers.forEach {
layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply { layoutInflater.inflate(R.layout.item_view_phone_number, contact_numbers_holder, false).apply {
@ -364,6 +368,7 @@ class ViewContactActivity : ContactActivity() {
} }
addresses = addresses.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Address> addresses = addresses.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Address>
fullContact!!.addresses = addresses.toMutableList() as ArrayList<Address>
if (addresses.isNotEmpty()) { if (addresses.isNotEmpty()) {
addresses.forEach { addresses.forEach {
layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply { layoutInflater.inflate(R.layout.item_view_address, contact_addresses_holder, false).apply {
@ -399,6 +404,7 @@ class ViewContactActivity : ContactActivity() {
} }
IMs = IMs.sortedBy { it.type }.toMutableSet() as LinkedHashSet<IM> IMs = IMs.sortedBy { it.type }.toMutableSet() as LinkedHashSet<IM>
fullContact!!.IMs = IMs.toMutableList() as ArrayList<IM>
if (IMs.isNotEmpty()) { if (IMs.isNotEmpty()) {
IMs.forEach { IMs.forEach {
layoutInflater.inflate(R.layout.item_view_im, contact_ims_holder, false).apply { layoutInflater.inflate(R.layout.item_view_im, contact_ims_holder, false).apply {
@ -430,6 +436,7 @@ class ViewContactActivity : ContactActivity() {
} }
events = events.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Event> events = events.sortedBy { it.type }.toMutableSet() as LinkedHashSet<Event>
fullContact!!.events = events.toMutableList() as ArrayList<Event>
if (events.isNotEmpty()) { if (events.isNotEmpty()) {
events.forEach { events.forEach {
layoutInflater.inflate(R.layout.item_view_event, contact_events_holder, false).apply { layoutInflater.inflate(R.layout.item_view_event, contact_events_holder, false).apply {
@ -494,6 +501,7 @@ class ViewContactActivity : ContactActivity() {
} }
websites = websites.sorted().toMutableSet() as LinkedHashSet<String> websites = websites.sorted().toMutableSet() as LinkedHashSet<String>
fullContact!!.websites = websites.toMutableList() as ArrayList<String>
if (websites.isNotEmpty()) { if (websites.isNotEmpty()) {
websites.forEach { websites.forEach {
val url = it val url = it
@ -528,6 +536,7 @@ class ViewContactActivity : ContactActivity() {
} }
groups = groups.sortedBy { it.title }.toMutableSet() as LinkedHashSet<Group> groups = groups.sortedBy { it.title }.toMutableSet() as LinkedHashSet<Group>
fullContact!!.groups = groups.toMutableList() as ArrayList<Group>
if (groups.isNotEmpty()) { if (groups.isNotEmpty()) {
groups.forEach { groups.forEach {
layoutInflater.inflate(R.layout.item_view_group, contact_groups_holder, false).apply { layoutInflater.inflate(R.layout.item_view_group, contact_groups_holder, false).apply {