Merge branch 'readonly-p4-donut' into donut
This commit is contained in:
commit
7330fe4953
@ -33,6 +33,7 @@ import com.android.email.mail.Message;
|
||||
import com.android.email.mail.MessagingException;
|
||||
import com.android.email.mail.Message.RecipientType;
|
||||
import com.android.email.mail.store.LocalStore;
|
||||
import com.android.email.mail.store.LocalStore.LocalFolder;
|
||||
import com.android.email.mail.store.LocalStore.LocalMessage;
|
||||
|
||||
import android.app.ExpandableListActivity;
|
||||
@ -125,6 +126,8 @@ public class FolderMessageList extends ExpandableListActivity {
|
||||
R.drawable.appointment_indicator_leftside_20,
|
||||
R.drawable.appointment_indicator_leftside_21,
|
||||
};
|
||||
|
||||
private static final Flag[] DELETED_FLAG = new Flag[] { Flag.DELETED };
|
||||
|
||||
private ExpandableListView mListView;
|
||||
private int colorChipResId;
|
||||
@ -667,7 +670,7 @@ public class FolderMessageList extends ExpandableListActivity {
|
||||
mHandler.dataChanged();
|
||||
}
|
||||
|
||||
if (folder.name.equals(mAccount.getDraftsFolderName())) {
|
||||
if (folder.drafts) {
|
||||
MessageCompose.actionEditDraft(this, mAccount, message.message);
|
||||
}
|
||||
else {
|
||||
@ -1032,6 +1035,27 @@ public class FolderMessageList extends ExpandableListActivity {
|
||||
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
|
||||
* into the MessageListener.
|
||||
@ -1050,15 +1074,14 @@ public class FolderMessageList extends ExpandableListActivity {
|
||||
else {
|
||||
holder.displayName = folder.getName();
|
||||
}
|
||||
if (holder.name.equals(mAccount.getOutboxFolderName())) {
|
||||
holder.outbox = true;
|
||||
}
|
||||
setSpecialFolderIndicator(holder);
|
||||
if (holder.messages == null) {
|
||||
holder.messages = new ArrayList<MessageInfoHolder>();
|
||||
}
|
||||
try {
|
||||
folder.open(Folder.OpenMode.READ_WRITE, null);
|
||||
holder.messageCount = folder.getMessageCount();
|
||||
holder.messageCount = ((LocalFolder) folder)
|
||||
.getMessageCount(null, DELETED_FLAG);
|
||||
holder.unreadMessageCount = folder.getUnreadMessageCount();
|
||||
folder.close(false);
|
||||
}
|
||||
@ -1230,11 +1253,11 @@ public class FolderMessageList extends ExpandableListActivity {
|
||||
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.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.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@ -1393,9 +1416,14 @@ public class FolderMessageList extends ExpandableListActivity {
|
||||
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 sent;
|
||||
public boolean trash;
|
||||
|
||||
public int compareTo(FolderInfoHolder o) {
|
||||
String s1 = this.name;
|
||||
@ -1445,7 +1473,7 @@ public class FolderMessageList extends ExpandableListActivity {
|
||||
}
|
||||
this.hasAttachments = message.getAttachmentCount() > 0;
|
||||
this.read = message.isSet(Flag.SEEN);
|
||||
if (folder.outbox) {
|
||||
if (folder.outbox || folder.drafts || folder.sent) {
|
||||
this.sender = Address.toFriendly(
|
||||
message.getRecipients(RecipientType.TO));
|
||||
}
|
||||
|
@ -651,10 +651,28 @@ public class LocalStore extends Store implements PersistentDataCallbacks {
|
||||
|
||||
@Override
|
||||
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);
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = mDb.rawQuery("SELECT COUNT(*) FROM messages WHERE messages.folder_id = ?",
|
||||
cursor = mDb.rawQuery(
|
||||
sql.toString(),
|
||||
new String[] {
|
||||
Long.toString(mFolderId)
|
||||
});
|
||||
@ -1007,6 +1025,39 @@ public class LocalStore extends Store implements PersistentDataCallbacks {
|
||||
"SELECT " + POPULATE_MESSAGE_SELECT_COLUMNS +
|
||||
" FROM messages" +
|
||||
" 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) {
|
||||
for (Flag flag : setFlags) {
|
||||
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
|
||||
|
@ -689,6 +689,70 @@ public class LocalStoreUnitTests extends AndroidTestCase {
|
||||
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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user