Add badge in conversation view if the participant is a work contact

TODO: To handle conversation having more than one participants.

Bug: 29065176
Change-Id: I3820454bf2b76c151dc3a13d9be270502029160d
diff --git a/res/layout/conversation_list_item_view.xml b/res/layout/conversation_list_item_view.xml
index da1ca4e..10fdcd5 100644
--- a/res/layout/conversation_list_item_view.xml
+++ b/res/layout/conversation_list_item_view.xml
@@ -118,25 +118,38 @@
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:background="@android:color/transparent">
+                    <LinearLayout
+                            android:layout_width="0dp"
+                            android:layout_height="wrap_content"
+                            android:layout_weight="1">
+                        <ImageView
+                            android:id="@+id/conversation_notification_bell"
+                            style="@style/ConversationListNotificationBellPaddingStyle"
+                            android:layout_width="wrap_content"
+                            android:layout_height="wrap_content"
+                            android:src="@drawable/ic_notifications_off_small_light"
+                            android:visibility="gone"
+                            android:importantForAccessibility="no"
+                            android:contentDescription="@null"
+                            android:layout_gravity="center_vertical"
+                            android:background="@android:color/transparent" />
+                        <TextView
+                            android:id="@+id/conversation_name"
+                            style="@style/ConversationListItemViewConversationNameStyle"
+                            android:layout_width="match_parent"
+                            android:layout_height="wrap_content"
+                            android:singleLine="true"
+                            android:layout_gravity="center_vertical"
+                            android:paddingBottom="2dp" />
+                    </LinearLayout>
                     <ImageView
-                        android:id="@+id/conversation_notification_bell"
-                        style="@style/ConversationListNotificationBellPaddingStyle"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:src="@drawable/ic_notifications_off_small_light"
-                        android:visibility="gone"
-                        android:importantForAccessibility="no"
-                        android:contentDescription="@null"
-                        android:layout_gravity="center_vertical"
-                        android:background="@android:color/transparent" />
-                    <TextView
-                        android:id="@+id/conversation_name"
-                        style="@style/ConversationListItemViewConversationNameStyle"
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:singleLine="true"
-                        android:layout_gravity="center_vertical"
-                        android:paddingBottom="2dp" />
+                            android:id="@+id/work_profile_icon"
+                            android:layout_width="wrap_content"
+                            android:layout_height="wrap_content"
+                            android:layout_gravity="right"
+                            android:scaleType="center"
+                            android:src="@drawable/ic_work_profile"
+                            android:visibility="gone"/>
                 </LinearLayout>
                 <TextView
                     android:id="@+id/conversation_subject"
diff --git a/src/com/android/messaging/datamodel/data/ConversationListItemData.java b/src/com/android/messaging/datamodel/data/ConversationListItemData.java
index b2e6e1c..77da49e 100644
--- a/src/com/android/messaging/datamodel/data/ConversationListItemData.java
+++ b/src/com/android/messaging/datamodel/data/ConversationListItemData.java
@@ -28,6 +28,7 @@
 import com.android.messaging.datamodel.DatabaseWrapper;
 import com.android.messaging.datamodel.action.DeleteConversationAction;
 import com.android.messaging.util.Assert;
+import com.android.messaging.util.ContactUtil;
 import com.android.messaging.util.Dates;
 import com.google.common.base.Joiner;
 
@@ -155,10 +156,23 @@
         return mPreviewContentType;
     }
 
+    /**
+     * @see DatabaseHelper.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.
+     */
+    public boolean isParticipantEnterpriseContact() {
+        return ContactUtil.isEnterpriseContactId(getParticipantContactId());
+    }
+
     public String getParticipantLookupKey() {
         return mParticipantLookupKey;
     }
diff --git a/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java b/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java
index 9b8c5ff..58c4e69 100644
--- a/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java
+++ b/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java
@@ -118,6 +118,7 @@
     private ViewGroup mCrossSwipeBackground;
     private ViewGroup mSwipeableContent;
     private TextView mConversationNameView;
+    private ImageView mWorkProfileIconView;
     private TextView mSnippetTextView;
     private TextView mSubjectTextView;
     private TextView mTimestampTextView;
@@ -145,6 +146,7 @@
         mConversationNameView = (TextView) findViewById(R.id.conversation_name);
         mSnippetTextView = (TextView) findViewById(R.id.conversation_snippet);
         mSubjectTextView = (TextView) findViewById(R.id.conversation_subject);
+        mWorkProfileIconView = (ImageView) findViewById(R.id.work_profile_icon);
         mTimestampTextView = (TextView) findViewById(R.id.conversation_timestamp);
         mContactIconView = (ContactIconView) findViewById(R.id.conversation_icon);
         mContactCheckmarkView = (ImageView) findViewById(R.id.conversation_checkmark);
@@ -183,6 +185,11 @@
         }
     }
 
+    private void setWorkProfileIcon() {
+        mWorkProfileIconView.setVisibility(
+                mData.isParticipantEnterpriseContact() ? View.VISIBLE : View.GONE);
+    }
+
     private void setConversationName() {
         if (mData.getIsRead() || mData.getShowDraft()) {
             mConversationNameView.setTextColor(mListItemReadColor);
@@ -391,6 +398,7 @@
         setSnippet();
         setConversationName();
         setSubject();
+        setWorkProfileIcon();
         setContentDescription(buildContentDescription(resources, mData,
                 mConversationNameView.getPaint()));