Search in sources :

Example 1 with ContentEngine

use of com.vodafone360.people.engine.content.ContentEngine 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 2 with ContentEngine

use of com.vodafone360.people.engine.content.ContentEngine in project 360-Engine-for-Android by 360.

the class EngineManager method createContentEngine.

/**
     * Create instance of ContentEngine.
     */
private synchronized void createContentEngine() {
    final MainApplication app = (MainApplication) mService.getApplication();
    mContentEngine = new ContentEngine(mUiEventCallback, app.getDatabase());
    addEngine(mContentEngine);
}
Also used : ContentEngine(com.vodafone360.people.engine.content.ContentEngine) MainApplication(com.vodafone360.people.MainApplication)

Aggregations

MainApplication (com.vodafone360.people.MainApplication)1 ThumbnailInfo (com.vodafone360.people.database.DatabaseHelper.ThumbnailInfo)1 ContentEngine (com.vodafone360.people.engine.content.ContentEngine)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1