Merge "Allowing overriding conversation list load limit." into ub-mail-master
diff --git a/src/com/android/mail/browse/ConversationCursor.java b/src/com/android/mail/browse/ConversationCursor.java
index 7a3ca0f..1b98540 100644
--- a/src/com/android/mail/browse/ConversationCursor.java
+++ b/src/com/android/mail/browse/ConversationCursor.java
@@ -130,7 +130,7 @@
     /** Set when we've sent refreshRequired() to listeners */
     private boolean mRefreshRequired = false;
     /** Whether our first query on this cursor should include a limit */
-    private boolean mInitialConversationLimit = false;
+    private boolean mUseInitialConversationLimit = false;
     /** A list of mostly-dead items */
     private final List<Conversation> mMostlyDead = Lists.newArrayList();
     /** A list of items pending removal from a notification action. These may be undone later.
@@ -187,9 +187,9 @@
         handleNotificationActions();
     }
 
-    public ConversationCursor(Activity activity, Uri uri, boolean initialConversationLimit,
+    public ConversationCursor(Activity activity, Uri uri, boolean useInitialConversationLimit,
             String name) {
-        mInitialConversationLimit = initialConversationLimit;
+        mUseInitialConversationLimit = useInitialConversationLimit;
         mResolver = activity.getApplicationContext().getContentResolver();
         qUri = uri;
         mName = name;
@@ -208,11 +208,11 @@
             try {
                 // Create new ConversationCursor
                 LogUtils.d(LOG_TAG, "Create: initial creation");
-                setCursor(doQuery(mInitialConversationLimit));
+                setCursor(doQuery(mUseInitialConversationLimit));
             } finally {
                 // If we used a limit, queue up a query without limit
-                if (mInitialConversationLimit) {
-                    mInitialConversationLimit = false;
+                if (mUseInitialConversationLimit) {
+                    mUseInitialConversationLimit = false;
                     // We want to notify about this change to allow the UI to requery.  We don't
                     // want to directly call refresh() here as this will start an AyncTask which
                     // is normally only run after the cursor is in the "refresh required"
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 9ec78f0..cf18905 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -177,6 +177,13 @@
     private final String BUNDLE_ACCOUNT_KEY = "account";
     /** Key to store a folder in a bundle */
     private final String BUNDLE_FOLDER_KEY = "folder";
+    /**
+     * Key to set a flag for the ConversationCursorLoader to ignore any
+     * initial load limit that may be set by the Account. Instead,
+     * perform a full load instead of the full-stage load.
+     */
+    private final String BUNDLE_IGNORE_INITIAL_CONVERSATION_LIMIT_KEY =
+            "ignore-initial-conversation-limit";
 
     protected Account mAccount;
     protected Folder mFolder;
@@ -240,6 +247,8 @@
 
     private FolderWatcher mFolderWatcher;
 
+    private boolean mIgnoreInitialConversationLimit;
+
     /**
      * Interface for actions that are deferred until after a load completes. This is for handling
      * user actions which affect cursors (e.g. marking messages read or unread) that happen before
@@ -1042,6 +1051,9 @@
         final Bundle args = new Bundle(2);
         args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
         args.putParcelable(BUNDLE_FOLDER_KEY, mFolder);
+        args.putBoolean(BUNDLE_IGNORE_INITIAL_CONVERSATION_LIMIT_KEY,
+                mIgnoreInitialConversationLimit);
+        mIgnoreInitialConversationLimit = false;
         lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks);
     }
 
@@ -2350,7 +2362,7 @@
 
             final Uri folderUri;
             if (intent.hasExtra(Utils.EXTRA_FOLDER_URI)) {
-                folderUri = (Uri) intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI);
+                folderUri = intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI);
             } else if (intent.hasExtra(Utils.EXTRA_FOLDER)) {
                 final Folder folder =
                         Folder.fromString(intent.getStringExtra(Utils.EXTRA_FOLDER));
@@ -2362,6 +2374,11 @@
                 folderUri = mAccount.settings.defaultInbox;
             }
 
+            // Check if we should load all conversations instead of using
+            // the default behavior which loads an initial subset.
+            mIgnoreInitialConversationLimit =
+                    intent.getBooleanExtra(Utils.EXTRA_IGNORE_INITIAL_CONVERSATION_LIMIT, false);
+
             args.putParcelable(Utils.EXTRA_FOLDER_URI, folderUri);
             args.putParcelable(Utils.EXTRA_CONVERSATION,
                     intent.getParcelableExtra(Utils.EXTRA_CONVERSATION));
@@ -3379,11 +3396,13 @@
         public Loader<ConversationCursor> onCreateLoader(int id, Bundle args) {
             final Account account = args.getParcelable(BUNDLE_ACCOUNT_KEY);
             final Folder folder = args.getParcelable(BUNDLE_FOLDER_KEY);
+            final boolean ignoreInitialConversationLimit =
+                    args.getBoolean(BUNDLE_IGNORE_INITIAL_CONVERSATION_LIMIT_KEY, false);
             if (account == null || folder == null) {
                 return null;
             }
-            return new ConversationCursorLoader((Activity) mActivity, account,
-                    folder.conversationListUri, folder.name);
+            return new ConversationCursorLoader(mActivity, account,
+                    folder.conversationListUri, folder.name, ignoreInitialConversationLimit);
         }
 
         @Override
diff --git a/src/com/android/mail/ui/ConversationCursorLoader.java b/src/com/android/mail/ui/ConversationCursorLoader.java
index 8d9df0b..f91d015 100644
--- a/src/com/android/mail/ui/ConversationCursorLoader.java
+++ b/src/com/android/mail/ui/ConversationCursorLoader.java
@@ -31,7 +31,6 @@
 public class ConversationCursorLoader extends AsyncTaskLoader<ConversationCursor> {
     private static final String TAG = "ConversationCursorLoader";
     private final Uri mUri;
-    private boolean mInitialConversationLimit;
     private final ConversationCursor mConversationCursor;
     private boolean mInit = false;
     private boolean mClosed = false;
@@ -44,15 +43,16 @@
     private static final ArrayList<ConversationCursorLoader> sLoaders =
             new ArrayList<ConversationCursorLoader>();
 
-    public ConversationCursorLoader(Activity activity, Account account, Uri uri, String name) {
+    public ConversationCursorLoader(Activity activity, Account account,
+            Uri uri, String name, boolean ignoreInitialConversationLimit) {
         super(activity);
         mUri = uri;
         mName = name;
-        mInitialConversationLimit =
+        final boolean useInitialConversationLimit = ignoreInitialConversationLimit ? false :
                 account.supportsCapability(AccountCapabilities.INITIAL_CONVERSATION_LIMIT);
         // Initialize the state of the conversation cursor
         mConversationCursor = new ConversationCursor(
-                activity, mUri, mInitialConversationLimit, name);
+                activity, mUri, useInitialConversationLimit, name);
         addLoader();
     }
 
diff --git a/src/com/android/mail/utils/Utils.java b/src/com/android/mail/utils/Utils.java
index 4994c17..ae9f3ea 100644
--- a/src/com/android/mail/utils/Utils.java
+++ b/src/com/android/mail/utils/Utils.java
@@ -16,7 +16,6 @@
 
 package com.android.mail.utils;
 
-import android.annotation.SuppressLint;
 import android.annotation.TargetApi;
 import android.app.Activity;
 import android.app.ActivityManager;
@@ -99,6 +98,8 @@
     public static final String EXTRA_COMPOSE_URI = "composeUri";
     public static final String EXTRA_CONVERSATION = "conversationUri";
     public static final String EXTRA_FROM_NOTIFICATION = "notification";
+    public static final String EXTRA_IGNORE_INITIAL_CONVERSATION_LIMIT =
+            "ignore-initial-conversation-limit";
 
     private static final String MAILTO_SCHEME = "mailto";