Search in sources :

Example 86 with Contact

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

the class ChatDbUtils method fillInContactDetails.

/**
 * Remove hard code
 *
 * @param msg
 * @param item
 * @param databaseHelper
 * @param incoming
 */
private static void fillInContactDetails(ChatMessage msg, TimelineSummaryItem item, DatabaseHelper databaseHelper, TimelineSummaryItem.Type incoming) {
    item.mTimestamp = System.currentTimeMillis();
    // here we set the time stamp back into the chat message
    // in order to be able to remove it from the chat history by time stamp in case its delivery fails
    msg.setTimeStamp(item.mTimestamp);
    item.mType = ActivityItem.Type.MESSAGE_IM_CONVERSATION;
    item.mDescription = msg.getBody();
    item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
    // we store sender's localContactId for incoming msgs and recipient's
    // localContactId for outgoing msgs
    item.mLocalContactId = msg.getLocalContactId();
    if (item.mLocalContactId != null && item.mLocalContactId != -1) {
        ContactDetail cd = ContactDetailsTable.fetchDetail(item.mLocalContactId, DetailKeys.VCARD_NAME, databaseHelper.getReadableDatabase());
        if (cd == null || cd.getName() == null) {
            // if we don't get any details, we have to check the summary
            // table because gtalk contacts
            // without name will be otherwise show as unknown
            ContactSummary contactSummary = new ContactSummary();
            ServiceStatus error = ContactSummaryTable.fetchSummaryItem(item.mLocalContactId, contactSummary, databaseHelper.getReadableDatabase());
            if (error == ServiceStatus.SUCCESS) {
                item.mContactName = (contactSummary.formattedName != null) ? contactSummary.formattedName : ContactDetail.UNKNOWN_NAME;
            } else {
                item.mContactName = ContactDetail.UNKNOWN_NAME;
            }
        } else {
            /**
             * Get name from contact details. *
             */
            VCardHelper.Name name = cd.getName();
            item.mContactName = (name != null) ? name.toString() : ContactDetail.UNKNOWN_NAME;
        }
    }
    item.mIncoming = incoming;
    item.mContactNetwork = SocialNetwork.getSocialNetworkValue(msg.getNetworkId()).toString();
    item.mNativeItemType = TimelineNativeTypes.ChatLog.ordinal();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactSummary(com.vodafone360.people.datatypes.ContactSummary) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper) Date(java.util.Date)

Example 87 with Contact

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

the class DatabaseHelper method syncDeleteContactList.

/**
 * Function used by the contact sync engine to delete a list of contacts
 * from the database.
 *
 * @param contactIdList The list of contact IDs received from the server (at
 *            least localId should be set)
 * @param syncToServer true if the contacts need to be deleted from the
 *            server
 * @param syncToNative true if the contacts need to be deleted from the
 *            native phonebook
 * @return SUCCESS or a suitable error code
 * @see #deleteContact(long)
 */
public ServiceStatus syncDeleteContactList(List<ContactsTable.ContactIdInfo> contactIdList, boolean syncToServer, boolean syncToNative) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.syncDeleteContactList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
    if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
        syncToServer = false;
    }
    if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
        syncToNative = false;
    }
    SQLiteDatabase writableDb = getWritableDatabase();
    for (ContactsTable.ContactIdInfo contactIdInfo : contactIdList) {
        try {
            writableDb.beginTransaction();
            if (syncToNative && contactIdInfo.mergedLocalId == null) {
                if (!NativeChangeLogTable.addDeletedContactChange(contactIdInfo.localId, contactIdInfo.nativeId, writableDb)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (syncToServer) {
                if (!ContactChangeLogTable.addDeletedContactChange(contactIdInfo.localId, contactIdInfo.serverId, syncToServer, writableDb)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (!ContactGroupsTable.deleteContact(contactIdInfo.localId, writableDb)) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            if (SyncMeDbUtils.getMeProfileLocalContactId(this) != null && SyncMeDbUtils.getMeProfileLocalContactId(this).longValue() == contactIdInfo.localId) {
                ServiceStatus status = StateTable.modifyMeProfileID(null, writableDb);
                if (ServiceStatus.SUCCESS != status) {
                    return status;
                }
                SyncMeDbUtils.setMeProfileId(null);
                PresenceDbUtils.resetMeProfileIds();
            }
            ServiceStatus status = ContactSummaryTable.deleteContact(contactIdInfo.localId, writableDb);
            if (ServiceStatus.SUCCESS != status) {
                return status;
            }
            status = ContactDetailsTable.deleteDetailByContactId(contactIdInfo.localId, writableDb);
            if (ServiceStatus.SUCCESS != status && ServiceStatus.ERROR_NOT_FOUND != status) {
                return status;
            }
            status = ContactsTable.deleteContact(contactIdInfo.localId, writableDb);
            if (ServiceStatus.SUCCESS != status) {
                return status;
            }
            if (!deleteThumbnail(contactIdInfo.localId))
                LogUtils.logE("Not able to delete thumbnail for: " + contactIdInfo.localId);
            // timeline
            ActivitiesTable.removeTimelineContactData(contactIdInfo.localId, writableDb);
            writableDb.setTransactionSuccessful();
        } finally {
            writableDb.endTransaction();
        }
    }
    return ServiceStatus.SUCCESS;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactsTable(com.vodafone360.people.database.tables.ContactsTable) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 88 with Contact

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

the class DatabaseHelper method addContact.

/**
 * Adds a contact to the database and fires an internal database change
 * event.
 *
 * @param contact A {@link Contact} object which contains the details to be
 *            added
 * @return SUCCESS or a suitable error code
 * @see #deleteContact(long)
 * @see #addContactDetail(ContactDetail)
 * @see #modifyContactDetail(ContactDetail)
 * @see #deleteContactDetail(long)
 * @see #addContactToGroup(long, long)
 * @see #deleteContactFromGroup(long, long)
 */
public ServiceStatus addContact(Contact contact) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        trace(false, "DatabaseHelper.addContact() contactID[" + contact.contactID + "] nativeContactId[" + contact.nativeContactId + "]");
    }
    List<Contact> contactList = new ArrayList<Contact>();
    contactList.add(contact);
    ServiceStatus status = syncAddContactList(contactList, true, true);
    if (ServiceStatus.SUCCESS == status) {
        fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
    }
    return status;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact)

Example 89 with Contact

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

the class DatabaseHelper method convertNativeContactChanges.

/**
 * Converts an array of ContactChange into a Contact object.
 *
 * @see ContactChange
 * @see Contact
 * @param contactChanges the array of ContactChange to convert
 * @return the equivalent Contact
 */
private Contact convertNativeContactChanges(ContactChange[] contactChanges) {
    if (contactChanges == null || contactChanges.length <= 0)
        return null;
    final Contact contact = new Contact();
    contact.localContactID = contactChanges[0].getInternalContactId();
    // coming from native
    contact.nativeContactId = new Integer((int) contactChanges[0].getNabContactId());
    contact.synctophone = true;
    // fill the contact with all the details
    for (int i = 0; i < contactChanges.length; i++) {
        final ContactDetail detail = convertContactChange(contactChanges[i]);
        // setting it to -1 means that it does not need to be synced back to
        // native
        detail.syncNativeContactId = -1;
        contact.details.add(detail);
    }
    return contact;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 90 with Contact

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

the class DatabaseHelper method syncDeleteContactDetailList.

/**
 * Function used by the contact sync engine to delete a list of contact
 * details from the database.
 *
 * @param contactDetailList The list of details which has been deleted on
 *            the server
 * @param serverIdList A list of server IDs if known, or null
 * @param syncToServer true if the details need to be sent to the server
 * @param syncToNative true if the contacts need to be added to the native
 *            phonebook
 * @param meProfile - TRUE if the added contact is Me profile.
 * @return SUCCESS or a suitable error code
 * @see #deleteContactDetail(long)
 */
public ServiceStatus syncDeleteContactDetailList(List<ContactDetail> contactDetailList, boolean syncToServer, boolean syncToNative) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.syncDeleteContactDetailList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
    if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
        syncToServer = false;
    }
    if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
        syncToNative = false;
    }
    SQLiteDatabase db = getWritableDatabase();
    boolean needFireDbUpdate = false;
    for (ContactDetail contactDetail : contactDetailList) {
        if ((contactDetail.serverContactId == null) || (contactDetail.serverContactId == -1)) {
            ContactsTable.ContactIdInfo contactIdInfo = ContactsTable.validateContactId(contactDetail.localContactID, db);
            if (contactIdInfo == null) {
                return ServiceStatus.ERROR_NOT_FOUND;
            }
            contactDetail.nativeContactId = contactIdInfo.nativeId;
            contactDetail.serverContactId = contactIdInfo.serverId;
        }
        try {
            db.beginTransaction();
            if (syncToNative) {
                if (!NativeChangeLogTable.addDeletedContactDetailChange(contactDetail, db)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (syncToServer) {
                if (!ContactChangeLogTable.addDeletedContactDetailChange(contactDetail, syncToServer, db)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (!ContactDetailsTable.deleteDetailByDetailId(contactDetail.localDetailID, db)) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            // in order not to override the new picture before it is uploaded.
            if (contactDetail.key == ContactDetail.DetailKeys.PHOTO && TextUtils.isEmpty(contactDetail.photo_url)) {
                ContactSummaryTable.modifyPictureLoadedFlag(contactDetail.localContactID, false, db);
                deleteThumbnail(contactDetail.localContactID);
            }
            String displayName = updateContactNameInSummary(db, contactDetail.localContactID, SyncMeDbUtils.isMeProfile(this, contactDetail.localContactID));
            if (displayName == null) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            if (updateTimelineNames(contactDetail, displayName, contactDetail.localContactID, db)) {
                needFireDbUpdate = true;
            }
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    }
    if (needFireDbUpdate) {
        fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, false);
    }
    return ServiceStatus.SUCCESS;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactsTable(com.vodafone360.people.database.tables.ContactsTable)

Aggregations

Contact (com.vodafone360.people.datatypes.Contact)109 ServiceStatus (com.vodafone360.people.service.ServiceStatus)107 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)100 ArrayList (java.util.ArrayList)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)50 Suppress (android.test.suitebuilder.annotation.Suppress)39 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)34 Cursor (android.database.Cursor)31 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)22 SmallTest (android.test.suitebuilder.annotation.SmallTest)19 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)18 SQLException (android.database.SQLException)15 ContentValues (android.content.ContentValues)14 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)13 Uri (android.net.Uri)11 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)11 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)11 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)11 SQLiteException (android.database.sqlite.SQLiteException)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)9