fix conversation read/unread edge cases

A re-render should mark new messages read, if there are any.
* on rotate, all messages will stay read, so nothing will
  happen in that case

A re-render should not clear 'unread' state as far as
"mark unread", i.e. "New message from X" -> tap -> re-render
-> mark unread -> should mark ALL unread messages unread, not
just new ones.

Bug: 7026808
Change-Id: I4693481a0a3e6d89380f9d16fd8591ba179896b2
diff --git a/src/com/android/mail/ui/ConversationViewFragment.java b/src/com/android/mail/ui/ConversationViewFragment.java
index 1d0c692..8ea082e 100644
--- a/src/com/android/mail/ui/ConversationViewFragment.java
+++ b/src/com/android/mail/ui/ConversationViewFragment.java
@@ -618,7 +618,9 @@
 
             // save off "read" state from the cursor
             // later, the view may not match the cursor (e.g. conversation marked read on open)
-            mViewState.setReadState(msg, msg.read);
+            // however, if a previous state indicated this message was unread, trust that instead
+            // so "mark unread" marks all originally unread messages
+            mViewState.setReadState(msg, msg.read && !prevState.isUnread(msg));
 
             // We only want to consider this for inclusion in the super collapsed block if
             // 1) The we don't have previous state about this message  (The first time that the
@@ -756,10 +758,11 @@
 
         mViewState.setInfoForConversation(mConversation);
 
-        // mark viewed if not previously marked viewed by this conversation view
-        // ('mark read', if necessary, will also happen there)
+        // mark viewed/read if not previously marked viewed by this conversation view,
+        // or if unread messages still exist in the message list cursor
         // we don't want to keep marking viewed on rotation or restore
-        if (!mConversation.isViewed()) {
+        // but we do want future re-renders to mark read (e.g. "New message from X" case)
+        if (!mConversation.isViewed() || (mCursor != null && !mCursor.isConversationRead())) {
             final ConversationUpdater listController = activity.getConversationUpdater();
             // The conversation cursor may not have finished loading by now (when launched via
             // notification), so watch for when it finishes and mark it read then.