Merge change I0bb16acd into eclair-mr2
* changes: Fix the bug that the count of draft and trash icons are wrong.
This commit is contained in:
commit
9bb382f43a
@ -28,6 +28,8 @@ import com.android.email.provider.EmailContent.Account;
|
|||||||
import com.android.email.provider.EmailContent.AccountColumns;
|
import com.android.email.provider.EmailContent.AccountColumns;
|
||||||
import com.android.email.provider.EmailContent.Mailbox;
|
import com.android.email.provider.EmailContent.Mailbox;
|
||||||
import com.android.email.provider.EmailContent.MailboxColumns;
|
import com.android.email.provider.EmailContent.MailboxColumns;
|
||||||
|
import com.android.email.provider.EmailContent.Message;
|
||||||
|
import com.android.email.provider.EmailContent.MessageColumns;
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
@ -64,6 +66,8 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
|
|||||||
private static final String MAILBOX_SELECTION = MailboxColumns.ACCOUNT_KEY + "=?"
|
private static final String MAILBOX_SELECTION = MailboxColumns.ACCOUNT_KEY + "=?"
|
||||||
+ " AND " + MailboxColumns.TYPE + "<" + Mailbox.TYPE_NOT_EMAIL
|
+ " AND " + MailboxColumns.TYPE + "<" + Mailbox.TYPE_NOT_EMAIL
|
||||||
+ " AND " + MailboxColumns.FLAG_VISIBLE + "=1";
|
+ " AND " + MailboxColumns.FLAG_VISIBLE + "=1";
|
||||||
|
private static final String MESSAGE_MAILBOX_ID_SELECTION =
|
||||||
|
MessageColumns.MAILBOX_KEY + "=?";
|
||||||
|
|
||||||
// UI support
|
// UI support
|
||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
@ -101,7 +105,13 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
|
|||||||
// DB access
|
// DB access
|
||||||
private long mAccountId;
|
private long mAccountId;
|
||||||
private LoadMailboxesTask mLoadMailboxesTask;
|
private LoadMailboxesTask mLoadMailboxesTask;
|
||||||
private AsyncTask mLoadAccountNameTask;
|
private AsyncTask<Void, Void, String> mLoadAccountNameTask;
|
||||||
|
private MessageCountTask mMessageCountTask;
|
||||||
|
|
||||||
|
private long mDraftMailboxKey = -1;
|
||||||
|
private long mTrashMailboxKey = -1;
|
||||||
|
private int mUnreadCountDraft = 0;
|
||||||
|
private int mUnreadCountTrash = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a specific account.
|
* Open a specific account.
|
||||||
@ -193,6 +203,7 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
Controller.getInstance(getApplication()).addResultCallback(mControllerCallback);
|
Controller.getInstance(getApplication()).addResultCallback(mControllerCallback);
|
||||||
|
updateMessageCount();
|
||||||
|
|
||||||
// TODO: may need to clear notifications here
|
// TODO: may need to clear notifications here
|
||||||
}
|
}
|
||||||
@ -211,6 +222,11 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
|
|||||||
mLoadAccountNameTask.cancel(true);
|
mLoadAccountNameTask.cancel(true);
|
||||||
mLoadAccountNameTask = null;
|
mLoadAccountNameTask = null;
|
||||||
}
|
}
|
||||||
|
if (mMessageCountTask != null &&
|
||||||
|
mMessageCountTask.getStatus() != MessageCountTask.Status.FINISHED) {
|
||||||
|
mMessageCountTask.cancel(true);
|
||||||
|
mMessageCountTask = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
@ -322,12 +338,27 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Cursor doInBackground(Void... params) {
|
protected Cursor doInBackground(Void... params) {
|
||||||
return MailboxList.this.managedQuery(
|
Cursor c = MailboxList.this.managedQuery(
|
||||||
EmailContent.Mailbox.CONTENT_URI,
|
EmailContent.Mailbox.CONTENT_URI,
|
||||||
MailboxList.this.mListAdapter.PROJECTION,
|
MailboxList.this.mListAdapter.PROJECTION,
|
||||||
MAILBOX_SELECTION,
|
MAILBOX_SELECTION,
|
||||||
new String[] { String.valueOf(mAccountKey) },
|
new String[] { String.valueOf(mAccountKey) },
|
||||||
MailboxColumns.TYPE + "," + MailboxColumns.DISPLAY_NAME);
|
MailboxColumns.TYPE + "," + MailboxColumns.DISPLAY_NAME);
|
||||||
|
mDraftMailboxKey = -1;
|
||||||
|
mTrashMailboxKey = -1;
|
||||||
|
c.moveToPosition(-1);
|
||||||
|
while (c.moveToNext()) {
|
||||||
|
long mailboxId = c.getInt(mListAdapter.COLUMN_ID);
|
||||||
|
switch (c.getInt(mListAdapter.COLUMN_TYPE)) {
|
||||||
|
case Mailbox.TYPE_DRAFTS:
|
||||||
|
mDraftMailboxKey = mailboxId;
|
||||||
|
break;
|
||||||
|
case Mailbox.TYPE_TRASH:
|
||||||
|
mTrashMailboxKey = mailboxId;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -336,9 +367,71 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MailboxList.this.mListAdapter.changeCursor(cursor);
|
MailboxList.this.mListAdapter.changeCursor(cursor);
|
||||||
|
updateMessageCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MessageCountTask extends AsyncTask<Void, Void, int[]> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int[] doInBackground(Void... params) {
|
||||||
|
int[] counts = new int[2];
|
||||||
|
if (mDraftMailboxKey != -1) {
|
||||||
|
counts[0] = EmailContent.count(MailboxList.this, Message.CONTENT_URI,
|
||||||
|
MESSAGE_MAILBOX_ID_SELECTION,
|
||||||
|
new String[] { String.valueOf(mDraftMailboxKey)});
|
||||||
|
} else {
|
||||||
|
counts[0] = -1;
|
||||||
|
}
|
||||||
|
if (mTrashMailboxKey != -1) {
|
||||||
|
counts[1] = EmailContent.count(MailboxList.this, Message.CONTENT_URI,
|
||||||
|
MESSAGE_MAILBOX_ID_SELECTION,
|
||||||
|
new String[] { String.valueOf(mTrashMailboxKey)});
|
||||||
|
} else {
|
||||||
|
counts[1] = -1;
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(int[] counts) {
|
||||||
|
boolean countChanged = false;
|
||||||
|
if (counts == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (counts[0] != -1) {
|
||||||
|
if (mUnreadCountDraft != counts[0]) {
|
||||||
|
mUnreadCountDraft = counts[0];
|
||||||
|
countChanged = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mUnreadCountDraft = 0;
|
||||||
|
}
|
||||||
|
if (counts[1] != -1) {
|
||||||
|
if (mUnreadCountTrash != counts[1]) {
|
||||||
|
mUnreadCountTrash = counts[1];
|
||||||
|
countChanged = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mUnreadCountTrash = 0;
|
||||||
|
}
|
||||||
|
if (countChanged) {
|
||||||
|
mListAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateMessageCount() {
|
||||||
|
if (mAccountId == -1 || mListAdapter.getCursor() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mMessageCountTask != null
|
||||||
|
&& mMessageCountTask.getStatus() != MessageCountTask.Status.FINISHED) {
|
||||||
|
mMessageCountTask.cancel(true);
|
||||||
|
}
|
||||||
|
mMessageCountTask = (MessageCountTask) new MessageCountTask().execute();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for UI-thread operations (when called from callbacks or any other threads)
|
* Handler for UI-thread operations (when called from callbacks or any other threads)
|
||||||
*/
|
*/
|
||||||
@ -502,6 +595,7 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
|
|||||||
|
|
||||||
public final String[] PROJECTION = new String[] { MailboxColumns.ID,
|
public final String[] PROJECTION = new String[] { MailboxColumns.ID,
|
||||||
MailboxColumns.DISPLAY_NAME, MailboxColumns.UNREAD_COUNT, MailboxColumns.TYPE };
|
MailboxColumns.DISPLAY_NAME, MailboxColumns.UNREAD_COUNT, MailboxColumns.TYPE };
|
||||||
|
public final int COLUMN_ID = 0;
|
||||||
public final int COLUMN_DISPLAY_NAME = 1;
|
public final int COLUMN_DISPLAY_NAME = 1;
|
||||||
public final int COLUMN_UNREAD_COUNT = 2;
|
public final int COLUMN_UNREAD_COUNT = 2;
|
||||||
public final int COLUMN_TYPE = 3;
|
public final int COLUMN_TYPE = 3;
|
||||||
@ -542,9 +636,21 @@ public class MailboxList extends ListActivity implements OnItemClickListener {
|
|||||||
chipView.setBackgroundResource(chipResId);
|
chipView.setBackgroundResource(chipResId);
|
||||||
// TODO do we use a different count for special mailboxes (total count vs. unread)
|
// TODO do we use a different count for special mailboxes (total count vs. unread)
|
||||||
int count = -1;
|
int count = -1;
|
||||||
text = cursor.getString(COLUMN_UNREAD_COUNT);
|
switch (type) {
|
||||||
if (text != null) {
|
case Mailbox.TYPE_DRAFTS:
|
||||||
count = Integer.valueOf(text);
|
count = mUnreadCountDraft;
|
||||||
|
text = String.valueOf(count);
|
||||||
|
break;
|
||||||
|
case Mailbox.TYPE_TRASH:
|
||||||
|
count = mUnreadCountTrash;
|
||||||
|
text = String.valueOf(count);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
text = cursor.getString(COLUMN_UNREAD_COUNT);
|
||||||
|
if (text != null) {
|
||||||
|
count = Integer.valueOf(text);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
TextView countView = (TextView) view.findViewById(R.id.new_message_count);
|
TextView countView = (TextView) view.findViewById(R.id.new_message_count);
|
||||||
// If the unread count is zero, not to show countView.
|
// If the unread count is zero, not to show countView.
|
||||||
|
Loading…
Reference in New Issue
Block a user