Search in sources :

Example 76 with Contact

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

the class NativeContactsApi2 method readOrganization.

/**
     * Reads an organization detail as a {@link ContactChange} from the provided
     * cursor. For this type of detail we need to use a VCARD (semicolon
     * separated) value. In reality two different changes may be read if a title
     * is also present.
     * 
     * @param cursor Cursor to read from
     * @param ccList List of Contact Changes to add read detail data
     * @param nabContactId ID of the NAB Contact
     */
private void readOrganization(Cursor cursor, List<ContactChange> ccList, long nabContactId) {
    final int type = CursorUtils.getInt(cursor, Organization.TYPE);
    int flags = mapFromNabOrganizationType(type);
    final boolean isPrimary = CursorUtils.getInt(cursor, Organization.IS_PRIMARY) != 0;
    if (isPrimary) {
        flags |= ContactChange.FLAG_PREFERRED;
    }
    final long nabDetailId = CursorUtils.getLong(cursor, Organization._ID);
    if (!mHaveReadOrganization) {
        // VCard Helper data type (CAB)
        final Organisation organization = new Organisation();
        // Company
        organization.name = CursorUtils.getString(cursor, Organization.COMPANY);
        // Department
        final String department = CursorUtils.getString(cursor, Organization.DEPARTMENT);
        if (!TextUtils.isEmpty(department)) {
            organization.unitNames.add(department);
        }
        if ((organization.unitNames != null && organization.unitNames.size() > 0) || !TextUtils.isEmpty(organization.name)) {
            final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_ORG, VCardHelper.makeOrg(organization), flags);
            cc.setNabContactId(nabContactId);
            cc.setNabDetailId(nabDetailId);
            ccList.add(cc);
            mHaveReadOrganization = true;
        }
        // Title
        final String title = CursorUtils.getString(cursor, Organization.TITLE);
        if (!TextUtils.isEmpty(title)) {
            final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_TITLE, title, flags);
            cc.setNabContactId(nabContactId);
            cc.setNabDetailId(nabDetailId);
            ccList.add(cc);
            mHaveReadOrganization = true;
        }
    }
}
Also used : Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation)

Example 77 with Contact

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

the class PeopleContactsApi method updateNativeContact.

/**
     * Updates a native contact in the people database.
     * 
     * Note: it assumes that the changes come from native as it sets flags
     *       to prevent syncing back to native
     * 
     * @param contact the contact changes to apply to the contact
     */
public void updateNativeContact(ContactChange[] contact) {
    mAddedDetails.clear();
    mDeletedDetails.clear();
    mUpdatedDetails.clear();
    for (int i = 0; i < contact.length; i++) {
        final ContactChange change = contact[i];
        // convert the ContactChange into a ContactDetail
        final ContactDetail detail = mDbh.convertContactChange(change);
        final int type = change.getType();
        switch(type) {
            case ContactChange.TYPE_ADD_DETAIL:
                mAddedDetails.add(detail);
                break;
            case ContactChange.TYPE_DELETE_DETAIL:
                mDeletedDetails.add(detail);
                break;
            case ContactChange.TYPE_UPDATE_DETAIL:
                mUpdatedDetails.add(detail);
                break;
        }
    }
    if (mAddedDetails.size() > 0) {
        mDbh.syncAddContactDetailList(mAddedDetails, true, false);
    }
    if (mDeletedDetails.size() > 0) {
        mDbh.syncDeleteContactDetailList(mDeletedDetails, true, false);
    }
    if (mUpdatedDetails.size() > 0) {
        mDbh.syncModifyContactDetailList(mUpdatedDetails, true, false);
    }
    // TODO: Throttle the event
    mDbh.fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, true);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail)

Example 78 with Contact

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

the class ThumbnailHandler method downloadThumbnails.

/**
     * Download the next bunch of contacts from the queue. The method uses the
     * ContentEngine to download the thumbnails and sets this class as a handler
     * 
     * @param thumbsPerPage Indicates the number of thumbnails to be downloaded
     *            in this page
     */
private void downloadThumbnails(final int thumbsPerPage) {
    List<Long> contactList = new ArrayList<Long>();
    for (int i = 0; i < thumbsPerPage; i++) {
        if (mContactsQueue.size() == 0) {
            break;
        }
        contactList.add((Long) mContactsQueue.remove(0));
    }
    // nothing to do? exit!
    if (contactList.size() == 0) {
        LogUtils.logI("Thumbnail download finished");
        return;
    }
    // get the contentengine, so we can access the database
    ContentEngine contentEngine = EngineManager.getInstance().getContentEngine();
    // list for holding the fetched ThumbnailURLs
    ArrayList<ThumbnailInfo> thumbnailInfoList = new ArrayList<ThumbnailInfo>();
    // fetches the URLs of all thumbnails that are not downloaded by now
    contentEngine.getDatabaseHelper().fetchThumbnailUrlsForContacts(thumbnailInfoList, contactList);
    // This list is needed because of following usecase: We have started the
    // thumbnail sync. 5 thumbnails are requested and we have got the
    // response for 3 of them. At this point, the thumbnail sync starts
    // again(maybe because somethign got changed in the server). This
    // function gets called again. And if we don't use this temporary
    // contentList, those contentObjects for which we haven't got the
    // response yet are also added into the queue of the COntent Engine.
    List<ContentObject> contentList = new ArrayList<ContentObject>();
    // iterate over the given thumbnailInfoList
    for (ThumbnailInfo thumbnailInfo : thumbnailInfoList) {
        // not every contact has a thumbnail, so continue in this case
        if (thumbnailInfo == null) {
            continue;
        }
        try {
            // create a ContentObject for downloading the particular
            // Thumbnail...
            ContentObject contentObject = new ContentObject(null, thumbnailInfo.localContactId, this, ContentObject.TransferDirection.DOWNLOAD, ContentObject.Protocol.RPG);
            // ... set the right URL and params...
            contentObject.setUrl(new URL(thumbnailInfo.photoServerUrl));
            contentObject.setUrlParams(ThumbnailUtils.REQUEST_THUMBNAIL_URI);
            contentObject.setTransferStatus(TransferStatus.INIT);
            contentList.add(contentObject);
            // ... and put it to the list
            mContentObjects.add(contentObject);
        } catch (MalformedURLException e) {
            LogUtils.logE("ThumbanailHandler.downloadContactThumbnails: " + thumbnailInfo.photoServerUrl + " is not a valid URL");
        }
    }
    // if the list is not empty, let the ContentEngine process them
    if (mContentObjects.size() > 0) {
        contentEngine.processContentObjects(contentList);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) ThumbnailInfo(com.vodafone360.people.database.DatabaseHelper.ThumbnailInfo) URL(java.net.URL)

Example 79 with Contact

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

the class SyncMeDbUtils method updateStatus.

/**
     * The utility method to save the status text change to the database...
     * @param dbHelper DatabaseHelper - database
     * @param statusText String - status text
     * @return ContactDetail - the modified or created ContactDetail with key
     *         ContactDetail.DetailKeys.PRESENCE_TEXT
     */
public static ContactDetail updateStatus(final DatabaseHelper dbHelper, final String statusText) {
    Contact meContact = new Contact();
    if (fetchMeProfile(dbHelper, meContact) == ServiceStatus.SUCCESS) {
        // try to modify an existing detail
        for (ContactDetail detail : meContact.details) {
            if (detail.key == ContactDetail.DetailKeys.PRESENCE_TEXT) {
                detail.value = statusText;
                // Currently it's only possible to post a status on
                // Vodafone sns
                detail.alt = ThirdPartyAccount.SNS_TYPE_VODAFONE;
                if (ServiceStatus.SUCCESS == dbHelper.modifyContactDetail(detail)) {
                    return detail;
                }
            }
        }
        // create a new detail instead
        ContactDetail contactDetail = new ContactDetail();
        contactDetail.setValue(statusText, ContactDetail.DetailKeys.PRESENCE_TEXT, null);
        contactDetail.alt = ThirdPartyAccount.SNS_TYPE_VODAFONE;
        contactDetail.localContactID = meContact.localContactID;
        if (ServiceStatus.SUCCESS == dbHelper.addContactDetail(contactDetail)) {
            return contactDetail;
        }
    }
    return null;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 80 with Contact

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

the class SyncMeDbUtils method setMeProfile.

/**
     * This method create a Me Profile contact in the database.
     * @param dbHelper DatabaseHelper - the database.
     * @param meProfile Contact - the Me Profile contact
     * @return ServiceStatus - ServiceStatus.SUCCESS when the new contact is
     *         successfully created.
     */
public static ServiceStatus setMeProfile(final DatabaseHelper dbHelper, Contact meProfile) {
    ServiceStatus status = ServiceStatus.ERROR_DATABASE_CORRUPT;
    // the contact didn't exist before
    if (sMeProfileLocalContactId == null) {
        List<Contact> contactList = new ArrayList<Contact>();
        contactList.add(meProfile);
        status = dbHelper.syncAddContactList(contactList, false, false);
        if (ServiceStatus.SUCCESS == status) {
            sMeProfileLocalContactId = meProfile.localContactID;
            status = StateTable.modifyMeProfileID(sMeProfileLocalContactId, dbHelper.getWritableDatabase());
            PresenceDbUtils.resetMeProfileIds();
            if (ServiceStatus.SUCCESS != status) {
                List<ContactsTable.ContactIdInfo> idList = new ArrayList<ContactsTable.ContactIdInfo>();
                ContactsTable.ContactIdInfo contactIdInfo = new ContactsTable.ContactIdInfo();
                contactIdInfo.localId = meProfile.localContactID;
                contactIdInfo.serverId = meProfile.contactID;
                contactIdInfo.nativeId = meProfile.nativeContactId;
                idList.add(contactIdInfo);
                dbHelper.syncDeleteContactList(idList, false, false);
            }
        }
    }
    return status;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ContactsTable(com.vodafone360.people.database.tables.ContactsTable) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact)

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