Search in sources :

Example 26 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeContactsApi2 method putName.

/**
     * Put Name detail into the values
     * 
     * @param cc {@link ContactChange} to read values from
     */
private void putName(ContactChange cc) {
    final Name name = VCardHelper.getName(cc.getValue());
    if (name == null) {
        // Nothing to do
        return;
    }
    mValues.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
    mValues.put(StructuredName.GIVEN_NAME, name.firstname);
    mValues.put(StructuredName.FAMILY_NAME, name.surname);
    mValues.put(StructuredName.PREFIX, name.title);
    mValues.put(StructuredName.MIDDLE_NAME, name.midname);
    mValues.put(StructuredName.SUFFIX, name.suffixes);
}
Also used : StructuredName(android.provider.ContactsContract.CommonDataKinds.StructuredName) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Example 27 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeContactsApi1 method getContact.

/**
     * @see NativeContactsApi#getContact(long)
     */
@Override
public ContactChange[] getContact(long nabContactId) {
    final List<ContactChange> ccList = new ArrayList<ContactChange>();
    final Cursor cursor = mCr.query(ContentUris.withAppendedId(People.CONTENT_URI, nabContactId), PEOPLE_PROJECTION, null, null, null);
    try {
        if (cursor.moveToNext()) {
            final String displayName = CursorUtils.getString(cursor, People.NAME);
            if (!TextUtils.isEmpty(displayName)) {
                // TODO: Remove if really not necessary
                // final Name name = parseRawName(displayName);
                final Name name = new Name();
                name.firstname = displayName;
                final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_NAME, VCardHelper.makeName(name), ContactChange.FLAG_NONE);
                cc.setNabContactId(nabContactId);
                ccList.add(cc);
            }
            // Note
            final String note = CursorUtils.getString(cursor, People.NOTES);
            if (!TextUtils.isEmpty(note)) {
                final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_NOTE, note, ContactChange.FLAG_NONE);
                cc.setNabContactId(nabContactId);
                ccList.add(cc);
            }
            // Remaining contact details
            readContactPhoneNumbers(ccList, nabContactId);
            readContactMethods(ccList, nabContactId);
            readContactOrganizations(ccList, nabContactId);
        }
    } finally {
        CursorUtils.closeCursor(cursor);
    }
    return ccList.toArray(new ContactChange[ccList.size()]);
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Example 28 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeChangeLogTable method getDeletedDetails.

/**
     * Gets the list of deleted details as a ContactChange array.
     * 
     * Note: the ContactChange object will have the type ContactChange.TYPE_DELETE_DETAIL
     * 
     * @see ContactChange
     * 
     * @param localContactId the local contact id to query
     * @param readableDb the db to query from
     * @return an array of ContactChange, null if no details where found
     */
public static ContactChange[] getDeletedDetails(long localContactId, SQLiteDatabase readableDb) {
    final String[] SELECTION = { String.valueOf(localContactId), Integer.toString(ContactChangeType.DELETE_DETAIL.ordinal()) };
    Cursor cursor = null;
    try {
        cursor = readableDb.rawQuery(QUERY_DELETED_DETAILS, SELECTION);
        if (cursor.getCount() > 0) {
            final ContactChange[] deletedDetails = new ContactChange[cursor.getCount()];
            int index = 0;
            while (cursor.moveToNext()) {
                // fill the ContactChange class with contact detail data
                final ContactChange change = new ContactChange();
                deletedDetails[index++] = change;
                // set the ContactChange as a deleted contact detail
                change.setType(ContactChange.TYPE_DELETE_DETAIL);
                // LocalContactId=1
                change.setInternalContactId(cursor.isNull(1) ? ContactChange.INVALID_ID : cursor.getLong(1));
                // NativeContactId=2
                change.setNabContactId(cursor.isNull(2) ? ContactChange.INVALID_ID : cursor.getLong(2));
                // DetailLocalId=3
                change.setInternalDetailId(cursor.isNull(3) ? ContactChange.INVALID_ID : cursor.getInt(3));
                // NativeDetailId=4
                change.setNabDetailId(cursor.isNull(4) ? ContactChange.INVALID_ID : cursor.getLong(4));
                // DetailKey=5
                change.setKey(cursor.isNull(5) ? ContactChange.KEY_UNKNOWN : ContactDetailsTable.mapInternalKeyToContactChangeKey(cursor.getInt(5)));
                if (change.getNabContactId() == ContactChange.INVALID_ID) {
                    LogUtils.logE("NativeChangeLogTable.getDeletedDetails(): the native contact id shall not be null! cc.internalContactId=" + change.getInternalContactId() + ", cc.key=" + change.getKey());
                }
            }
            return deletedDetails;
        }
    } catch (Exception e) {
        if (Settings.ENABLED_DATABASE_TRACE) {
            DatabaseHelper.trace(false, "NativeChangeLogTable.getDeletedContactsNativeIds(): " + e);
        }
    } finally {
        CloseUtils.close(cursor);
        cursor = null;
    }
    return null;
}
Also used : Cursor(android.database.Cursor) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange) SQLException(android.database.SQLException) SQLiteException(android.database.sqlite.SQLiteException)

Example 29 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeExporterTest method getNewDetails.

/**
     * Gets an array of ContatChange new details  for the provided Contact
     * @param pcam the PeopleContactsApiMockup instance
     * @param nativeContactId the contact native id
     * @return an array for ContatChange updates
     */
private ContactChange[] getNewDetails(PeopleContactsApiMockup pcam, long nativeContactId) {
    final ContactChange[] contact = pcam.getContact(nativeContactId);
    final long localContactId = contact[0].getInternalContactId();
    final ContactChange[] addedDetails = new ContactChange[2];
    int index = 0;
    // add extra details
    addedDetails[index] = new ContactChange(ContactChange.KEY_VCARD_EMAIL, "xxxxx@xxxxx.xx", ContactChange.FLAG_WORK);
    addedDetails[index].setNabContactId(nativeContactId);
    addedDetails[index].setInternalContactId(localContactId);
    addedDetails[index].setType(ContactChange.TYPE_ADD_DETAIL);
    index++;
    addedDetails[index] = new ContactChange(ContactChange.KEY_VCARD_PHONE, "+9912345678", ContactChange.FLAG_WORK);
    addedDetails[index].setNabContactId(nativeContactId);
    addedDetails[index].setInternalContactId(localContactId);
    addedDetails[index].setType(ContactChange.TYPE_ADD_DETAIL);
    index++;
    return addedDetails;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 30 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class NativeImporterTest method copyContactChange.

/**
     * Copies a ContactChange.
     * 
     * @param change the change to copy
     * @return a deep copy of the ContactChange 
     */
public static ContactChange copyContactChange(ContactChange change) {
    final ContactChange copy = new ContactChange(change.getKey(), change.getValue(), change.getFlags());
    copy.setBackendContactId(change.getBackendContactId());
    copy.setBackendDetailId(change.getBackendDetailId());
    copy.setInternalContactId(change.getInternalContactId());
    copy.setInternalDetailId(change.getInternalDetailId());
    copy.setNabContactId(change.getNabContactId());
    copy.setNabDetailId(change.getNabDetailId());
    copy.setType(change.getType());
    return copy;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Aggregations

ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)33 Name (com.vodafone360.people.datatypes.VCardHelper.Name)6 Organisation (com.vodafone360.people.datatypes.VCardHelper.Organisation)6 PeopleContactsApi (com.vodafone360.people.engine.contactsync.PeopleContactsApi)6 Cursor (android.database.Cursor)5 Suppress (android.test.suitebuilder.annotation.Suppress)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 ArrayList (java.util.ArrayList)5 SQLException (android.database.SQLException)4 SQLiteException (android.database.sqlite.SQLiteException)4 Uri (android.net.Uri)4 PostalAddress (com.vodafone360.people.datatypes.VCardHelper.PostalAddress)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 Contact (com.vodafone360.people.datatypes.Contact)3 ContentValues (android.content.ContentValues)2 StructuredName (android.provider.ContactsContract.CommonDataKinds.StructuredName)2 MediumTest (android.test.suitebuilder.annotation.MediumTest)2 SmallTest (android.test.suitebuilder.annotation.SmallTest)2 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)2 NativeContactsApi (com.vodafone360.people.engine.contactsync.NativeContactsApi)2