am 0de263dd: Merge "Mark messages seen when we view a conversation list" into jb-ub-mail-ur9

* commit '0de263ddfcfe59b60bf24dd62b159df58c863128':
  Mark messages seen when we view a conversation list
diff --git a/src/com/android/mail/browse/ConversationCursor.java b/src/com/android/mail/browse/ConversationCursor.java
index f47f7fd..b3c9f79 100644
--- a/src/com/android/mail/browse/ConversationCursor.java
+++ b/src/com/android/mail/browse/ConversationCursor.java
@@ -74,7 +74,7 @@
  * caching for quick UI response. This is effectively a singleton class, as the cache is
  * implemented as a static HashMap.
  */
-public final class ConversationCursor implements Cursor {
+public final class ConversationCursor implements Cursor, ConversationCursorMarkSeenListener {
 
     private static final boolean ENABLE_CONVERSATION_PRECACHING = true;
 
@@ -2101,4 +2101,12 @@
             });
         }
     }
+
+    /**
+     * Marks all contents of this cursor as seen. This may have no effect with certain providers.
+     */
+    @Override
+    public void markContentsSeen() {
+        ConversationCursorMarkSeenListener.MarkSeenHelper.markContentsSeen(mUnderlyingCursor);
+    }
 }
diff --git a/src/com/android/mail/browse/ConversationCursorMarkSeenListener.java b/src/com/android/mail/browse/ConversationCursorMarkSeenListener.java
new file mode 100644
index 0000000..0956859
--- /dev/null
+++ b/src/com/android/mail/browse/ConversationCursorMarkSeenListener.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ *      Copyright (C) 2013 Google Inc.
+ *      Licensed to The Android Open Source Project.
+ *
+ *      Licensed under the Apache License, Version 2.0 (the "License");
+ *      you may not use this file except in compliance with the License.
+ *      You may obtain a copy of the License at
+ *
+ *           http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *      Unless required by applicable law or agreed to in writing, software
+ *      distributed under the License is distributed on an "AS IS" BASIS,
+ *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *      See the License for the specific language governing permissions and
+ *      limitations under the License.
+ *******************************************************************************/
+package com.android.mail.browse;
+
+import android.database.Cursor;
+import android.database.CursorWrapper;
+
+public interface ConversationCursorMarkSeenListener {
+    /**
+     * Marks all contents of this cursor as seen.
+     */
+    void markContentsSeen();
+
+    public class MarkSeenHelper {
+        /**
+         * Invokes {@link ConversationCursorMarkSeenListener#markContentsSeen(Cursor)} on the
+         * specified {@link Cursor}, recursively calls {@link #markContentsSeen(Cursor)} on a
+         * wrapped cursor, or returns.
+         */
+        public static void markContentsSeen(final Cursor cursor) {
+            if (cursor == null) {
+                return;
+            }
+
+            if (cursor instanceof ConversationCursorMarkSeenListener) {
+                ((ConversationCursorMarkSeenListener) cursor).markContentsSeen();
+            } else if (cursor instanceof CursorWrapper) {
+                markContentsSeen(((CursorWrapper) cursor).getWrappedCursor());
+            }
+        }
+    }
+}
diff --git a/src/com/android/mail/ui/ConversationListFragment.java b/src/com/android/mail/ui/ConversationListFragment.java
index e0f2fd3..12d2087 100644
--- a/src/com/android/mail/ui/ConversationListFragment.java
+++ b/src/com/android/mail/ui/ConversationListFragment.java
@@ -790,6 +790,11 @@
             mListAdapter.notifyDataSetChanged();
         }
         mConversationCursorHash = newCursorHash;
+
+        if (newCursor != null) {
+            newCursor.markContentsSeen();
+        }
+
         // If a current conversation is available, and none is selected in the list, then ask
         // the list to select the current conversation.
         final Conversation conv = mCallbacks.getCurrentConversation();