Search in sources :

Example 1 with ThumbnailInfo

use of com.vodafone360.people.database.DatabaseHelper.ThumbnailInfo in project 360-Engine-for-Android by 360.

the class NowPlusDBHelperThumbnailTest method testDBHelperThumbnail.

@SmallTest
public void testDBHelperThumbnail() {
    assertTrue(initialise());
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
    Contact contact = mTestModule.createDummyContactData();
    status = mDatabaseHelper.addContact(contact);
    assertEquals(ServiceStatus.SUCCESS, status);
    Bitmap testBimap = Bitmap.createBitmap(createColors(), 0, STRIDE, WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
    ContactDetail cd = new ContactDetail();
    cd.localContactID = contact.localContactID;
    cd.photo = testBimap;
    status = mDatabaseHelper.addContactDetail(cd);
    status = ContactSummaryTable.modifyPictureLoadedFlag(contact.localContactID, false, mDatabaseHelper.getWritableDatabase());
    assertEquals(ServiceStatus.SUCCESS, status);
    int numOfThumbnails = mDatabaseHelper.fetchThumbnailUrlCount();
    assertEquals(1, numOfThumbnails);
    List<ThumbnailInfo> thumbInfoList = new ArrayList<ThumbnailInfo>();
    status = mDatabaseHelper.fetchThumbnailUrls(thumbInfoList, 0, 1);
    assertEquals(ServiceStatus.SUCCESS, status);
    shutdown();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Bitmap(android.graphics.Bitmap) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) ThumbnailInfo(com.vodafone360.people.database.DatabaseHelper.ThumbnailInfo) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 2 with ThumbnailInfo

use of com.vodafone360.people.database.DatabaseHelper.ThumbnailInfo 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)

Aggregations

ThumbnailInfo (com.vodafone360.people.database.DatabaseHelper.ThumbnailInfo)2 ArrayList (java.util.ArrayList)2 Bitmap (android.graphics.Bitmap)1 SmallTest (android.test.suitebuilder.annotation.SmallTest)1 Contact (com.vodafone360.people.datatypes.Contact)1 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)1 ServiceStatus (com.vodafone360.people.service.ServiceStatus)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1