use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method updateMeProfileDbDetailIds.
/**
* The utility method to save Contacts/setMe() response to the database...
* @param dbHelper Database - database
* @param uploadedMeProfile Contact - me profile which has been uploaded in
* Contacts/setMe() call
* @param result ContactChanges - the contents of response Contacts/setMe().
* The contact details in response need to be in the same order
* as they were in setMe() request
*/
public static void updateMeProfileDbDetailIds(final DatabaseHelper dbHelper, final ArrayList<ContactDetail> uploadedDetails, final ContactChanges result) {
Contact uploadedMeProfile = new Contact();
SyncMeDbUtils.fetchMeProfile(dbHelper, uploadedMeProfile);
boolean changed = false;
if (result.mUserProfile.userID != null && !result.mUserProfile.userID.equals(uploadedMeProfile.userID)) {
uploadedMeProfile.userID = result.mUserProfile.userID;
changed = true;
}
if (result.mUserProfile.contactID != null && !result.mUserProfile.contactID.equals(uploadedMeProfile.contactID)) {
uploadedMeProfile.contactID = result.mUserProfile.contactID;
changed = true;
}
if (changed) {
dbHelper.modifyContactServerId(uploadedMeProfile.localContactID, uploadedMeProfile.contactID, uploadedMeProfile.userID);
}
ListIterator<ContactDetail> destIt = uploadedDetails.listIterator();
for (ContactDetail srcDetail : result.mUserProfile.details) {
if (!destIt.hasNext()) {
LogUtils.logE("SyncMeDbUtils updateProfileDbDetailsId() - # of details in response > # in request");
return;
}
final ContactDetail destDetail = destIt.next();
if (srcDetail.key == null || !srcDetail.key.equals(destDetail.key)) {
LogUtils.logE("SyncMeDbUtils updateProfileDbDetailsId() - details order is wrong");
break;
}
destDetail.unique_id = srcDetail.unique_id;
dbHelper.syncContactDetail(destDetail.localDetailID, destDetail.unique_id);
}
}
use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method populateWithModifiedDetails.
private static void populateWithModifiedDetails(final DatabaseHelper dbHelper, final ArrayList<ContactDetail> updates, Contact meProfile) {
boolean avatarChanged = dbHelper.isMeProfileAvatarChanged();
for (ContactDetail detail : meProfile.details) {
// LogUtils.logV("meProfile.details:" + detail);
if (avatarChanged && detail.key == ContactDetail.DetailKeys.PHOTO) {
populatePhotoDetail(dbHelper, meProfile, detail);
updates.add(detail);
} else if (detail.key != ContactDetail.DetailKeys.VCARD_INTERNET_ADDRESS && detail.key != ContactDetail.DetailKeys.VCARD_IMADDRESS && detail.key != ContactDetail.DetailKeys.PRESENCE_TEXT) {
// fix for bug 16029 - it's a server issue (getMe() returns
// broken details) but the workaround on the client side is
// just
// not to add the extra details to setMe() request
detail.updated = null;
// LogUtils.logV("meProfile.details: put");
updates.add(detail);
}
}
}
use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class ChatDbUtils method saveChatMessageAsATimeline.
/**
* This method saves the supplied
*
* @param msg
* @param type
* @param databaseHelper
*/
protected static void saveChatMessageAsATimeline(ChatMessage message, TimelineSummaryItem.Type type, DatabaseHelper databaseHelper) {
TimelineSummaryItem item = new TimelineSummaryItem();
fillInContactDetails(message, item, databaseHelper, type);
SQLiteDatabase writableDatabase = databaseHelper.getWritableDatabase();
boolean isRead = true;
if (type == TimelineSummaryItem.Type.INCOMING) {
isRead = false;
}
if (ActivitiesTable.addChatTimelineEvent(item, isRead, writableDatabase) != -1) {
ConversationsTable.addNewConversationId(message, writableDatabase);
} else {
LogUtils.logE("The msg was not saved to the ActivitiesTable");
}
}
use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class ChatDbUtils method fillInContactDetails.
/**
* Remove hard code
*
* @param msg
* @param item
* @param databaseHelper
* @param incoming
*/
private static void fillInContactDetails(ChatMessage msg, TimelineSummaryItem item, DatabaseHelper databaseHelper, TimelineSummaryItem.Type incoming) {
item.mTimestamp = System.currentTimeMillis();
// here we set the time stamp back into the chat message
// in order to be able to remove it from the chat history by time stamp in case its delivery fails
msg.setTimeStamp(item.mTimestamp);
item.mType = ActivityItem.Type.MESSAGE_IM_CONVERSATION;
item.mDescription = msg.getBody();
item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
// we store sender's localContactId for incoming msgs and recipient's
// localContactId for outgoing msgs
item.mLocalContactId = msg.getLocalContactId();
if (item.mLocalContactId != null && item.mLocalContactId != -1) {
ContactDetail cd = ContactDetailsTable.fetchDetail(item.mLocalContactId, DetailKeys.VCARD_NAME, databaseHelper.getReadableDatabase());
if (cd == null || cd.getName() == null) {
// if we don't get any details, we have to check the summary
// table because gtalk contacts
// without name will be otherwise show as unknown
ContactSummary contactSummary = new ContactSummary();
ServiceStatus error = ContactSummaryTable.fetchSummaryItem(item.mLocalContactId, contactSummary, databaseHelper.getReadableDatabase());
if (error == ServiceStatus.SUCCESS) {
item.mContactName = (contactSummary.formattedName != null) ? contactSummary.formattedName : ContactDetail.UNKNOWN_NAME;
} else {
item.mContactName = ContactDetail.UNKNOWN_NAME;
}
} else {
/** Get name from contact details. **/
VCardHelper.Name name = cd.getName();
item.mContactName = (name != null) ? name.toString() : ContactDetail.UNKNOWN_NAME;
}
}
item.mIncoming = incoming;
item.mContactNetwork = SocialNetwork.getSocialNetworkValue(msg.getNetworkId()).toString();
item.mNativeItemType = TimelineNativeTypes.ChatLog.ordinal();
}
use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class ChatDbUtilsTest method setUp.
/***
* Set up the DatabaseHelper.
*/
public final void setUp() {
createApplication();
MainApplication mainApplication = getApplication();
if (mainApplication == null) {
throw (new RuntimeException("ChatDbUtilsTest.setUp() " + "Unable to create main application"));
}
mDatabaseHelper = mainApplication.getDatabase();
}
Aggregations