mirror of
https://github.com/etesync/android
synced 2025-05-23 17:28:51 +00:00
Import: improve group import and fix a potential crash
Fixes a potential crash when e.g. importing a file with a group that has members that don't actually exist (e.g. importing a partial vcf). This change also fixes importing files that have the groups show up before their members.
This commit is contained in:
parent
1878b45168
commit
b13be67820
@ -246,7 +246,6 @@ class ImportFragment : DialogFragment() {
|
|||||||
entryProcessed()
|
entryProcessed()
|
||||||
}
|
}
|
||||||
} else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
|
} else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
|
||||||
// FIXME: assumes groups only show after their members
|
|
||||||
val oldUidToNewId = HashMap<String?, Long>()
|
val oldUidToNewId = HashMap<String?, Long>()
|
||||||
val downloader = ContactsSyncManager.ResourceDownloader(context!!)
|
val downloader = ContactsSyncManager.ResourceDownloader(context!!)
|
||||||
val contacts = Contact.fromReader(importReader, downloader)
|
val contacts = Contact.fromReader(importReader, downloader)
|
||||||
@ -264,15 +263,8 @@ class ImportFragment : DialogFragment() {
|
|||||||
val provider = context!!.contentResolver.acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI)
|
val provider = context!!.contentResolver.acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI)
|
||||||
val localAddressBook = LocalAddressBook.findByUid(context!!, provider!!, account, info.uid!!)
|
val localAddressBook = LocalAddressBook.findByUid(context!!, provider!!, account, info.uid!!)
|
||||||
|
|
||||||
for (contact in contacts) {
|
for (contact in contacts.filter { contact -> !contact.group }) {
|
||||||
try {
|
try {
|
||||||
if (contact.group) {
|
|
||||||
val localGroup = LocalGroup(localAddressBook!!, contact, null, null)
|
|
||||||
val memberIds = contact.members.map { memberUid ->
|
|
||||||
oldUidToNewId[memberUid]!!
|
|
||||||
}
|
|
||||||
localGroup.createAsDirty(memberIds)
|
|
||||||
} else {
|
|
||||||
val localContact = LocalContact(localAddressBook!!, contact, null, null)
|
val localContact = LocalContact(localAddressBook!!, contact, null, null)
|
||||||
localContact.createAsDirty()
|
localContact.createAsDirty()
|
||||||
// If uid is null, so be it. We won't be able to process the group later.
|
// If uid is null, so be it. We won't be able to process the group later.
|
||||||
@ -284,7 +276,6 @@ class ImportFragment : DialogFragment() {
|
|||||||
localContact.addToGroup(batch, localAddressBook.findOrCreateGroup(category))
|
localContact.addToGroup(batch, localAddressBook.findOrCreateGroup(category))
|
||||||
}
|
}
|
||||||
batch.commit()
|
batch.commit()
|
||||||
}
|
|
||||||
|
|
||||||
result.added++
|
result.added++
|
||||||
} catch (e: ContactsStorageException) {
|
} catch (e: ContactsStorageException) {
|
||||||
@ -293,6 +284,23 @@ class ImportFragment : DialogFragment() {
|
|||||||
|
|
||||||
entryProcessed()
|
entryProcessed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (contact in contacts.filter { contact -> contact.group }) {
|
||||||
|
try {
|
||||||
|
val localGroup = LocalGroup(localAddressBook!!, contact, null, null)
|
||||||
|
val memberIds = contact.members.mapNotNull { memberUid ->
|
||||||
|
oldUidToNewId[memberUid]
|
||||||
|
}
|
||||||
|
localGroup.createAsDirty(memberIds)
|
||||||
|
|
||||||
|
result.added++
|
||||||
|
} catch (e: ContactsStorageException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
|
||||||
|
entryProcessed()
|
||||||
|
}
|
||||||
|
|
||||||
provider.release()
|
provider.release()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user