Search in sources :

Example 56 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 57 with Contact

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

the class SyncMeDbUtils method populateWithDeletedContactDetails.

/**
 * This method adds the deleted details to the detail list sent to server...
 * @param dbHelper DatabaseHelper - database
 * @param contactDetails List<ContactDetail> - the deleted details list
 * @param contactId Long - Me Profile local contact id.
 */
private static void populateWithDeletedContactDetails(final DatabaseHelper dbHelper, final List<ContactDetail> contactDetails, final Long contactId) {
    List<ContactChangeInfo> deletedDetails = new ArrayList<ContactChangeInfo>();
    if (!ContactChangeLogTable.fetchMeProfileChangeLog(deletedDetails, ContactChangeType.DELETE_DETAIL, dbHelper.getReadableDatabase(), contactId)) {
        LogUtils.logE("UploadServerContacts populateWithDeletedContactDetails -" + " Unable to fetch contact changes from database");
        return;
    }
    for (int i = 0; i < deletedDetails.size(); i++) {
        ContactChangeInfo info = deletedDetails.get(i);
        final ContactDetail detail = new ContactDetail();
        detail.localDetailID = info.mLocalDetailId;
        detail.key = info.mServerDetailKey;
        detail.unique_id = info.mServerDetailId;
        detail.deleted = true;
        contactDetails.add(detail);
    }
    dbHelper.deleteContactChanges(deletedDetails);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList)

Example 58 with Contact

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

the class SyncMeDbUtils method processMyContactDetailsChanges.

/**
 * This method stores the getMyChanges() response to database - details part.
 * @param dbHelper DatabaseHelper - database.
 * @param currentMeProfile Contact - me profile contact.
 * @param profileChanges UserProfile - the contact changes.
 * @return ServiceStatus - SUCCESS if the contact changes have been successfully processed stored.
 */
private static String processMyContactDetailsChanges(final DatabaseHelper dbHelper, final Contact currentMeProfile, final UserProfile profileChanges) {
    String ret = null;
    final ArrayList<ContactDetail> modifiedDetailList = new ArrayList<ContactDetail>();
    final ArrayList<ContactDetail> addedDetailList = new ArrayList<ContactDetail>();
    final ArrayList<ContactDetail> deletedDetailList = new ArrayList<ContactDetail>();
    for (ContactDetail newDetail : profileChanges.details) {
        boolean found = false;
        for (int i = 0; i < currentMeProfile.details.size(); i++) {
            ContactDetail oldDetail = currentMeProfile.details.get(i);
            if (DatabaseHelper.doDetailsMatch(newDetail, oldDetail)) {
                found = true;
                if (newDetail.deleted != null && newDetail.deleted.booleanValue()) {
                    deletedDetailList.add(oldDetail);
                } else if (DatabaseHelper.hasDetailChanged(oldDetail, newDetail)) {
                    newDetail.localDetailID = oldDetail.localDetailID;
                    newDetail.localContactID = oldDetail.localContactID;
                    newDetail.nativeContactId = oldDetail.nativeContactId;
                    newDetail.nativeDetailId = oldDetail.nativeDetailId;
                    modifiedDetailList.add(newDetail);
                    if (newDetail.key == DetailKeys.PHOTO) {
                        dbHelper.markMeProfileAvatarChanged();
                        ret = newDetail.value;
                    }
                }
                break;
            }
        }
        // in the response or the deleted flag was false we have to add the new detail to the list
        if ((!found) && ((null == newDetail.deleted) || (!newDetail.deleted.booleanValue()))) {
            newDetail.localContactID = currentMeProfile.localContactID;
            newDetail.nativeContactId = currentMeProfile.nativeContactId;
            if (newDetail.key == DetailKeys.PHOTO) {
                dbHelper.markMeProfileAvatarChanged();
                ret = newDetail.value;
            }
            addedDetailList.add(newDetail);
        }
    }
    if (!addedDetailList.isEmpty()) {
        dbHelper.syncAddContactDetailList(addedDetailList, false, false);
    }
    if (!modifiedDetailList.isEmpty()) {
        dbHelper.syncModifyContactDetailList(modifiedDetailList, false, false);
    }
    if (!deletedDetailList.isEmpty()) {
        dbHelper.syncDeleteContactDetailList(deletedDetailList, false, false);
    }
    return ret;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ArrayList(java.util.ArrayList)

Example 59 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 60 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