Merge "Fix stream item layout and failing tests"
diff --git a/res/layout/stream_item_container.xml b/res/layout/stream_item_container.xml
index 6fa15b1..ee32596 100644
--- a/res/layout/stream_item_container.xml
+++ b/res/layout/stream_item_container.xml
@@ -50,20 +50,31 @@
             android:layout_height="wrap_content"
             android:textSize="16sp"
             android:textColor="?android:attr/textColorPrimary" />
-        <TextView android:id="@+id/stream_item_attribution"
-            android:layout_width="wrap_content"
+        <!--
+        Attribution (e.g. timestamp) and comments (e.g. +1, like) should align horizontally.
+        Can't merge this with the parent list view.
+        -->
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:textAppearance="?android:attr/textAppearanceSmall"
-            android:textColor="?android:attr/textColorSecondary"
-            android:ellipsize="end"
-            android:maxLines="1" />
-        <TextView android:id="@+id/stream_item_comments"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="@dimen/detail_update_section_attribution_comments_padding"
-            android:textAppearance="?android:attr/textAppearanceSmall"
-            android:textColor="?android:attr/textColorSecondary"
-            android:maxLines="1"/>
+            android:orientation="horizontal"
+            >
+            <TextView android:id="@+id/stream_item_attribution"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceSmall"
+                android:textColor="?android:attr/textColorSecondary"
+                android:ellipsize="end"
+                android:maxLines="1" />
+            <TextView android:id="@+id/stream_item_comments"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft=
+                    "@dimen/detail_update_section_attribution_comments_padding"
+                android:textAppearance="?android:attr/textAppearanceSmall"
+                android:textColor="?android:attr/textColorSecondary"
+                android:maxLines="1"/>
+        </LinearLayout>
     </LinearLayout>
 
     <View
diff --git a/src/com/android/contacts/util/StreamItemEntry.java b/src/com/android/contacts/util/StreamItemEntry.java
index 6c8210f..46684e8 100644
--- a/src/com/android/contacts/util/StreamItemEntry.java
+++ b/src/com/android/contacts/util/StreamItemEntry.java
@@ -141,6 +141,12 @@
         return mPhotos;
     }
 
+    /**
+     * Make {@link #getDecodedText} and {@link #getDecodedComments} available.  Must be called
+     * before calling those.
+     *
+     * We can't do this automatically in the getters, because it'll require a {@link Context}.
+     */
     public void decodeHtml(Context context) {
         final Html.ImageGetter imageGetter = ContactDetailDisplayUtils.getImageGetter(context);
         if (mText != null) {
@@ -152,13 +158,21 @@
     }
 
     public CharSequence getDecodedText() {
+        checkDecoded(mText, mDecodedText);
         return mDecodedText;
     }
 
     public CharSequence getDecodedComments() {
+        checkDecoded(mComments, mDecodedComments);
         return mDecodedComments;
     }
 
+    private static void checkDecoded(CharSequence original, CharSequence decoded) {
+        if (original != null && decoded == null) {
+            throw new IllegalStateException("decodeHtml must have been called");
+        }
+    }
+
     private static String getString(Cursor cursor, String columnName) {
         return cursor.getString(cursor.getColumnIndex(columnName));
     }
diff --git a/tests/src/com/android/contacts/detail/ContactDetailDisplayUtilsTest.java b/tests/src/com/android/contacts/detail/ContactDetailDisplayUtilsTest.java
index fd30390..419cac8 100644
--- a/tests/src/com/android/contacts/detail/ContactDetailDisplayUtilsTest.java
+++ b/tests/src/com/android/contacts/detail/ContactDetailDisplayUtilsTest.java
@@ -51,19 +51,20 @@
     }
 
     public void testAddStreamItemText_IncludesComments() {
-        StreamItemEntry streamItem = getTestBuilder().setComment("1 comment").build();
+        StreamItemEntry streamItem = getTestBuilder().setComment("1 comment").build(getContext());
         View streamItemView = addStreamItemText(streamItem);
         assertHasText(streamItemView, R.id.stream_item_comments, "1 comment");
     }
 
     public void testAddStreamItemText_IncludesHtmlComments() {
-        StreamItemEntry streamItem = getTestBuilder().setComment("1 <b>comment</b>").build();
+        StreamItemEntry streamItem = getTestBuilder().setComment("1 <b>comment</b>")
+                .build(getContext());
         View streamItemView = addStreamItemText(streamItem);
         assertHasHtmlText(streamItemView, R.id.stream_item_comments, "1 <b>comment<b>");
     }
 
     public void testAddStreamItemText_NoComments() {
-        StreamItemEntry streamItem = getTestBuilder().setComment(null).build();
+        StreamItemEntry streamItem = getTestBuilder().setComment(null).build(getContext());
         View streamItemView = addStreamItemText(streamItem);
         assertGone(streamItemView, R.id.stream_item_comments);
     }
diff --git a/tests/src/com/android/contacts/detail/StreamItemAdapterTest.java b/tests/src/com/android/contacts/detail/StreamItemAdapterTest.java
index 131af96..cd2d6bf 100644
--- a/tests/src/com/android/contacts/detail/StreamItemAdapterTest.java
+++ b/tests/src/com/android/contacts/detail/StreamItemAdapterTest.java
@@ -85,7 +85,7 @@
     private ArrayList<StreamItemEntry> createStreamItemList(int count) {
         ArrayList<StreamItemEntry> list = Lists.newArrayList();
         for (int index = 0; index < count; ++index) {
-            list.add(createStreamItemEntryBuilder().build());
+            list.add(createStreamItemEntryBuilder().build(getContext()));
         }
         return list;
     }
diff --git a/tests/src/com/android/contacts/format/SpannedTestUtils.java b/tests/src/com/android/contacts/format/SpannedTestUtils.java
index 646a7ec..ce228a7 100644
--- a/tests/src/com/android/contacts/format/SpannedTestUtils.java
+++ b/tests/src/com/android/contacts/format/SpannedTestUtils.java
@@ -41,7 +41,7 @@
             // If the text is empty, it does not add the <p></p> bits to it.
             Assert.assertEquals("", actualHtmlText);
         } else {
-            Assert.assertEquals("<p>" + expectedHtmlText + "</p>\n", actualHtmlText);
+            Assert.assertEquals("<p dir=ltr>" + expectedHtmlText + "</p>\n", actualHtmlText);
         }
     }
 
diff --git a/tests/src/com/android/contacts/util/StreamItemEntryBuilder.java b/tests/src/com/android/contacts/util/StreamItemEntryBuilder.java
index 319ba48..7fd9307 100644
--- a/tests/src/com/android/contacts/util/StreamItemEntryBuilder.java
+++ b/tests/src/com/android/contacts/util/StreamItemEntryBuilder.java
@@ -16,6 +16,10 @@
 
 package com.android.contacts.util;
 
+import com.android.contacts.util.StreamItemEntry;
+
+import android.content.Context;
+
 /**
  * Builder for {@link StreamItemEntry}s to make writing tests easier.
  */
@@ -58,8 +62,10 @@
         return this;
     }
 
-    public StreamItemEntry build() {
-        return new StreamItemEntry(mId, mText, mComment, mTimestamp, mAccountType, mAccountName,
-                mDataSet, mResPackage, mIconRes, mLabelRes);
+    public StreamItemEntry build(Context context) {
+        StreamItemEntry ret = new StreamItemEntry(mId, mText, mComment, mTimestamp, mAccountType,
+                mAccountName, mDataSet, mResPackage, mIconRes, mLabelRes);
+        ret.decodeHtml(context);
+        return ret;
     }
 }
\ No newline at end of file