use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class ContactsTable method fetchContactList.
/**
* Fetches a List with Contacts from Database Uses the persistence helper to
* build the objects The Contactdetails are not read, only the contacts
*
* @param readableDB A readable Database
* @return java.util.list<Contact> with contacts
*/
public static List<Contact> fetchContactList(SQLiteDatabase readableDB) {
ArrayList<Contact> contactList = new ArrayList<Contact>();
Cursor cursor = openContactsCursor(readableDB);
if (null == cursor) {
throw new RuntimeException("no cursor returned");
}
try {
while (cursor.moveToNext()) {
Contact contact = new Contact();
PersistenceHelper.mapCursorToObject(contact, cursor);
contactList.add(contact);
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
cursor.close();
}
return contactList;
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method getQueryData.
/**
* Fetches the contact summary data from the current record of the given
* cursor.
*
* @param c Cursor returned by one of the {@link #getFullQueryList()} based
* query methods.
* @return Filled in ContactSummary object
*/
public static ContactSummary getQueryData(Cursor c) {
ContactSummary contactSummary = new ContactSummary();
if (!c.isNull(SUMMARY_ID)) {
contactSummary.summaryID = c.getLong(SUMMARY_ID);
}
if (!c.isNull(LOCALCONTACT_ID)) {
contactSummary.localContactID = c.getLong(LOCALCONTACT_ID);
}
contactSummary.formattedName = c.getString(FORMATTED_NAME);
contactSummary.statusText = c.getString(STATUS_TEXT);
contactSummary.onlineStatus = getPresence(contactSummary.localContactID);
if (!c.isNull(NATIVE_CONTACTID)) {
contactSummary.nativeContactId = c.getInt(NATIVE_CONTACTID);
}
if (!c.isNull(FRIEND_MINE)) {
contactSummary.friendOfMine = (c.getInt(FRIEND_MINE) == 0 ? false : true);
}
if (!c.isNull(PICTURE_LOADED)) {
contactSummary.pictureLoaded = (c.getInt(PICTURE_LOADED) == 0 ? false : true);
}
if (!c.isNull(SNS)) {
contactSummary.sns = c.getString(SNS);
}
if (!c.isNull(SYNCTOPHONE)) {
contactSummary.synctophone = (c.getInt(SYNCTOPHONE) == 0 ? false : true);
}
if (!c.isNull(ALTFIELD_TYPE)) {
int val = c.getInt(ALTFIELD_TYPE);
if (val < AltFieldType.values().length) {
contactSummary.altFieldType = AltFieldType.values()[val];
}
}
if (!c.isNull(ALTDETAIL_TYPE)) {
int val = c.getInt(ALTDETAIL_TYPE);
if (val < ContactDetail.DetailKeys.values().length) {
contactSummary.altDetailType = ContactDetail.DetailKeyTypes.values()[val];
}
}
return contactSummary;
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method getDisplayNameDetail.
/**
* Retrieves display name detail for a contact
* @param contact Contact to retrieve display name from
* @return Found display name detail - maybe be null
*/
private static ContactDetail getDisplayNameDetail(Contact contact) {
// These two Arrays contains the order in which the details are queried.
// First valid (not empty or unknown) detail is taken
ContactDetail.DetailKeys[] preferredNameDetails = { ContactDetail.DetailKeys.VCARD_NAME, ContactDetail.DetailKeys.VCARD_ORG, ContactDetail.DetailKeys.VCARD_EMAIL, ContactDetail.DetailKeys.VCARD_PHONE };
ContactDetail name = null;
// Query the details for the name field
for (ContactDetail.DetailKeys key : preferredNameDetails) {
if ((name = contact.getContactDetail(key)) != null) {
// (gmail for example)
if (key == ContactDetail.DetailKeys.VCARD_NAME && name.getName() == null)
continue;
if (key != ContactDetail.DetailKeys.VCARD_NAME && TextUtils.isEmpty(name.getValue()))
continue;
break;
}
}
return name;
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class ContactDetailsTable method syncSetServerIds.
/**
* Set contact detail server ID for all those details which require a server
* ID. In any case, the server sync contact ID flag is set to -1 to indicate
* that the detail has been fully synced with the server.
*
* @param serverIdList The list of contact details. This list should include
* all details even the ones which don't have server IDs.
* @param writableDb A writable SQLite database object
* @return SUCCESS or a suitable error code.
*/
public static ServiceStatus syncSetServerIds(List<ServerIdInfo> serverIdList, SQLiteDatabase writableDb) {
final int STATEMENT1_COLUMN_SERVERID = 1;
final int STATEMENT1_COLUMN_LOCALID = 2;
final int STATEMENT2_COLUMN_LOCALID = 1;
DatabaseHelper.trace(true, "ContactDetailsTable.syncSetServerIds()");
if (serverIdList.size() == 0) {
return ServiceStatus.SUCCESS;
}
SQLiteStatement statement1 = null;
SQLiteStatement statement2 = null;
try {
writableDb.beginTransaction();
for (int i = 0; i < serverIdList.size(); i++) {
final ServerIdInfo info = serverIdList.get(i);
if (info.serverId != null) {
if (statement1 == null) {
statement1 = writableDb.compileStatement("UPDATE " + TABLE_NAME + " SET " + Field.DETAILSERVERID + "=?," + Field.SERVERSYNCCONTACTID + "=-1 WHERE " + Field.DETAILLOCALID + "=?");
}
statement1.bindLong(STATEMENT1_COLUMN_SERVERID, info.serverId);
statement1.bindLong(STATEMENT1_COLUMN_LOCALID, info.localId);
statement1.execute();
} else {
if (statement2 == null) {
statement2 = writableDb.compileStatement("UPDATE " + TABLE_NAME + " SET " + Field.SERVERSYNCCONTACTID + "=-1 WHERE " + Field.DETAILLOCALID + "=?");
}
statement2.bindLong(STATEMENT2_COLUMN_LOCALID, info.localId);
statement2.execute();
}
}
writableDb.setTransactionSuccessful();
return ServiceStatus.SUCCESS;
} catch (SQLException e) {
LogUtils.logE("ContactDetailsTable.syncSetServerIds() SQLException - Unable to update contact detail server Ids", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
} finally {
writableDb.endTransaction();
if (statement1 != null) {
statement1.close();
statement1 = null;
}
if (statement2 != null) {
statement2.close();
statement2 = null;
}
}
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class ContactDetailsTable method mergeContactDetails.
/**
* Moves native details ownership from the duplicate contact to the original
* contact.
*
* @param info the info for duplicated and original contacts
* @param nativeInfoList the list of native details from the duplicated
* contact
* @param writableDb A writable SQLite database object
* @return SUCCESS or a suitable error code.
*/
public static ServiceStatus mergeContactDetails(ContactIdInfo info, List<ContactDetail> nativeInfoList, SQLiteDatabase writableDb) {
DatabaseHelper.trace(true, "ContactDetailsTable.mergeContactDetails()");
/**
* Used to hold some contact details info.
*/
final class DetailsInfo {
/**
* The detail local id.
*/
public Long localId;
/**
* The detail server id.
*/
public Long serverId;
public DetailsInfo(Long localId, Long serverId) {
this.localId = localId;
this.serverId = serverId;
}
}
// the list of details from the original contact
List<DetailsInfo> detailLocalIds = new ArrayList<DetailsInfo>();
// the result cursor from the original contact details query
Cursor cursor = null;
try {
// Retrieve a list of detail local IDs from the merged contact
// (original one)
final String[] args = { String.valueOf(info.mergedLocalId) };
cursor = writableDb.rawQuery(QUERY_DETAIL_LOCAL_AND_SERVER_IDS_BY_LOCAL_CONTACT_ID, args);
while (cursor.moveToNext()) {
if (!cursor.isNull(0) && !cursor.isNull(1)) {
// only adding details with a detailServerId (Name and
// Nickname don't have detailServerIds)
detailLocalIds.add(new DetailsInfo(cursor.getLong(0), cursor.getLong(1)));
}
}
DatabaseHelper.trace(true, "ContactDetailsTable.mergeContactDetails(): detailLocalIds.size()=" + detailLocalIds.size());
} catch (Exception e) {
LogUtils.logE("ContactDetailsTable.mergeContactDetails() Exception - " + "Unable to query merged contact details list", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
} finally {
if (cursor != null) {
cursor.close();
cursor = null;
}
}
try {
final ContentValues cv = new ContentValues();
// duplicated contact to the original contact
for (int infoListIndex = 0; infoListIndex < nativeInfoList.size(); infoListIndex++) {
final ContactDetail detailInfo = nativeInfoList.get(infoListIndex);
// Change the ownership
for (int detailsIndex = 0; detailsIndex < detailLocalIds.size(); detailsIndex++) {
final DetailsInfo currentDetails = detailLocalIds.get(detailsIndex);
if (currentDetails.serverId.equals(detailInfo.unique_id)) {
cv.put(Field.LOCALCONTACTID.toString(), info.mergedLocalId);
cv.put(Field.NATIVECONTACTID.toString(), detailInfo.nativeContactId);
cv.put(Field.NATIVEDETAILID.toString(), detailInfo.nativeDetailId);
cv.put(Field.NATIVEDETAILVAL1.toString(), detailInfo.nativeVal1);
cv.put(Field.NATIVEDETAILVAL2.toString(), detailInfo.nativeVal2);
cv.put(Field.NATIVEDETAILVAL3.toString(), detailInfo.nativeVal3);
cv.put(Field.NATIVESYNCCONTACTID.toString(), detailInfo.syncNativeContactId);
DatabaseHelper.trace(true, "ContactDetailsTable.mergeContactDetails():" + " changing ownership for duplicated detail: " + detailInfo);
writableDb.update(TABLE_NAME, cv, Field.DETAILLOCALID + "=" + currentDetails.localId, null);
cv.clear();
detailLocalIds.remove(detailsIndex);
break;
}
}
}
return ServiceStatus.SUCCESS;
} catch (SQLException e) {
LogUtils.logE("ContactDetailsTable.mergeContactDetails() SQLException - " + "Unable to merge contact detail native info", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
Aggregations