Minor change

Adjusted coding style and removed GROUP attribute as per comment from here:
https://github.com/SimpleMobileTools/Simple-Contacts/issues/146

previous post, it should look like CATEGORIES:Testgroup,Testgroup1. Regarding the code, check the spacing, newlines, remove comments.
This commit is contained in:
Dirkster99 2018-09-04 17:33:43 +02:00
parent b3d99e99e0
commit a153427646
2 changed files with 11 additions and 20 deletions

View File

@ -123,16 +123,13 @@ class VcfExporter {
card.addPhoto(photo) card.addPhoto(photo)
} }
// Export a list of groups where this contact is a member of if (contact.groups.size > 0) {
if (contact.groups.size > 0){
// Copy groups into a categorized list and add this category into VCard
val groupList = Categories(); val groupList = Categories();
contact.groups.forEach{ contact.groups.forEach {
groupList.addParameter("GROUP", it.title); groupList.getValues().add(it.title);
} }
card.addCategories(groupList); card.setCategories(groupList);
} }
cards.add(card) cards.add(card)

View File

@ -105,29 +105,23 @@ class VcfImporter(val activity: SimpleActivity) {
val notes = ezContact.notes.firstOrNull()?.value ?: "" val notes = ezContact.notes.firstOrNull()?.value ?: ""
val groups = ArrayList<Group>() val groups = ArrayList<Group>()
if (ezContact.categories != null){ // Iterate through categories of this contact (if any) if (ezContact.categories != null) {
val groupNames = ezContact.categories.getValues();
// Iterate through group names for this contact
// Check if group already exist and create it if not
// Associate group with this user
val groupNames = ezContact.categories.getParameters("GROUP");
if (groupNames != null){ // Resolve group references for this contact
if (groupNames != null) {
val storedGroups = ContactsHelper(activity).getStoredGroups(); val storedGroups = ContactsHelper(activity).getStoredGroups();
groupNames.forEach {
groupNames.forEach {
val groupName = it; val groupName = it;
val storedGroup = storedGroups.firstOrNull { it.title == groupName } val storedGroup = storedGroups.firstOrNull { it.title == groupName }
if (storedGroup != null){ if (storedGroup != null) {
groups.add(storedGroup); // Group is already present on this device groups.add(storedGroup);
} }
else { else {
// Group is not present on this device, yet so we create a new one
val newcontactGroup = activity.dbHelper.insertGroup(Group(0, groupName)); val newcontactGroup = activity.dbHelper.insertGroup(Group(0, groupName));
if (newcontactGroup != null) // and associate it with this contact if (newcontactGroup != null)
groups.add(newcontactGroup); groups.add(newcontactGroup);
} }
} }