Search in sources :

Example 16 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class DatabaseHelper method updateContactNameInSummary.

/**
 * Updates the ContactSummary table with the new/changed Contact.
 * @param writableDatabase - SQLiteDatabase writable database.
 * @param localContactId - long contact local id.
 * @param isMeProfile - boolean that indicates if the localContactId belongs to Me Profile.
 * @return The updated name, may be null in failure situations
 */
public String updateContactNameInSummary(SQLiteDatabase writableDatabase, long localContactId, boolean isMeProfile) {
    Contact contact = new Contact();
    ServiceStatus status = fetchBaseContact(localContactId, contact, writableDatabase);
    if (ServiceStatus.SUCCESS != status) {
        return null;
    }
    status = ContactDetailsTable.fetchContactDetails(localContactId, contact.details, writableDatabase);
    if (ServiceStatus.SUCCESS != status) {
        return null;
    }
    return ContactSummaryTable.updateContactDisplayName(contact, writableDatabase, isMeProfile);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact)

Example 17 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class DatabaseHelper method syncAddContactList.

/**
 * Function used by the contact sync engine to add a list of contacts to the
 * database.
 *
 * @param contactList The list of contacts received from the server
 * @param syncToServer true if the contacts need to be sent to the server
 * @param syncToNative true if the contacts need to be added to the native
 *            phonebook
 * @return SUCCESS or a suitable error code
 * @see #addContact(Contact)
 */
public ServiceStatus syncAddContactList(List<Contact> contactList, boolean syncToServer, boolean syncToNative) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.syncAddContactList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
    if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
        syncToServer = false;
    }
    if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
        syncToNative = false;
    }
    SQLiteDatabase writableDb = getWritableDatabase();
    boolean needFireDbUpdate = false;
    for (Contact contact : contactList) {
        contact.deleted = null;
        contact.localContactID = null;
        if (syncToNative) {
            contact.nativeContactId = null;
        }
        if (syncToServer) {
            contact.contactID = null;
            contact.updated = null;
            contact.synctophone = true;
        }
        try {
            writableDb.beginTransaction();
            ServiceStatus status = ContactsTable.addContact(contact, writableDb);
            if (ServiceStatus.SUCCESS != status) {
                LogUtils.logE("DatabaseHelper.syncAddContactList() Unable to add contact to contacts table, due to a database error");
                return status;
            }
            List<ContactDetail.DetailKeys> orderList = new ArrayList<ContactDetail.DetailKeys>();
            for (int i = 0; i < contact.details.size(); i++) {
                final ContactDetail detail = contact.details.get(i);
                detail.localContactID = contact.localContactID;
                detail.localDetailID = null;
                if (syncToServer) {
                    detail.unique_id = null;
                }
                if (detail.order != null && (detail.order.equals(ContactDetail.ORDER_PREFERRED))) {
                    if (orderList.contains(detail.key)) {
                        detail.order = ContactDetail.ORDER_NORMAL;
                    } else {
                        orderList.add(detail.key);
                    }
                }
                status = ContactDetailsTable.addContactDetail(detail, syncToServer, (syncToNative && contact.synctophone), writableDb);
                if (ServiceStatus.SUCCESS != status) {
                    LogUtils.logE("DatabaseHelper.syncAddContactList() Unable to add contact detail (for new contact), " + "due to a database error. Contact ID[" + contact.localContactID + "]");
                    return status;
                }
            }
            // details are not stored
            if (!contact.details.isEmpty()) {
                status = ContactSummaryTable.addContact(contact, writableDb);
                if (ServiceStatus.SUCCESS != status) {
                    return status;
                }
            }
            if (contact.groupList != null) {
                for (Long groupId : contact.groupList) {
                    if (groupId != -1 && !ContactGroupsTable.addContactToGroup(contact.localContactID, groupId, writableDb)) {
                        return ServiceStatus.ERROR_DATABASE_CORRUPT;
                    }
                }
            }
            if (contact.sources != null) {
                for (String source : contact.sources) {
                    if (!ContactSourceTable.addContactSource(contact.localContactID, source, writableDb)) {
                        return ServiceStatus.ERROR_DATABASE_CORRUPT;
                    }
                }
            }
            if (syncToServer) {
                if (contact.groupList != null) {
                    for (Long groupId : contact.groupList) {
                        if (!ContactChangeLogTable.addGroupRel(contact.localContactID, contact.contactID, groupId, writableDb)) {
                            return ServiceStatus.ERROR_DATABASE_CORRUPT;
                        }
                    }
                }
            }
            /*
                 * FIXME: Hacking a check for me profile here using syncToNative and syncToServer
                 * The me contact does not use a static local contact id 
                 * which is ridiculous. Basically we have to check the syncToNative and syncToServer
                 * flags together with isMeProfile
                 * because luckily as of yet the they are only both false when its me profile 
                 * in case that's the contact being added.
                 */
            String displayName = updateContactNameInSummary(writableDb, contact.localContactID, (!syncToNative && !syncToServer) || SyncMeDbUtils.isMeProfile(this, contact.localContactID));
            if (null == displayName) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            // updating timeline
            for (ContactDetail detail : contact.details) {
                // we already have name, don't need to get it again
                if (detail.key != ContactDetail.DetailKeys.VCARD_NAME) {
                    detail.localContactID = contact.localContactID;
                    detail.nativeContactId = contact.nativeContactId;
                    if (updateTimelineNames(detail, displayName, contact.contactID, writableDb)) {
                        needFireDbUpdate = true;
                    }
                }
            }
            writableDb.setTransactionSuccessful();
        } finally {
            writableDb.endTransaction();
        }
    }
    if (needFireDbUpdate) {
        fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, false);
    }
    return ServiceStatus.SUCCESS;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) DetailKeys(com.vodafone360.people.datatypes.ContactDetail.DetailKeys) Contact(com.vodafone360.people.datatypes.Contact)

Example 18 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class DatabaseHelper method updateTimelineNames.

/**
 * Updates the contents of the activities table when a contact detail
 * changes.
 *
 * @param cd The new or modified contact detail
 * @param contactFriendlyName Name of contact (if known)
 * @param serverId if known
 * @param db Writable SQLite database for the update
 * @return true if the Activities table was updated, false otherwise
 */
private boolean updateTimelineNames(ContactDetail cd, String contactFriendlyName, Long serverId, SQLiteDatabase db) {
    if (cd.key == ContactDetail.DetailKeys.VCARD_NAME) {
        if (contactFriendlyName != null) {
            ActivitiesTable.updateTimelineContactNameAndId(contactFriendlyName, cd.localContactID, db);
            return true;
        }
    }
    if (cd.key == ContactDetail.DetailKeys.VCARD_PHONE) {
        if (contactFriendlyName == null) {
            ContactSummary cs = new ContactSummary();
            if (ContactSummaryTable.fetchSummaryItem(cd.localContactID, cs, db) == ServiceStatus.SUCCESS) {
                contactFriendlyName = cs.formattedName;
            }
        }
        if (contactFriendlyName != null) {
            Long cId = serverId;
            if (cId == null) {
                cId = ContactsTable.fetchServerId(cd.localContactID, db);
            }
            ActivitiesTable.updateTimelineContactNameAndId(cd.getTel(), contactFriendlyName, cd.localContactID, cId, db);
            return true;
        } else {
            LogUtils.logE("updateTimelineNames() failed to fetch summary Item");
        }
    }
    return false;
}
Also used : ContactSummary(com.vodafone360.people.datatypes.ContactSummary)

Example 19 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class ContactSummaryTable method getDisplayNameDetail.

/**
 * Retrieves display name detail for a contact
 * @param contact Contact to retrieve display name from
 * @return Found display name detail - maybe be null
 */
private static ContactDetail getDisplayNameDetail(Contact contact) {
    // These two Arrays contains the order in which the details are queried.
    // First valid (not empty or unknown) detail is taken
    ContactDetail.DetailKeys[] preferredNameDetails = { ContactDetail.DetailKeys.VCARD_NAME, ContactDetail.DetailKeys.VCARD_ORG, ContactDetail.DetailKeys.VCARD_EMAIL, ContactDetail.DetailKeys.VCARD_PHONE };
    ContactDetail name = null;
    // Query the details for the name field
    for (ContactDetail.DetailKeys key : preferredNameDetails) {
        if ((name = contact.getContactDetail(key)) != null) {
            // (gmail for example)
            if (key == ContactDetail.DetailKeys.VCARD_NAME && name.getName() == null)
                continue;
            if (key != ContactDetail.DetailKeys.VCARD_NAME && TextUtils.isEmpty(name.getValue()))
                continue;
            break;
        }
    }
    return name;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) DetailKeys(com.vodafone360.people.datatypes.ContactDetail.DetailKeys) DetailKeys(com.vodafone360.people.datatypes.ContactDetail.DetailKeys)

Example 20 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.

the class ContactSummaryTable method addContact.

/**
 * Adds contact summary information to the table for a new contact. If the
 * contact has no name or no status, an alternative detail will be used such
 * as telephone number or email address.
 *
 * @param contact The new contact
 * @param writableDb Writable SQLite database
 * @return SUCCESS or a suitable error code
 */
public static ServiceStatus addContact(Contact contact, SQLiteDatabase writableDb) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        DatabaseHelper.trace(true, "ContactSummeryTable.addContact() contactID[" + contact.contactID + "]");
    }
    if (contact.localContactID == null) {
        LogUtils.logE("ContactSummeryTable.addContact() Invalid parameters");
        return ServiceStatus.ERROR_NOT_FOUND;
    }
    try {
        final ContentValues values = new ContentValues();
        values.put(Field.LOCALCONTACTID.toString(), contact.localContactID);
        values.put(Field.NATIVEID.toString(), contact.nativeContactId);
        values.put(Field.FRIENDOFMINE.toString(), contact.friendOfMine);
        values.put(Field.SYNCTOPHONE.toString(), contact.synctophone);
        ContactDetail altDetail = findAlternativeNameContactDetail(values, contact.details);
        updateAltValues(values, altDetail);
        addToPresenceMap(contact.localContactID);
        if (writableDb.insertOrThrow(TABLE_NAME, null, values) < 0) {
            LogUtils.logE("ContactSummeryTable.addContact() " + "Unable to insert new contact summary");
            return ServiceStatus.ERROR_NOT_FOUND;
        }
        return ServiceStatus.SUCCESS;
    } catch (SQLException e) {
        LogUtils.logE("ContactSummeryTable.addContact() SQLException - " + "Unable to insert new contact summary", e);
        return ServiceStatus.ERROR_DATABASE_CORRUPT;
    }
}
Also used : ContentValues(android.content.ContentValues) ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLException(android.database.SQLException)

Aggregations

ContactDetail (com.vodafone360.people.datatypes.ContactDetail)23 ServiceStatus (com.vodafone360.people.service.ServiceStatus)20 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)13 Cursor (android.database.Cursor)12 Contact (com.vodafone360.people.datatypes.Contact)12 ArrayList (java.util.ArrayList)11 Name (com.vodafone360.people.datatypes.VCardHelper.Name)9 ContentValues (android.content.ContentValues)7 Uri (android.net.Uri)7 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)7 SQLException (android.database.SQLException)6 Organisation (com.vodafone360.people.datatypes.VCardHelper.Organisation)6 QueueManager (com.vodafone360.people.service.io.QueueManager)6 Request (com.vodafone360.people.service.io.Request)6 TimelineSummaryItem (com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem)5 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)5 Hashtable (java.util.Hashtable)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 Suppress (android.test.suitebuilder.annotation.Suppress)4 Date (java.util.Date)4