am 7330fe49
: Merge branch \'readonly-p4-donut\' into donut
Merge commit '7330fe4953c39741376bdd8cb3e5c2c03068b0aa' * commit '7330fe4953c39741376bdd8cb3e5c2c03068b0aa': AI 149573: Display To: instead of From: in Drafts folder && Display unread message count for inbox, total message count everywhere else.
This commit is contained in:
commit
18106fe981
@ -33,6 +33,7 @@ import com.android.email.mail.Message;
|
|||||||
import com.android.email.mail.MessagingException;
|
import com.android.email.mail.MessagingException;
|
||||||
import com.android.email.mail.Message.RecipientType;
|
import com.android.email.mail.Message.RecipientType;
|
||||||
import com.android.email.mail.store.LocalStore;
|
import com.android.email.mail.store.LocalStore;
|
||||||
|
import com.android.email.mail.store.LocalStore.LocalFolder;
|
||||||
import com.android.email.mail.store.LocalStore.LocalMessage;
|
import com.android.email.mail.store.LocalStore.LocalMessage;
|
||||||
|
|
||||||
import android.app.ExpandableListActivity;
|
import android.app.ExpandableListActivity;
|
||||||
@ -126,6 +127,8 @@ public class FolderMessageList extends ExpandableListActivity {
|
|||||||
R.drawable.appointment_indicator_leftside_21,
|
R.drawable.appointment_indicator_leftside_21,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final Flag[] DELETED_FLAG = new Flag[] { Flag.DELETED };
|
||||||
|
|
||||||
private ExpandableListView mListView;
|
private ExpandableListView mListView;
|
||||||
private int colorChipResId;
|
private int colorChipResId;
|
||||||
|
|
||||||
@ -687,7 +690,7 @@ public class FolderMessageList extends ExpandableListActivity {
|
|||||||
mHandler.dataChanged();
|
mHandler.dataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (folder.name.equals(mAccount.getDraftsFolderName())) {
|
if (folder.drafts) {
|
||||||
MessageCompose.actionEditDraft(this, mAccount, message.message);
|
MessageCompose.actionEditDraft(this, mAccount, message.message);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1052,6 +1055,27 @@ public class FolderMessageList extends ExpandableListActivity {
|
|||||||
mAttachmentIcon = getResources().getDrawable(R.drawable.ic_mms_attachment_small);
|
mAttachmentIcon = getResources().getDrawable(R.drawable.ic_mms_attachment_small);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set special folder boolean indicator in FolderInfoHolder
|
||||||
|
*/
|
||||||
|
private void setSpecialFolderIndicator(FolderInfoHolder holder) {
|
||||||
|
String folderName = holder.name;
|
||||||
|
holder.special = true;
|
||||||
|
if (folderName.equalsIgnoreCase(Email.INBOX)) {
|
||||||
|
holder.inbox = true;
|
||||||
|
} else if (folderName.equals(mAccount.getDraftsFolderName())) {
|
||||||
|
holder.drafts = true;
|
||||||
|
} else if (folderName.equals(mAccount.getOutboxFolderName())) {
|
||||||
|
holder.outbox = true;
|
||||||
|
} else if (folderName.equals(mAccount.getSentFolderName())) {
|
||||||
|
holder.sent = true;
|
||||||
|
} else if (folderName.equals(mAccount.getTrashFolderName())) {
|
||||||
|
holder.trash = true;
|
||||||
|
} else {
|
||||||
|
holder.special = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This code is invoked (in the UI thread) in response to a listFolders() callback
|
* This code is invoked (in the UI thread) in response to a listFolders() callback
|
||||||
* into the MessageListener.
|
* into the MessageListener.
|
||||||
@ -1070,15 +1094,14 @@ public class FolderMessageList extends ExpandableListActivity {
|
|||||||
else {
|
else {
|
||||||
holder.displayName = folder.getName();
|
holder.displayName = folder.getName();
|
||||||
}
|
}
|
||||||
if (holder.name.equals(mAccount.getOutboxFolderName())) {
|
setSpecialFolderIndicator(holder);
|
||||||
holder.outbox = true;
|
|
||||||
}
|
|
||||||
if (holder.messages == null) {
|
if (holder.messages == null) {
|
||||||
holder.messages = new ArrayList<MessageInfoHolder>();
|
holder.messages = new ArrayList<MessageInfoHolder>();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
folder.open(Folder.OpenMode.READ_WRITE, null);
|
folder.open(Folder.OpenMode.READ_WRITE, null);
|
||||||
holder.messageCount = folder.getMessageCount();
|
holder.messageCount = ((LocalFolder) folder)
|
||||||
|
.getMessageCount(null, DELETED_FLAG);
|
||||||
holder.unreadMessageCount = folder.getUnreadMessageCount();
|
holder.unreadMessageCount = folder.getUnreadMessageCount();
|
||||||
folder.close(false);
|
folder.close(false);
|
||||||
}
|
}
|
||||||
@ -1250,11 +1273,11 @@ public class FolderMessageList extends ExpandableListActivity {
|
|||||||
holder.folderStatus.setVisibility(View.VISIBLE);
|
holder.folderStatus.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!folder.outbox && folder.unreadMessageCount != 0) {
|
if ((folder.inbox || !folder.special) && folder.unreadMessageCount != 0) {
|
||||||
holder.newMessageCount.setText(Integer.toString(folder.unreadMessageCount));
|
holder.newMessageCount.setText(Integer.toString(folder.unreadMessageCount));
|
||||||
holder.newMessageCount.setVisibility(View.VISIBLE);
|
holder.newMessageCount.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
else if (folder.outbox && folder.messageCount > 0) {
|
else if ((folder.outbox || folder.drafts) && folder.messageCount > 0) {
|
||||||
holder.newMessageCount.setText(Integer.toString(folder.messageCount));
|
holder.newMessageCount.setText(Integer.toString(folder.messageCount));
|
||||||
holder.newMessageCount.setVisibility(View.VISIBLE);
|
holder.newMessageCount.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
@ -1413,9 +1436,14 @@ public class FolderMessageList extends ExpandableListActivity {
|
|||||||
public boolean lastCheckFailed;
|
public boolean lastCheckFailed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Outbox is handled differently from any other folder.
|
* Special folder indicator.
|
||||||
*/
|
*/
|
||||||
|
public boolean special; // One of the following five folders.
|
||||||
|
public boolean inbox;
|
||||||
|
public boolean drafts;
|
||||||
public boolean outbox;
|
public boolean outbox;
|
||||||
|
public boolean sent;
|
||||||
|
public boolean trash;
|
||||||
|
|
||||||
public int compareTo(FolderInfoHolder o) {
|
public int compareTo(FolderInfoHolder o) {
|
||||||
String s1 = this.name;
|
String s1 = this.name;
|
||||||
@ -1465,7 +1493,7 @@ public class FolderMessageList extends ExpandableListActivity {
|
|||||||
}
|
}
|
||||||
this.hasAttachments = message.getAttachmentCount() > 0;
|
this.hasAttachments = message.getAttachmentCount() > 0;
|
||||||
this.read = message.isSet(Flag.SEEN);
|
this.read = message.isSet(Flag.SEEN);
|
||||||
if (folder.outbox) {
|
if (folder.outbox || folder.drafts || folder.sent) {
|
||||||
this.sender = Address.toFriendly(
|
this.sender = Address.toFriendly(
|
||||||
message.getRecipients(RecipientType.TO));
|
message.getRecipients(RecipientType.TO));
|
||||||
}
|
}
|
||||||
|
@ -651,10 +651,28 @@ public class LocalStore extends Store implements PersistentDataCallbacks {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMessageCount() throws MessagingException {
|
public int getMessageCount() throws MessagingException {
|
||||||
|
return getMessageCount(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return number of messages based on the state of the flags.
|
||||||
|
*
|
||||||
|
* @param setFlags The flags that should be set for a message to be selected (null ok)
|
||||||
|
* @param clearFlags The flags that should be clear for a message to be selected (null ok)
|
||||||
|
* @return The number of messages matching the desired flag states.
|
||||||
|
* @throws MessagingException
|
||||||
|
*/
|
||||||
|
public int getMessageCount(Flag[] setFlags, Flag[] clearFlags) throws MessagingException {
|
||||||
|
// Generate WHERE clause based on flags observed
|
||||||
|
StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM messages WHERE ");
|
||||||
|
buildFlagPredicates(sql, setFlags, clearFlags);
|
||||||
|
sql.append("messages.folder_id = ?");
|
||||||
|
|
||||||
open(OpenMode.READ_WRITE);
|
open(OpenMode.READ_WRITE);
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = mDb.rawQuery("SELECT COUNT(*) FROM messages WHERE messages.folder_id = ?",
|
cursor = mDb.rawQuery(
|
||||||
|
sql.toString(),
|
||||||
new String[] {
|
new String[] {
|
||||||
Long.toString(mFolderId)
|
Long.toString(mFolderId)
|
||||||
});
|
});
|
||||||
@ -1007,6 +1025,39 @@ public class LocalStore extends Store implements PersistentDataCallbacks {
|
|||||||
"SELECT " + POPULATE_MESSAGE_SELECT_COLUMNS +
|
"SELECT " + POPULATE_MESSAGE_SELECT_COLUMNS +
|
||||||
" FROM messages" +
|
" FROM messages" +
|
||||||
" WHERE ");
|
" WHERE ");
|
||||||
|
buildFlagPredicates(sql, setFlags, clearFlags);
|
||||||
|
sql.append("folder_id = ?");
|
||||||
|
|
||||||
|
open(OpenMode.READ_WRITE);
|
||||||
|
ArrayList<Message> messages = new ArrayList<Message>();
|
||||||
|
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
cursor = mDb.rawQuery(
|
||||||
|
sql.toString(),
|
||||||
|
new String[] {
|
||||||
|
Long.toString(mFolderId)
|
||||||
|
});
|
||||||
|
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
LocalMessage message = new LocalMessage(null, this);
|
||||||
|
populateMessageFromGetMessageCursor(message, cursor);
|
||||||
|
messages.add(message);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return messages.toArray(new Message[] {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Build SQL where predicates expression from set and clear flag arrays.
|
||||||
|
*/
|
||||||
|
private void buildFlagPredicates(StringBuilder sql, Flag[] setFlags, Flag[] clearFlags)
|
||||||
|
throws MessagingException {
|
||||||
if (setFlags != null) {
|
if (setFlags != null) {
|
||||||
for (Flag flag : setFlags) {
|
for (Flag flag : setFlags) {
|
||||||
if (flag == Flag.X_STORE_1) {
|
if (flag == Flag.X_STORE_1) {
|
||||||
@ -1041,32 +1092,6 @@ public class LocalStore extends Store implements PersistentDataCallbacks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sql.append("folder_id = ?");
|
|
||||||
|
|
||||||
open(OpenMode.READ_WRITE);
|
|
||||||
ArrayList<Message> messages = new ArrayList<Message>();
|
|
||||||
|
|
||||||
Cursor cursor = null;
|
|
||||||
try {
|
|
||||||
cursor = mDb.rawQuery(
|
|
||||||
sql.toString(),
|
|
||||||
new String[] {
|
|
||||||
Long.toString(mFolderId)
|
|
||||||
});
|
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
LocalMessage message = new LocalMessage(null, this);
|
|
||||||
populateMessageFromGetMessageCursor(message, cursor);
|
|
||||||
messages.add(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return messages.toArray(new Message[] {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -689,6 +689,70 @@ public class LocalStoreUnitTests extends AndroidTestCase {
|
|||||||
assertEquals(failMessage, expectedUids, actualUids);
|
assertEquals(failMessage, expectedUids, actualUids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for getMessageCount
|
||||||
|
*/
|
||||||
|
public void testMessageCount() throws MessagingException {
|
||||||
|
|
||||||
|
final MimeMessage message1 = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
||||||
|
message1.setFlag(Flag.X_STORE_1, false);
|
||||||
|
message1.setFlag(Flag.X_STORE_2, false);
|
||||||
|
message1.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
||||||
|
|
||||||
|
final MimeMessage message2 = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
||||||
|
message2.setFlag(Flag.X_STORE_1, true);
|
||||||
|
message2.setFlag(Flag.X_STORE_2, false);
|
||||||
|
|
||||||
|
final MimeMessage message3 = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
||||||
|
message3.setFlag(Flag.X_STORE_1, false);
|
||||||
|
message3.setFlag(Flag.X_STORE_2, true);
|
||||||
|
message3.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
||||||
|
|
||||||
|
final MimeMessage message4 = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
||||||
|
message4.setFlag(Flag.X_STORE_1, true);
|
||||||
|
message4.setFlag(Flag.X_STORE_2, true);
|
||||||
|
message4.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
||||||
|
|
||||||
|
final MimeMessage message5 = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
||||||
|
message5.setFlag(Flag.X_DOWNLOADED_FULL, true);
|
||||||
|
|
||||||
|
final MimeMessage message6 = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
||||||
|
message6.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
|
||||||
|
|
||||||
|
final MimeMessage message7 = buildTestMessage(RECIPIENT_TO, SENDER, SUBJECT, BODY);
|
||||||
|
message7.setFlag(Flag.DELETED, true);
|
||||||
|
|
||||||
|
Message[] allOriginals = new Message[] {
|
||||||
|
message1, message2, message3, message4, message5, message6, message7 };
|
||||||
|
|
||||||
|
mFolder.open(OpenMode.READ_WRITE, null);
|
||||||
|
mFolder.appendMessages(allOriginals);
|
||||||
|
mFolder.close(false);
|
||||||
|
|
||||||
|
// Null lists are the same as empty lists - return all messages
|
||||||
|
mFolder.open(OpenMode.READ_WRITE, null);
|
||||||
|
|
||||||
|
int allMessages = mFolder.getMessageCount();
|
||||||
|
assertEquals("all messages", 7, allMessages);
|
||||||
|
|
||||||
|
int storeFlag1 = mFolder.getMessageCount(new Flag[] { Flag.X_STORE_1 }, null);
|
||||||
|
assertEquals("store flag 1", 2, storeFlag1);
|
||||||
|
|
||||||
|
int storeFlag1NotFlag2 = mFolder.getMessageCount(
|
||||||
|
new Flag[] { Flag.X_STORE_1 }, new Flag[] { Flag.X_STORE_2 });
|
||||||
|
assertEquals("store flag 1, not 2", 1, storeFlag1NotFlag2);
|
||||||
|
|
||||||
|
int downloadedFull = mFolder.getMessageCount(new Flag[] { Flag.X_DOWNLOADED_FULL }, null);
|
||||||
|
assertEquals("downloaded full", 4, downloadedFull);
|
||||||
|
|
||||||
|
int storeFlag2Full = mFolder.getMessageCount(
|
||||||
|
new Flag[] { Flag.X_STORE_2, Flag.X_DOWNLOADED_FULL }, null);
|
||||||
|
assertEquals("store flag 2, full", 2, storeFlag2Full);
|
||||||
|
|
||||||
|
int notDeleted = mFolder.getMessageCount(null, new Flag[] { Flag.DELETED });
|
||||||
|
assertEquals("not deleted", 6, notDeleted);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test unread messages count
|
* Test unread messages count
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user