Remove StreamIteams from loader and disable social updates from UI.

Bug: 10328519
Change-Id: I7df4d66ed3297f38b187fa9f3091bcfc3d4466b9
diff --git a/src/com/android/contacts/activities/ContactDetailActivity.java b/src/com/android/contacts/activities/ContactDetailActivity.java
index 237e387..0f793e2 100644
--- a/src/com/android/contacts/activities/ContactDetailActivity.java
+++ b/src/com/android/contacts/activities/ContactDetailActivity.java
@@ -55,9 +55,6 @@
 public class ContactDetailActivity extends ContactsActivity {
     private static final String TAG = "ContactDetailActivity";
 
-    /** Shows a toogle button for hiding/showing updates. Don't submit with true */
-    private static final boolean DEBUG_TRANSITIONS = false;
-
     private Contact mContactData;
     private Uri mLookupUri;
 
@@ -126,19 +123,6 @@
         super.onCreateOptionsMenu(menu);
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.star, menu);
-        if (DEBUG_TRANSITIONS) {
-            final MenuItem toggleSocial =
-                    menu.add(mLoaderFragment.getLoadStreamItems() ? "less" : "more");
-            toggleSocial.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-            toggleSocial.setOnMenuItemClickListener(new OnMenuItemClickListener() {
-                @Override
-                public boolean onMenuItemClick(MenuItem item) {
-                    mLoaderFragment.toggleLoadStreamItems();
-                    invalidateOptionsMenu();
-                    return false;
-                }
-            });
-        }
         return true;
     }
 
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 80d5885..6a8cf4c 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -109,9 +109,6 @@
 
     private static final String TAG = "PeopleActivity";
 
-    /** Shows a toogle button for hiding/showing updates. Don't submit with true */
-    private static final boolean DEBUG_TRANSITIONS = false;
-
     private static final int TAB_FADE_IN_DURATION = 500;
 
     private static final String ENABLE_DEBUG_OPTIONS_HIDDEN_CODE = "debug debug!";
@@ -1376,20 +1373,6 @@
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.people_options, menu);
 
-        if (DEBUG_TRANSITIONS && mContactDetailLoaderFragment != null) {
-            final MenuItem toggleSocial =
-                    menu.add(mContactDetailLoaderFragment.getLoadStreamItems() ? "less" : "more");
-            toggleSocial.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
-            toggleSocial.setOnMenuItemClickListener(new OnMenuItemClickListener() {
-                @Override
-                public boolean onMenuItemClick(MenuItem item) {
-                    mContactDetailLoaderFragment.toggleLoadStreamItems();
-                    invalidateOptionsMenu();
-                    return false;
-                }
-            });
-        }
-
         return true;
     }
 
diff --git a/src/com/android/contacts/detail/ContactLoaderFragment.java b/src/com/android/contacts/detail/ContactLoaderFragment.java
index 0d4285f..5f5a137 100644
--- a/src/com/android/contacts/detail/ContactLoaderFragment.java
+++ b/src/com/android/contacts/detail/ContactLoaderFragment.java
@@ -186,8 +186,8 @@
         public Loader<Contact> onCreateLoader(int id, Bundle args) {
             Uri lookupUri = args.getParcelable(LOADER_ARG_CONTACT_URI);
             return new ContactLoader(mContext, lookupUri, true /* loadGroupMetaData */,
-                    true /* loadStreamItems */, true /* load invitable account types */,
-                    true /* postViewNotification */, true /* computeFormattedPhoneNumber */);
+                    true /* load invitable account types */, true /* postViewNotification */,
+                    true /* computeFormattedPhoneNumber */);
         }
 
         @Override
@@ -467,18 +467,4 @@
                 mContext, mLookupUri, mCustomRingtone);
         mContext.startService(intent);
     }
-
-    /** Toggles whether to load stream items. Just for debugging */
-    public void toggleLoadStreamItems() {
-        Loader<Contact> loaderObj = getLoaderManager().getLoader(LOADER_DETAILS);
-        ContactLoader loader = (ContactLoader) loaderObj;
-        loader.setLoadStreamItems(!loader.getLoadStreamItems());
-    }
-
-    /** Returns whether to load stream items. Just for debugging */
-    public boolean getLoadStreamItems() {
-        Loader<Contact> loaderObj = getLoaderManager().getLoader(LOADER_DETAILS);
-        ContactLoader loader = (ContactLoader) loaderObj;
-        return loader != null && loader.getLoadStreamItems();
-    }
 }
diff --git a/src/com/android/contacts/model/Contact.java b/src/com/android/contacts/model/Contact.java
index 0314c3c..9f7f217 100644
--- a/src/com/android/contacts/model/Contact.java
+++ b/src/com/android/contacts/model/Contact.java
@@ -33,6 +33,7 @@
 import com.google.common.collect.ImmutableMap;
 
 import java.util.ArrayList;
+import java.util.Collections;
 
 /**
  * A Contact represents a single person or logical entity as perceived by the user.  The information
@@ -72,7 +73,6 @@
     private final boolean mStarred;
     private final Integer mPresence;
     private ImmutableList<RawContact> mRawContacts;
-    private ImmutableList<StreamItemEntry> mStreamItems;
     private ImmutableMap<Long,DataStatus> mStatuses;
     private ImmutableList<AccountType> mInvitableAccountTypes;
 
@@ -108,7 +108,6 @@
         mLookupKey = null;
         mId = -1;
         mRawContacts = null;
-        mStreamItems = null;
         mStatuses = null;
         mNameRawContactId = -1;
         mDisplayNameSource = DisplayNameSources.UNDEFINED;
@@ -150,7 +149,6 @@
         mLookupKey = lookupKey;
         mId = id;
         mRawContacts = null;
-        mStreamItems = null;
         mStatuses = null;
         mNameRawContactId = nameRawContactId;
         mDisplayNameSource = displayNameSource;
@@ -187,7 +185,6 @@
         mStarred = from.mStarred;
         mPresence = from.mPresence;
         mRawContacts = from.mRawContacts;
-        mStreamItems = from.mStreamItems;
         mStatuses = from.mStatuses;
         mInvitableAccountTypes = from.mInvitableAccountTypes;
 
@@ -354,7 +351,7 @@
      * @return
      */
     public ImmutableList<StreamItemEntry> getStreamItems() {
-        return mStreamItems;
+        return ImmutableList.of();
     }
 
     public ImmutableMap<Long, DataStatus> getStatuses() {
@@ -484,8 +481,4 @@
     /* package */ void setGroupMetaData(ImmutableList<GroupMetaData> groups) {
         mGroups = groups;
     }
-
-    /* package */ void setStreamItems(ImmutableList<StreamItemEntry> streamItems) {
-        mStreamItems = streamItems;
-    }
 }
diff --git a/src/com/android/contacts/model/ContactLoader.java b/src/com/android/contacts/model/ContactLoader.java
index 3c1fc9d..c780f23 100644
--- a/src/com/android/contacts/model/ContactLoader.java
+++ b/src/com/android/contacts/model/ContactLoader.java
@@ -82,7 +82,6 @@
     private final Uri mRequestedUri;
     private Uri mLookupUri;
     private boolean mLoadGroupMetaData;
-    private boolean mLoadStreamItems;
     private boolean mLoadInvitableAccountTypes;
     private boolean mPostViewNotification;
     private boolean mComputeFormattedPhoneNumber;
@@ -91,17 +90,16 @@
     private final Set<Long> mNotifiedRawContactIds = Sets.newHashSet();
 
     public ContactLoader(Context context, Uri lookupUri, boolean postViewNotification) {
-        this(context, lookupUri, false, false, false, postViewNotification, false);
+        this(context, lookupUri, false, false, postViewNotification, false);
     }
 
     public ContactLoader(Context context, Uri lookupUri, boolean loadGroupMetaData,
-            boolean loadStreamItems, boolean loadInvitableAccountTypes,
+            boolean loadInvitableAccountTypes,
             boolean postViewNotification, boolean computeFormattedPhoneNumber) {
         super(context);
         mLookupUri = lookupUri;
         mRequestedUri = lookupUri;
         mLoadGroupMetaData = loadGroupMetaData;
-        mLoadStreamItems = loadStreamItems;
         mLoadInvitableAccountTypes = loadInvitableAccountTypes;
         mPostViewNotification = postViewNotification;
         mComputeFormattedPhoneNumber = computeFormattedPhoneNumber;
@@ -331,9 +329,6 @@
                         loadGroupMetaData(result);
                     }
                 }
-                if (mLoadStreamItems && result.getStreamItems() == null) {
-                    loadStreamItems(result);
-                }
                 if (mComputeFormattedPhoneNumber) {
                     computeFormattedPhoneNumbers(result);
                 }
@@ -711,95 +706,6 @@
     }
 
     /**
-     * Loads all stream items and stream item photos belonging to this contact.
-     */
-    private void loadStreamItems(Contact result) {
-        final Cursor cursor = getContext().getContentResolver().query(
-                Contacts.CONTENT_LOOKUP_URI.buildUpon()
-                        .appendPath(result.getLookupKey())
-                        .appendPath(Contacts.StreamItems.CONTENT_DIRECTORY).build(),
-                null, null, null, null);
-        final LongSparseArray<StreamItemEntry> streamItemsById =
-                new LongSparseArray<StreamItemEntry>();
-        final ArrayList<StreamItemEntry> streamItems = new ArrayList<StreamItemEntry>();
-        try {
-            while (cursor.moveToNext()) {
-                StreamItemEntry streamItem = new StreamItemEntry(cursor);
-                streamItemsById.put(streamItem.getId(), streamItem);
-                streamItems.add(streamItem);
-            }
-        } finally {
-            cursor.close();
-        }
-
-        // Pre-decode all HTMLs
-        final long start = System.currentTimeMillis();
-        for (StreamItemEntry streamItem : streamItems) {
-            streamItem.decodeHtml(getContext());
-        }
-        final long end = System.currentTimeMillis();
-        if (DEBUG) {
-            Log.d(TAG, "Decoded HTML for " + streamItems.size() + " items, took "
-                    + (end - start) + " ms");
-        }
-
-        // Now retrieve any photo records associated with the stream items.
-        if (!streamItems.isEmpty()) {
-            if (result.isUserProfile()) {
-                // If the stream items we're loading are for the profile, we can't bulk-load the
-                // stream items with a custom selection.
-                for (StreamItemEntry entry : streamItems) {
-                    Cursor siCursor = getContext().getContentResolver().query(
-                            Uri.withAppendedPath(
-                                    ContentUris.withAppendedId(
-                                            StreamItems.CONTENT_URI, entry.getId()),
-                                    StreamItems.StreamItemPhotos.CONTENT_DIRECTORY),
-                            null, null, null, null);
-                    try {
-                        while (siCursor.moveToNext()) {
-                            entry.addPhoto(new StreamItemPhotoEntry(siCursor));
-                        }
-                    } finally {
-                        siCursor.close();
-                    }
-                }
-            } else {
-                String[] streamItemIdArr = new String[streamItems.size()];
-                StringBuilder streamItemPhotoSelection = new StringBuilder();
-                streamItemPhotoSelection.append(StreamItemPhotos.STREAM_ITEM_ID + " IN (");
-                for (int i = 0; i < streamItems.size(); i++) {
-                    if (i > 0) {
-                        streamItemPhotoSelection.append(",");
-                    }
-                    streamItemPhotoSelection.append("?");
-                    streamItemIdArr[i] = String.valueOf(streamItems.get(i).getId());
-                }
-                streamItemPhotoSelection.append(")");
-                Cursor sipCursor = getContext().getContentResolver().query(
-                        StreamItems.CONTENT_PHOTO_URI,
-                        null, streamItemPhotoSelection.toString(), streamItemIdArr,
-                        StreamItemPhotos.STREAM_ITEM_ID);
-                try {
-                    while (sipCursor.moveToNext()) {
-                        long streamItemId = sipCursor.getLong(
-                                sipCursor.getColumnIndex(StreamItemPhotos.STREAM_ITEM_ID));
-                        StreamItemEntry streamItem = streamItemsById.get(streamItemId);
-                        streamItem.addPhoto(new StreamItemPhotoEntry(sipCursor));
-                    }
-                } finally {
-                    sipCursor.close();
-                }
-            }
-        }
-
-        // Set the sorted stream items on the result.
-        Collections.sort(streamItems);
-        result.setStreamItems(new ImmutableList.Builder<StreamItemEntry>()
-                .addAll(streamItems.iterator())
-                .build());
-    }
-
-    /**
      * Iterates over all data items that represent phone numbers are tries to calculate a formatted
      * number. This function can safely be called several times as no unformatted data is
      * overwritten
@@ -892,28 +798,16 @@
     }
 
     /**
-     * Sets whether to load stream items. Will trigger a reload if the value has changed.
-     * At the moment, this is only used for debugging purposes
-     */
-    public void setLoadStreamItems(boolean value) {
-        if (mLoadStreamItems != value) {
-            mLoadStreamItems = value;
-            onContentChanged();
-        }
-    }
-
-    /**
      * Fully upgrades this ContactLoader to one with all lists fully loaded. When done, the
      * new result will be delivered
      */
     public void upgradeToFullContact() {
         // Everything requested already? Nothing to do, so let's bail out
-        if (mLoadGroupMetaData && mLoadInvitableAccountTypes && mLoadStreamItems
+        if (mLoadGroupMetaData && mLoadInvitableAccountTypes
                 && mPostViewNotification && mComputeFormattedPhoneNumber) return;
 
         mLoadGroupMetaData = true;
         mLoadInvitableAccountTypes = true;
-        mLoadStreamItems = true;
         mPostViewNotification = true;
         mComputeFormattedPhoneNumber = true;
 
@@ -925,10 +819,6 @@
         onContentChanged();
     }
 
-    public boolean getLoadStreamItems() {
-        return mLoadStreamItems;
-    }
-
     public Uri getLookupUri() {
         return mLookupUri;
     }
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 79a71d7..c1cfb55 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -585,9 +585,8 @@
                 Log.wtf(TAG, "Lookup uri wasn't initialized. Loader was started too early");
             }
             return new ContactLoader(getApplicationContext(), mLookupUri,
-                    false /*loadGroupMetaData*/, false /*loadStreamItems*/,
-                    false /*loadInvitableAccountTypes*/, false /*postViewNotification*/,
-                    true /*computeFormattedPhoneNumber*/);
+                    false /*loadGroupMetaData*/, false /*loadInvitableAccountTypes*/,
+                    false /*postViewNotification*/, true /*computeFormattedPhoneNumber*/);
         }
     };
 
diff --git a/src/com/android/contacts/socialwidget/SocialWidgetProvider.java b/src/com/android/contacts/socialwidget/SocialWidgetProvider.java
index 40c29b9..e8b8e03 100644
--- a/src/com/android/contacts/socialwidget/SocialWidgetProvider.java
+++ b/src/com/android/contacts/socialwidget/SocialWidgetProvider.java
@@ -113,7 +113,7 @@
             // Not yet set-up (this can happen while the Configuration activity is visible)
             return;
         }
-        final ContactLoader contactLoader = new ContactLoader(context, contactUri, false, true,
+        final ContactLoader contactLoader = new ContactLoader(context, contactUri, false,
                 false, true, false);
         contactLoader.registerListener(0,
                 new ContactLoader.OnLoadCompleteListener<Contact>() {