Show badge icon if any participant in the conversation is work contact

Precompute is_enterprise and stored the value in conversation table.
Include is_enterprise in the ConversationList view.

Change-Id: I2e31bd61c08d25a296aaa3e99cb24631ae2e7976
This commit is contained in:
Tony Mak
2016-06-29 10:58:33 +01:00
parent dec1aca348
commit 7ad7ac27f1
6 changed files with 100 additions and 15 deletions
@@ -67,6 +67,7 @@ public class ConversationListItemData {
private String mDraftSubject;
private String mSnippetSenderFirstName;
private String mSnippetSenderDisplayDestination;
private boolean mIsEnterprise;
public ConversationListItemData() {
}
@@ -118,6 +119,7 @@ public class ConversationListItemData {
mSnippetSenderFirstName = cursor.getString(INDEX_SNIPPET_SENDER_FIRST_NAME);
mSnippetSenderDisplayDestination =
cursor.getString(INDEX_SNIPPET_SENDER_DISPLAY_DESTINATION);
mIsEnterprise = cursor.getInt(INDEX_IS_ENTERPRISE) == 1;
}
public String getConversationId() {
@@ -157,20 +159,19 @@ public class ConversationListItemData {
}
/**
* @see DatabaseHelper.ConversationColumns#PARTICIPANT_CONTACT_ID
* @return the contact id of the participant if it is a 1:1 conversation, -1 for group.
*/
* @see ConversationColumns#PARTICIPANT_CONTACT_ID
* @return the contact id of the participant if it is a 1:1 conversation, -1 for group.
*/
public long getParticipantContactId() {
return mParticipantContactId;
}
/**
* TODO: support group conversation.
* @see android.provider.ContactsContract#isEnterpriseContactId(long)
* @return is the participant an enterprise contact. False if it is a group conversation.
* @see ConversationColumns#IS_ENTERPRISE
* @return whether the conversation is enterprise.
*/
public boolean isParticipantEnterpriseContact() {
return ContactUtil.isEnterpriseContactId(getParticipantContactId());
public boolean isEnterprise() {
return mIsEnterprise;
}
public String getParticipantLookupKey() {
@@ -345,7 +346,9 @@ public class ConversationListItemData {
+ DatabaseHelper.PARTICIPANTS_TABLE + '.' + ParticipantColumns.FIRST_NAME
+ " as " + ConversationListViewColumns.SNIPPET_SENDER_FIRST_NAME + ", "
+ DatabaseHelper.PARTICIPANTS_TABLE + '.' + ParticipantColumns.DISPLAY_DESTINATION
+ " as " + ConversationListViewColumns.SNIPPET_SENDER_DISPLAY_DESTINATION;
+ " as " + ConversationListViewColumns.SNIPPET_SENDER_DISPLAY_DESTINATION + ", "
+ DatabaseHelper.CONVERSATIONS_TABLE + '.' + ConversationColumns.IS_ENTERPRISE
+ " as " + ConversationListViewColumns.IS_ENTERPRISE;
private static final String JOIN_PARTICIPANTS =
" LEFT JOIN " + DatabaseHelper.PARTICIPANTS_TABLE + " ON ("
@@ -404,6 +407,7 @@ public class ConversationListItemData {
static final String SNIPPET_SENDER_FIRST_NAME = "snippet_sender_first_name";
static final String SNIPPET_SENDER_DISPLAY_DESTINATION =
"snippet_sender_display_destination";
static final String IS_ENTERPRISE = ConversationColumns.IS_ENTERPRISE;
}
public static final String[] PROJECTION = {
@@ -436,6 +440,7 @@ public class ConversationListItemData {
ConversationListViewColumns.MESSAGE_RAW_TELEPHONY_STATUS,
ConversationListViewColumns.SNIPPET_SENDER_FIRST_NAME,
ConversationListViewColumns.SNIPPET_SENDER_DISPLAY_DESTINATION,
ConversationListViewColumns.IS_ENTERPRISE,
};
private static final int INDEX_ID = 0;
@@ -467,9 +472,20 @@ public class ConversationListItemData {
private static final int INDEX_MESSAGE_RAW_TELEPHONY_STATUS = 26;
private static final int INDEX_SNIPPET_SENDER_FIRST_NAME = 27;
private static final int INDEX_SNIPPET_SENDER_DISPLAY_DESTINATION = 28;
private static final int INDEX_IS_ENTERPRISE = 29;
private static final String DIVIDER_TEXT = ", ";
public static boolean hasAnyEnterpriseContact(
final List<ParticipantData> participants) {
for (final ParticipantData participant : participants) {
if (ContactUtil.isEnterpriseContactId(participant.getContactId())) {
return true;
}
}
return false;
}
/**
* Get a conversation from the local DB based on the conversation id.
*