Search in sources :

Example 11 with Name

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

the class NowPlusContactSummaryTest method testUpdateDisplayName.

/**
 * Tests updating a contact's display name.
 */
@SmallTest
public void testUpdateDisplayName() {
    Log.i(LOG_TAG, "***** EXECUTING testtestUpdateDisplayName *****");
    Log.i(LOG_TAG, "Create ContactSummaryTable");
    ContactSummaryTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Create also a ContactDetailsTable");
    ContactDetailsTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
    final Contact contact = new Contact();
    contact.localContactID = new Long(10);
    contact.nativeContactId = new Integer(11);
    ServiceStatus serviceStatus = ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    // Name
    ContactDetail nameDetail = new ContactDetail();
    nameDetail.localContactID = contact.localContactID;
    VCardHelper.Name name = new VCardHelper.Name();
    name.firstname = "John";
    name.surname = "Doe";
    nameDetail.setName(name);
    // ORG
    ContactDetail orgDetail = new ContactDetail();
    nameDetail.localContactID = contact.localContactID;
    VCardHelper.Organisation org = new VCardHelper.Organisation();
    org.name = "VF";
    org.unitNames.add("Dev");
    orgDetail.setOrg(org, ContactDetail.DetailKeyTypes.WORK);
    ContactDetail emailDetail = new ContactDetail();
    emailDetail.localContactID = contact.localContactID;
    emailDetail.setEmail("dev@vf.com", ContactDetail.DetailKeyTypes.WORK);
    ContactDetail phoneDetail = new ContactDetail();
    phoneDetail.localContactID = contact.localContactID;
    phoneDetail.setTel("+123456789", ContactDetail.DetailKeyTypes.HOME);
    contact.details.add(nameDetail);
    contact.details.add(orgDetail);
    contact.details.add(emailDetail);
    contact.details.add(phoneDetail);
    // Loop for number of details + 1
    final int numLoopCycles = contact.details.size() + 1;
    int loopCycles = numLoopCycles;
    boolean isMe = false;
    while (loopCycles-- > 0) {
        assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
        if (contact.details.size() > 0) {
            contact.details.remove(0);
        }
    }
    final Contact meContact = new Contact();
    meContact.localContactID = new Long(11);
    meContact.nativeContactId = new Integer(12);
    isMe = true;
    Log.i(LOG_TAG, "Add me Contact to ContactSummaryTable");
    serviceStatus = ContactSummaryTable.addContact(meContact, mTestDatabase.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    meContact.details.add(nameDetail);
    meContact.details.add(orgDetail);
    meContact.details.add(emailDetail);
    meContact.details.add(phoneDetail);
    loopCycles = numLoopCycles;
    while (loopCycles-- > 0) {
        assertEquals(getDisplayName(contact, isMe), ContactSummaryTable.updateContactDisplayName(contact, mTestDatabase.getWritableDatabase(), isMe));
        if (contact.details.size() > 0) {
            contact.details.remove(0);
        }
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 with Name

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

the class ContactChangeHelper method randomName.

private static Name randomName() {
    String firstname = null, surname = null, midname = null, suffix = null, title = null;
    if (randomTrue()) {
        firstname = randomString();
    }
    if (randomTrue()) {
        surname = randomString();
    }
    if (randomTrue()) {
        midname = randomString();
    }
    if (randomTrue()) {
        if (randomTrue()) {
            title = randomString();
        } else {
            title = mNameTitleList[randomPositiveInt(mNameTitleList.length)];
        }
    }
    if (randomTrue()) {
        suffix = randomString();
    }
    if (randomTrue()) {
        firstname = randomString();
    }
    Name name = new Name();
    if (firstname == null && surname == null) {
        /* So that we have one part not null!
    		 * Note that we ignored middle name, suffix and title in the above check
    		 * The reason for doing so is that 2.X NAB cannot work with just middle name, prefix and suffix fields!
    		 */
        firstname = randomString();
    }
    name.firstname = firstname;
    name.midname = midname;
    name.surname = surname;
    name.title = title;
    name.suffixes = suffix;
    return name;
}
Also used : Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Example 13 with Name

use of com.vodafone360.people.datatypes.VCardHelper.Name 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 14 with Name

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

the class DatabaseHelper method modifyContactDetail.

/**
 * Modifies an existing contact detail in the database. Also fires an
 * internal database change event.
 *
 * @param detail A {@link ContactDetail} object which contains the detail to add
 *
 * @return SUCCESS or a suitable error code
 * @see #addContactDetail(ContactDetail)
 * @see #deleteContactDetail(long)
 * @see #addContact(Contact)
 * @see #deleteContact(long)
 * @see #addContactToGroup(long, long)
 * @see #deleteContactFromGroup(long, long)
 */
public ServiceStatus modifyContactDetail(ContactDetail detail) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        trace(false, "DatabaseHelper.modifyContactDetail() name[" + detail.getName() + "]");
    }
    boolean isMeProfile = SyncMeDbUtils.isMeProfile(this, detail.localContactID);
    List<ContactDetail> detailList = new ArrayList<ContactDetail>();
    detailList.add(detail);
    ServiceStatus status = syncModifyContactDetailList(detailList, !isMeProfile, !isMeProfile);
    if (ServiceStatus.SUCCESS == status) {
        fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
        if (isMeProfile) {
            WidgetUtils.kickWidgetUpdateNow(mContext);
        }
    }
    return status;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList)

Example 15 with Name

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

the class DatabaseHelper method addContactDetail.

/**
 * Adds a contact detail to the database and fires an internal database
 * change event.
 *
 * @param detail A {@link ContactDetail} object which contains the detail to
 *            add
 * @return SUCCESS or a suitable error code
 * @see #modifyContactDetail(ContactDetail)
 * @see #deleteContactDetail(long)
 * @see #addContact(Contact)
 * @see #deleteContact(long)
 * @see #addContactToGroup(long, long)
 * @see #deleteContactFromGroup(long, long)
 * @throws NullPointerException When detail is NULL
 */
public ServiceStatus addContactDetail(ContactDetail detail) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        trace(false, "DatabaseHelper.addContactDetail() name[" + detail.getName() + "]");
    }
    if (detail == null) {
        throw new NullPointerException("DatabaseHelper.addContactDetail() detail should not be NULL");
    }
    boolean isMeProfile = (SyncMeDbUtils.getMeProfileLocalContactId(this) != null && detail.localContactID != null && detail.localContactID.equals(SyncMeDbUtils.getMeProfileLocalContactId(this)));
    List<ContactDetail> detailList = new ArrayList<ContactDetail>();
    detailList.add(detail);
    ServiceStatus status = syncAddContactDetailList(detailList, !isMeProfile, !isMeProfile);
    if (status == ServiceStatus.SUCCESS) {
        fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
        if (isMeProfile) {
            WidgetUtils.kickWidgetUpdateNow(mContext);
        }
    }
    return status;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList)

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