Fix view state when resuming from search

Added check to onResume such that when we resume and the cursor is
not ready, we should essentially treat it like onCreate and set the
appropriate flags and the default view state. Previously, the fragment's
cursor gets cleared when we perform a search, thus when we resume from
search, we see the empty state for a little bit before the cursor loads
the actual data.

b/14461247

Change-Id: I5f9124179e710631aa76b414dd1fec3c4d670138
diff --git a/src/com/android/mail/ui/ConversationListFragment.java b/src/com/android/mail/ui/ConversationListFragment.java
index 7d6b812..6f057aa 100644
--- a/src/com/android/mail/ui/ConversationListFragment.java
+++ b/src/com/android/mail/ui/ConversationListFragment.java
@@ -656,6 +656,13 @@
         super.onResume();
 
         final ConversationCursor conversationCursor = getConversationListCursor();
+        if (!isCursorReadyToShow(conversationCursor)) {
+            mInitialCursorLoading = true;
+
+            // Let's show the list view when we resume and are waiting for load again
+            showListView();
+        }
+
         if (conversationCursor != null) {
             conversationCursor.handleNotificationActions();
 
@@ -1148,10 +1155,7 @@
                 // completed loading.
                 // Use this point to log the appropriate timing information that depends on when
                 // the conversation list view finishes loading
-                final int cursorStatus = newCursor.getExtras().getInt(
-                        UIProvider.CursorExtraKeys.EXTRA_STATUS);
-                if (newCursor.getCount() > 0 ||
-                        !UIProvider.CursorStatus.isWaitingForResults(cursorStatus)) {
+                if (isCursorReadyToShow(newCursor)) {
                     if (newCursor.getCount() == 0) {
                         Analytics.getInstance().sendEvent("empty_state", "post_label_change",
                                 mFolder.getTypeDescription(), 0);
@@ -1183,4 +1187,18 @@
             mConversationCursorLastCount = 0;
         }
     }
+
+    /**
+     * Helper function to determine if the given cursor is ready to populate the UI
+     * @param cursor
+     * @return
+     */
+    private boolean isCursorReadyToShow(ConversationCursor cursor) {
+        if (cursor == null) {
+            return false;
+        }
+        final int status = cursor.getExtras().getInt(
+                UIProvider.CursorExtraKeys.EXTRA_STATUS);
+        return (cursor.getCount() > 0 || !UIProvider.CursorStatus.isWaitingForResults(status));
+    }
 }