Search in sources :

Example 51 with Name

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

the class NowPlusActivitiesTableTest method testUpdateTimelineContactNameAndId3.

/**
 * this method checks the updated contacts are present in the database
 */
@Suppress
public void testUpdateTimelineContactNameAndId3() {
    Log.i(LOG_TAG, "***** testUpdateTimelineContactNameAndId3: create table *****");
    SQLiteDatabase writableDataBase = mTestDatabase.getWritableDatabase();
    ActivitiesTable.create(writableDataBase);
    Log.i(LOG_TAG, "***** testUpdateTimelineContactNameAndId3 , not call log though *****");
    ArrayList<TimelineSummaryItem> timeLines = TestModule.generateFakeTimeLinesList();
    ActivitiesTable.addTimelineEvents(timeLines, false, writableDataBase);
    // check if the records are there
    SQLiteDatabase readableDataBase = mTestDatabase.getReadableDatabase();
    Cursor c = ActivitiesTable.fetchTimelineEventList(YESTERDAY_TIME_MILLIS, new TimelineNativeTypes[] { TimelineNativeTypes.SmsLog, TimelineNativeTypes.MmsLog }, readableDataBase);
    ArrayList<TimelineSummaryItem> actualDBTimeLines = new ArrayList<TimelineSummaryItem>();
    for (int i = 0; i < timeLines.size(); i++) {
        if (c.moveToPosition(i)) {
            actualDBTimeLines.add(ActivitiesTable.getTimelineData(c));
        }
    }
    compareTimeLineIds(timeLines, actualDBTimeLines);
    final String NAME = "New";
    for (TimelineSummaryItem timeLineSummary : timeLines) {
        timeLineSummary.mContactName += NAME;
        ActivitiesTable.updateTimelineContactNameAndId(timeLineSummary.mContactName, timeLineSummary.mLocalContactId, writableDataBase);
    }
    c.requery();
    actualDBTimeLines.clear();
    for (int i = 0; i < timeLines.size(); i++) {
        if (c.moveToPosition(i)) {
            actualDBTimeLines.add(ActivitiesTable.getTimelineData(c));
        }
    }
    compareTimeLineIds(timeLines, actualDBTimeLines);
    Log.i(LOG_TAG, "***** testUpdateTimelineContactNameAndId3 SUCCEEDED *****");
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) TimelineSummaryItem(com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem) Cursor(android.database.Cursor) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 52 with Name

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

the class NowPlusContactSummaryTest method getDisplayName.

/**
 * Simplified logic in comparison to the real code in ContactSummaryTable.getDisplayNameDetail
 * and updateDisplayName which should behave the same way.
 * @param contact The contact to search
 * @param isMe Is the contact the me contact
 * @return The retrieved displayName
 */
private static String getDisplayName(Contact contact, boolean isMe) {
    ContactDetail name = null;
    name = contact.getContactDetail(ContactDetail.DetailKeys.VCARD_NAME);
    if (name != null && name.getName() != null) {
        return name.getName().toString();
    }
    if (isMe) {
        return SyncMeDbUtils.ME_PROFILE_DEFAULT_NAME;
    }
    name = contact.getContactDetail(ContactDetail.DetailKeys.VCARD_ORG);
    if (name != null && !TextUtils.isEmpty(name.getValue())) {
        return name.getValue();
    }
    name = contact.getContactDetail(ContactDetail.DetailKeys.VCARD_EMAIL);
    if (name != null && !TextUtils.isEmpty(name.getValue())) {
        return name.getValue();
    }
    name = contact.getContactDetail(ContactDetail.DetailKeys.VCARD_PHONE);
    if (name != null && !TextUtils.isEmpty(name.getValue())) {
        return name.getValue();
    }
    return ContactDetail.UNKNOWN_NAME;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail)

Example 53 with Name

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

the class NowPlusContactsTest method isContactDetailInSummary.

/**
 * Check if contact detail was added to ContactSummary.
 * If contact detail is a name check if it's name in formatted state
 * is the same as contact summary formatted name.
 * @param cd ContactDetail
 * @return boolean true if ContactDetail is in ContactSummaryTable
 */
private boolean isContactDetailInSummary(ContactDetail cd) {
    // boolean result = true;
    ContactSummary cs = new ContactSummary();
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    ServiceStatus status = ContactSummaryTable.fetchSummaryItem(cd.localContactID, cs, db);
    if (status != ServiceStatus.SUCCESS) {
        return false;
    } else if (ContactDetail.DetailKeys.VCARD_NAME == cd.key && !cd.getName().toString().equals(cs.formattedName)) {
        // if ContactDetail name is different then ContactSummary name
        return false;
    } else {
        return true;
    }
}
Also used : ContactSummary(com.vodafone360.people.datatypes.ContactSummary) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 54 with Name

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

the class UploadServerContacts method processNewContactsResp.

/**
 * Called when a server response is received during a new contact sync. The
 * server ID, user ID and contact detail unique IDs are extracted from the
 * response and the NowPlus database updated. Possibly server errors are
 * also handled.
 *
 * @param resp Response from server.
 */
private void processNewContactsResp(final DecodedResponse resp) {
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactChanges contactChanges = (ContactChanges) resp.mDataTypes.get(0);
        ListIterator<Contact> itContactSrc = contactChanges.mContacts.listIterator();
        ListIterator<Contact> itContactDest = mContactChangeList.listIterator();
        List<ServerIdInfo> contactServerIdList = new ArrayList<ServerIdInfo>();
        List<ServerIdInfo> detailServerIdList = new ArrayList<ServerIdInfo>();
        while (itContactSrc.hasNext()) {
            if (!itContactDest.hasNext()) {
                /**
                 * The response should contain the same number of contacts
                 * as was supplied but must handle the error.
                 */
                status = ServiceStatus.ERROR_COMMS_BAD_RESPONSE;
                break;
            }
            Contact contactSrc = itContactSrc.next();
            Contact contactDest = itContactDest.next();
            if (Settings.ENABLED_CONTACTS_SYNC_TRACE) {
                String name = null;
                String sns = null;
                for (ContactDetail detail : contactDest.details) {
                    if (detail.key == ContactDetail.DetailKeys.VCARD_NAME) {
                        if (detail.value != null) {
                            VCardHelper.Name nameObj = detail.getName();
                            if (nameObj != null) {
                                name = nameObj.toString();
                            }
                        }
                    }
                    if (detail.key == ContactDetail.DetailKeys.VCARD_INTERNET_ADDRESS) {
                        sns = detail.alt;
                    }
                }
                LogUtils.logV("UploadServerContacts." + "processNewContactsResp() Contact uploaded: SID" + " = " + contactSrc.contactID + ", name = " + name + ", sns = " + sns + ", no of details = " + contactDest.details.size() + ", deleted=" + contactSrc.deleted);
            }
            if (contactSrc.contactID != null && contactSrc.contactID.longValue() != -1L) {
                if (contactDest.contactID == null || !contactDest.contactID.equals(contactSrc.contactID)) {
                    ServerIdInfo info = new ServerIdInfo();
                    info.localId = contactDest.localContactID;
                    info.serverId = contactSrc.contactID;
                    info.userId = contactSrc.userID;
                    contactServerIdList.add(info);
                }
            } else {
                LogUtils.logE("UploadServerContacts." + "processNewContactsResp() The server failed to " + "add the following contact: " + contactDest.localContactID + ", server ID = " + contactDest.contactID);
                mFailureList += "Failed to add contact: " + contactDest.localContactID + "\n";
                for (ContactDetail d : contactDest.details) {
                    LogUtils.logV("Failed Contact Info: " + contactDest.localContactID + ", Detail: " + d.key + ", " + d.keyType + " = " + d.value);
                }
            }
            status = handleUploadDetailChanges(contactSrc, contactDest, detailServerIdList);
        }
        if (status != ServiceStatus.SUCCESS) {
            /**
             * Something is going wrong - cancel the update *
             */
            complete(status);
            return;
        }
        long startTime = System.nanoTime();
        List<ContactIdInfo> dupList = new ArrayList<ContactIdInfo>();
        status = ContactsTable.syncSetServerIds(contactServerIdList, dupList, mDb.getWritableDatabase());
        if (status != ServiceStatus.SUCCESS) {
            complete(status);
            return;
        }
        status = ContactDetailsTable.syncSetServerIds(detailServerIdList, mDb.getWritableDatabase());
        if (status != ServiceStatus.SUCCESS) {
            complete(status);
            return;
        }
        if (dupList.size() > 0) {
            LogUtils.logV("UploadServerContacts.processNewContactsResp() Found " + dupList.size() + " duplicate contacts. Trying to remove them...");
            if (VersionUtils.is2XPlatform()) {
                // This is a very important distinction for 2.X devices!
                // the NAB IDs from the contacts we first import are stripped away
                // So we won't have the correct ID if syncMergeContactList() is executed
                // This is critical because a chain reaction will cause a Contact Delete in the end
                // Instead we can syncDeleteContactList() which should be safe on 2.X!
                status = mDb.syncDeleteContactList(dupList, false, true);
            } else {
                status = mDb.syncMergeContactList(dupList);
            }
            if (status != ServiceStatus.SUCCESS) {
                complete(status);
                return;
            }
            markDbChanged();
        }
        mDbSyncTime += (System.nanoTime() - startTime);
        while (itContactDest.hasNext()) {
            Contact contactDest = itContactDest.next();
            LogUtils.logE("UploadServerContacts.processNewContactsResp() " + "The server failed to add the following contact (not " + "included in returned list): " + contactDest.localContactID);
            mFailureList += "Failed to add contact (missing from return " + "list): " + contactDest.localContactID + "\n";
        }
        updateProgress();
        sendNextContactAdditionsPage();
        return;
    }
    complete(status);
}
Also used : ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) ArrayList(java.util.ArrayList) ServerIdInfo(com.vodafone360.people.database.DatabaseHelper.ServerIdInfo) ContactChanges(com.vodafone360.people.datatypes.ContactChanges) Contact(com.vodafone360.people.datatypes.Contact) ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper)

Example 55 with Name

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

the class UpdateNativeContactsTest method feedOneSyncableContact.

/**
 * Feeds the People database with a contact containing all the possible details
 * that can be synced on native side.
 *
 * @return the created Contact
 */
private Contact feedOneSyncableContact() {
    final Contact contact = new Contact();
    // set it syncable to native side
    contact.synctophone = true;
    contact.aboutMe = "xxx xxyyyy";
    contact.friendOfMine = false;
    contact.gender = 1;
    // add a VCARD_NAME
    ContactDetail detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_NAME;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    Name name = new Name();
    name.firstname = "Firstname";
    name.midname = "Midname";
    name.surname = "Surname";
    name.suffixes = "Suffixes";
    name.title = "Title";
    // a VCARD_NAME
    detail.value = VCardHelper.makeName(name);
    contact.details.add(detail);
    // add a VCARD_NICKNAME
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_NICKNAME;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "My Nickname";
    contact.details.add(detail);
    // add a birthday VCARD_DATE + BIRTHDAY type
    detail = new ContactDetail();
    detail.order = ContactDetail.ORDER_NORMAL;
    Time time = new Time();
    time.set(1, 1, 2010);
    detail.setDate(time, ContactDetail.DetailKeyTypes.BIRTHDAY);
    contact.details.add(detail);
    // add emails (Work, Home, Other)
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "email@home.test";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail.keyType = ContactDetail.DetailKeyTypes.WORK;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "email@work.test";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "email@other.test";
    contact.details.add(detail);
    // add phones VCARD_PHONE (Home, Cell, Work, Fax, Other)
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33111111";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.CELL;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33222222";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.WORK;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33333333";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.FAX;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33444444";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33555555";
    contact.details.add(detail);
    // add a preferred detail since all the others are set to normal
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_PREFERRED;
    detail.value = "+33666666";
    contact.details.add(detail);
    // add VCARD_ADDRESS (Home, Work, Other)
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_NORMAL;
    PostalAddress address = new PostalAddress();
    address.addressLine1 = "home address line 1";
    address.addressLine2 = "home address line 2";
    address.city = "home city";
    address.country = "home country";
    address.county = "home county";
    address.postCode = "home postcode";
    address.postOfficeBox = "home po box";
    detail.value = VCardHelper.makePostalAddress(address);
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
    detail.keyType = ContactDetail.DetailKeyTypes.WORK;
    detail.order = ContactDetail.ORDER_NORMAL;
    address = new PostalAddress();
    address.addressLine1 = "work address line 1";
    address.addressLine2 = "work address line 2";
    address.city = "work city";
    address.country = "work country";
    address.county = "work county";
    address.postCode = "work postcode";
    address.postOfficeBox = "work po box";
    detail.value = VCardHelper.makePostalAddress(address);
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    address = new PostalAddress();
    address.addressLine1 = "other address line 1";
    address.addressLine2 = "other address line 2";
    address.city = "other city";
    address.country = "other country";
    address.county = "other county";
    address.postCode = "other postcode";
    address.postOfficeBox = "other po box";
    detail.value = VCardHelper.makePostalAddress(address);
    contact.details.add(detail);
    // add a VCARD_URL
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_URL;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "http://myurl.test";
    contact.details.add(detail);
    // add a VCARD_NOTE
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_NOTE;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "a note";
    contact.details.add(detail);
    // add a VCARD_ORG
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ORG;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    Organisation org = new Organisation();
    org.name = "company name";
    org.unitNames.add("department");
    detail.value = VCardHelper.makeOrg(org);
    contact.details.add(detail);
    // add a VCARD_TITLE
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_TITLE;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "title";
    contact.details.add(detail);
    mDatabaseHelper.addContact(contact);
    return contact;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) PostalAddress(com.vodafone360.people.datatypes.VCardHelper.PostalAddress) Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation) Time(android.text.format.Time) Contact(com.vodafone360.people.datatypes.Contact) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

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