Use ConversationCursor directly in the Controller, and check for null

Fixes b/6357409

Change-Id: I24b6bbbc4d5d5144c13c7568f2c5f0f7999f9808
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index c9e5be2..6ec18c4 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -264,7 +264,7 @@
     }
 
     @Override
-    public ConversationCursor getConversationListCursor() {
+    public final ConversationCursor getConversationListCursor() {
         return mConversationListCursor;
     }
 
@@ -1464,8 +1464,8 @@
         long now = System.currentTimeMillis();
         long sinceLastRefresh = now - mConversationListRefreshTime;
 //        if (sinceLastRefresh > CONVERSATION_LIST_THROTTLE_MS) {
-            if (getConversationListCursor().isRefreshRequired()) {
-                getConversationListCursor().refresh();
+            if (mConversationListCursor.isRefreshRequired()) {
+                mConversationListCursor.refresh();
                 mTracker.updateCursor(mConversationListCursor);
                 mConversationListRefreshTime = now;
             }
@@ -1559,11 +1559,10 @@
     public void onScrollStateChanged(AbsListView view, int scrollState) {
         boolean isScrolling = (scrollState != OnScrollListener.SCROLL_STATE_IDLE);
         if (!isScrolling) {
-            ConversationCursor cc = getConversationListCursor();
-            if (cc.isRefreshRequired()) {
+            if (mConversationListCursor.isRefreshRequired()) {
                 LogUtils.d(LOG_TAG, "Stop scrolling: refresh");
-                cc.refresh();
-            } else if (cc.isRefreshReady()) {
+                mConversationListCursor.refresh();
+            } else if (mConversationListCursor.isRefreshReady()) {
                 LogUtils.d(LOG_TAG, "Stop scrolling: try sync");
                 onRefreshReady();
             }
@@ -1622,7 +1621,7 @@
 
     @Override
     public void performAction() {
-        if (getConversationListCursor().isRefreshReady()) {
+        if (mConversationListCursor != null && mConversationListCursor.isRefreshReady()) {
             refreshAdapter();
         }
     }
@@ -1774,13 +1773,12 @@
     public void sendConversationRead(String toFragment, Conversation conversation, boolean state,
             boolean local) {
         if (toFragment.equals(TAG_CONVERSATION_LIST)) {
-            ConversationCursor cc = getConversationListCursor();
-            if (cc != null) {
+            if (mConversationListCursor != null) {
                 if (local) {
-                    cc.setConversationColumn(conversation.uri.toString(), ConversationColumns.READ,
+                    mConversationListCursor.setConversationColumn(conversation.uri.toString(), ConversationColumns.READ,
                             state);
                 } else {
-                    cc.markRead(mContext, state, conversation);
+                    mConversationListCursor.markRead(mContext, state, conversation);
                 }
             }
         } else if (toFragment.equals(TAG_CONVERSATION)) {
@@ -1792,12 +1790,11 @@
     public void sendConversationUriStarred(String toFragment, String conversationUri,
             boolean state, boolean local) {
         if (toFragment.equals(TAG_CONVERSATION_LIST)) {
-            ConversationCursor cc = getConversationListCursor();
-            if (cc != null) {
+            if (mConversationListCursor != null) {
                 if (local) {
-                    cc.setConversationColumn(conversationUri, ConversationColumns.STARRED, state);
+                    mConversationListCursor.setConversationColumn(conversationUri, ConversationColumns.STARRED, state);
                 } else {
-                    cc.updateBoolean(mContext, conversationUri, ConversationColumns.STARRED, state);
+                    mConversationListCursor.updateBoolean(mContext, conversationUri, ConversationColumns.STARRED, state);
                 }
             }
         } else if (toFragment.equals(TAG_CONVERSATION)) {