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();
}
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);
}
}
Aggregations