Add folders to AccountFolderList

* Scan folders and write into child cursors
* Clicking a folder takes you to MessageList
* Remove most links to FolderMessageList (nearly dead!)
* Repair 1-account startup behavior (takes you directly to inbox)
* Cleanup a few basic things like context menus & refresh

TODO: Magic mailbox section at the top
TODO: As always, better linkage to sync engine(s)
TODO: Menus, context menus, etc.
TODO: Proper handling of expandable list - accounts should stay open?
This commit is contained in:
Andrew Stadler 2009-07-10 16:46:51 -07:00
parent 72dce73390
commit ded3c915d8
10 changed files with 432 additions and 165 deletions

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingLeft="36px"
android:paddingRight="4px" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
android:id="@+id/folder_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?android:attr/textColorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/folder_status"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorTertiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<View
android:layout_height="0dip"
android:layout_width="0dip"
android:layout_weight="1" />
<TextView
android:id="@+id/new_message_count"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?android:attr/textColorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/text_box_light"
android:paddingLeft="10px"
android:paddingRight="10px"
android:minWidth="64px"
android:gravity="right" />
</LinearLayout>

View File

@ -15,10 +15,12 @@
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/open"
android:title="@string/open_action" />
<item android:id="@+id/edit_account"
android:title="@string/account_settings_action" />
<item android:id="@+id/delete_account"
android:title="@string/remove_account_action" />
<!-- This is probably temporary -->
<item android:id="@+id/refresh_account"
android:title="@string/refresh_action" />
</menu>

View File

@ -15,27 +15,24 @@
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/check_mail"
<item android:id="@+id/check_mail"
android:alphabeticShortcut="r"
android:title="@string/refresh_action"
android:icon="@*android:drawable/ic_menu_refresh"
/>
<item
android:id="@+id/add_new_account"
android:title="@string/add_account_action"
android:icon="@android:drawable/ic_menu_add"
/>
<item
android:id="@+id/compose"
android:title="@string/refresh_action"
android:icon="@*android:drawable/ic_menu_refresh"
/>
<item android:id="@+id/add_new_account"
android:title="@string/add_account_action"
android:icon="@android:drawable/ic_menu_add"
/>
<item android:id="@+id/compose"
android:alphabeticShortcut="c"
android:title="@string/compose_action"
android:icon="@*android:drawable/ic_menu_compose"
/>
<!--
<item android:id="@+id/search"
android:title="@string/search_action" />
<item android:id="@+id/preferences"
android:title="@string/preferences_action" />
-->
android:icon="@*android:drawable/ic_menu_compose"
/>
<!--
<item android:id="@+id/search"
android:title="@string/search_action" />
<item android:id="@+id/preferences"
android:title="@string/preferences_action" />
-->
</menu>

View File

@ -16,11 +16,12 @@
package com.android.email.activity;
import com.android.email.Controller;
import com.android.email.Email;
import com.android.email.MessagingController;
import com.android.email.R;
import com.android.email.activity.setup.AccountSettings;
import com.android.email.activity.setup.AccountSetupBasics;
import com.android.email.mail.MessagingException;
import com.android.email.mail.Store;
import com.android.email.provider.EmailContent;
import com.android.email.provider.EmailContent.Account;
@ -37,6 +38,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -48,14 +50,12 @@ import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.CursorTreeAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
public class AccountFolderList extends ExpandableListActivity
implements OnItemClickListener, OnClickListener {
public class AccountFolderList extends ExpandableListActivity implements OnClickListener {
private static final int DIALOG_REMOVE_ACCOUNT = 1;
/**
* Key codes used to open a debug settings screen.
@ -66,26 +66,18 @@ public class AccountFolderList extends ExpandableListActivity
};
private int mSecretKeyCodeIndex = 0;
private static final String ICICLE_SELECTED_ACCOUNT = "com.android.email.selectedAccount";
private EmailContent.Account mSelectedContextAccount;
ExpandableListView mListView;
LoadAccountsTask mAsyncTask;
/**
* Support for list adapter
*/
private final static String[] sFromColumns = new String[] {
EmailContent.AccountColumns.DISPLAY_NAME,
EmailContent.AccountColumns.EMAIL_ADDRESS,
EmailContent.RECORD_ID
};
private final int[] sToIds = new int[] {
R.id.description,
R.id.email,
R.id.new_message_count
};
ExpandableListView mListView;
AccountsAdapter mListAdapter;
LoadAccountsTask mLoadAccountsTask;
LoadMailboxesTask mLoadMailboxesTask;
private MessageListHandler mHandler = new MessageListHandler();
private ControllerResults mControllerCallback = new ControllerResults();
/**
* Start the Accounts list activity. Uses the CLEAR_TOP flag which means that other stacked
@ -102,7 +94,6 @@ public class AccountFolderList extends ExpandableListActivity
super.onCreate(icicle);
setContentView(R.layout.account_folder_list);
mListView = getExpandableListView();
mListView.setOnItemClickListener(this);
mListView.setItemsCanFocus(false);
mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
mListView.setLongClickable(true);
@ -114,7 +105,7 @@ public class AccountFolderList extends ExpandableListActivity
mSelectedContextAccount = (Account) icicle.getParcelable(ICICLE_SELECTED_ACCOUNT);
}
mAsyncTask = (LoadAccountsTask) new LoadAccountsTask().execute();
mLoadAccountsTask = (LoadAccountsTask) new LoadAccountsTask().execute();
}
@Override
@ -125,6 +116,12 @@ public class AccountFolderList extends ExpandableListActivity
}
}
@Override
public void onPause() {
super.onPause();
Controller.getInstance(getApplication()).removeResultCallback(mControllerCallback);
}
@Override
public void onResume() {
super.onResume();
@ -132,15 +129,26 @@ public class AccountFolderList extends ExpandableListActivity
NotificationManager notifMgr = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notifMgr.cancel(1);
Controller.getInstance(getApplication()).addResultCallback(mControllerCallback);
// TODO: What updates do we need to auto-trigger, now that we have mailboxes in view?
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mAsyncTask != null && mAsyncTask.getStatus() != LoadAccountsTask.Status.FINISHED) {
mAsyncTask.cancel(true);
mAsyncTask = null;
if (mLoadMailboxesTask != null &&
mLoadMailboxesTask.getStatus() != LoadMailboxesTask.Status.FINISHED) {
mLoadMailboxesTask.cancel(true);
mLoadMailboxesTask = null;
}
if (mLoadAccountsTask != null &&
mLoadAccountsTask.getStatus() != LoadAccountsTask.Status.FINISHED) {
mLoadAccountsTask.cancel(true);
mLoadAccountsTask = null;
}
}
@ -148,17 +156,33 @@ public class AccountFolderList extends ExpandableListActivity
public void onGroupExpand(int groupPosition) {
super.onGroupExpand(groupPosition);
// This is a temporary hack, until I implement the child cursors
AccountsAdapter adapter = (AccountsAdapter) mListView.getExpandableListAdapter();
if (adapter != null) {
Cursor groupCursor = adapter.getGroup(groupPosition);
long mailboxKey = groupCursor.getLong(EmailContent.Mailbox.CONTENT_ID_COLUMN);
FolderMessageList.actionHandleAccount(this, mailboxKey);
// If we don't have a cursor yet, create one
Cursor childCursor = mListAdapter.getChild(groupPosition, 0);
if (childCursor == null) {
// Kill any previous unfinished task
if (mLoadMailboxesTask != null &&
mLoadMailboxesTask.getStatus() != LoadMailboxesTask.Status.FINISHED) {
mLoadMailboxesTask.cancel(true);
mLoadMailboxesTask = null;
}
// Now start a new task to create a non-empty cursor
Cursor groupCursor = mListAdapter.getCursor();
long accountKey = groupCursor.getLong(EmailContent.Account.CONTENT_ID_COLUMN);
mLoadMailboxesTask = new LoadMailboxesTask(accountKey, groupPosition);
mLoadMailboxesTask.execute();
}
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
onOpenFolder(groupPosition, childPosition);
return true; // "handled"
}
/**
* Async task to handle the cursor query out of the UI thread
* Async task to handle the accounts query outside of the UI thread
*/
private class LoadAccountsTask extends AsyncTask<Void, Void, Cursor> {
@ -173,8 +197,8 @@ public class AccountFolderList extends ExpandableListActivity
@Override
protected void onPostExecute(Cursor theCursor) {
AccountsAdapter adapter = new AccountsAdapter(theCursor, AccountFolderList.this);
mListView.setAdapter(adapter);
mListAdapter = new AccountsAdapter(theCursor, AccountFolderList.this);
mListView.setAdapter(mListAdapter);
// This is deferred until after the first fetch, so it won't flicker
// while we're waiting to find out if we have any accounts
@ -182,6 +206,45 @@ public class AccountFolderList extends ExpandableListActivity
}
}
/**
* Async task to handle the mailboxes query outside of the UI thread
*/
private class LoadMailboxesTask extends AsyncTask<Void, Void, Cursor> {
private long mAccountId;
private int mGroupNumber;
public LoadMailboxesTask(long accountId, int groupNumber) {
mAccountId = accountId;
mGroupNumber = groupNumber;
}
@Override
protected Cursor doInBackground(Void... params) {
// TODO use a custom projection and don't have to sample all of these columns
return AccountFolderList.this.managedQuery(
EmailContent.Mailbox.CONTENT_URI,
EmailContent.Mailbox.CONTENT_PROJECTION,
EmailContent.MailboxColumns.ACCOUNT_KEY + "=?",
new String[] { String.valueOf(mAccountId) },
EmailContent.MailboxColumns.TYPE);
}
@Override
protected void onPostExecute(Cursor theCursor) {
// TODO: There is a race condition here - what if the result came back after
// the positions shifted? We need to use something other than "groupNumber"
// to set the correct adapter & cursor.
AccountFolderList.this.mListAdapter.setChildrenCursor(mGroupNumber, theCursor);
// If there are zero folders, this is probably a brand-new account - schedule a
// top-level refresh
if (theCursor.getCount() == 0) {
onRefresh(mAccountId);
}
}
}
private void onAddNewAccount() {
AccountSetupBasics.actionNewAccount(this);
}
@ -190,8 +253,22 @@ public class AccountFolderList extends ExpandableListActivity
AccountSettings.actionSettings(this, accountId);
}
private void onRefresh() {
MessagingController.getInstance(getApplication()).checkMail(this, null, null);
/**
* Refresh one or all accounts
* @param accountId A specific id to refresh folders only, or -1 to refresh everything
*/
private void onRefresh(long accountId) {
if (accountId == -1) {
// TODO implement a suitable "Refresh all accounts" / "check mail" comment in Controller
// TODO this is temp
Toast.makeText(this,
"Please longpress an account to refresh it", Toast.LENGTH_LONG).show();
} else {
EmailContent.Account account =
EmailContent.Account.restoreAccountWithId(this, accountId);
Controller.getInstance(getApplication()).updateMailboxList(
account, mControllerCallback);
}
}
private void onCompose() {
@ -203,10 +280,6 @@ public class AccountFolderList extends ExpandableListActivity
}
}
private void onOpenAccount(long accountId) {
FolderMessageList.actionHandleAccount(this, accountId);
}
public void onClick(View view) {
if (view.getId() == R.id.add_new_account) {
onAddNewAccount();
@ -227,6 +300,17 @@ public class AccountFolderList extends ExpandableListActivity
return super.onCreateDialog(id);
}
/**
* Open a folder. This may be a "real" folder or composite, depending on which group.
* @param groupPosition The group # (account)
* @param childPosition The child # (folder)
*/
private void onOpenFolder(int groupPosition, int childPosition) {
Cursor childCursor = mListAdapter.getChild(groupPosition, childPosition);
long mailboxKey = childCursor.getLong(EmailContent.Mailbox.CONTENT_ID_COLUMN);
MessageList.actionHandleAccount(this, mailboxKey, null, null);
}
private Dialog createRemoveAccountDialog() {
return new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
@ -263,27 +347,29 @@ public class AccountFolderList extends ExpandableListActivity
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)item.getMenuInfo();
Cursor c = (Cursor) mListView.getItemAtPosition(menuInfo.position);
long accountId = c.getLong(Account.CONTENT_ID_COLUMN);
switch (item.getItemId()) {
case R.id.delete_account:
onDeleteAccount(accountId);
break;
case R.id.edit_account:
onEditAccount(accountId);
break;
case R.id.open:
onOpenAccount(accountId);
break;
}
return true;
}
ExpandableListContextMenuInfo menuInfo = (ExpandableListContextMenuInfo)item.getMenuInfo();
int type = ExpandableListView.getPackedPositionType(menuInfo.packedPosition);
public void onItemClick(AdapterView parent, View view, int position, long id) {
Cursor c = (Cursor) mListView.getItemAtPosition(position);
long accountId = c.getLong(Account.CONTENT_ID_COLUMN);
onOpenAccount(accountId);
if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
int group = ExpandableListView.getPackedPositionGroup(menuInfo.packedPosition);
Cursor c = (Cursor) mListView.getItemAtPosition(group);
long accountId = c.getLong(Account.CONTENT_ID_COLUMN);
switch (item.getItemId()) {
case R.id.delete_account:
onDeleteAccount(accountId);
break;
case R.id.edit_account:
onEditAccount(accountId);
break;
case R.id.refresh_account:
onRefresh(accountId);
break;
}
return true;
} else {
// TODO child context menus (per mailbox)
return false;
}
}
@Override
@ -293,7 +379,7 @@ public class AccountFolderList extends ExpandableListActivity
onAddNewAccount();
break;
case R.id.check_mail:
onRefresh();
onRefresh(-1);
break;
case R.id.compose:
onCompose();
@ -311,15 +397,21 @@ public class AccountFolderList extends ExpandableListActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.accounts_option, menu);
getMenuInflater().inflate(R.menu.account_folder_list_option, menu);
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(R.string.accounts_context_menu_title);
getMenuInflater().inflate(R.menu.accounts_context, menu);
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo info) {
super.onCreateContextMenu(menu, v, info);
ExpandableListContextMenuInfo menuInfo = (ExpandableListContextMenuInfo) info;
int type = ExpandableListView.getPackedPositionType(menuInfo.packedPosition);
if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
menu.setHeaderTitle(R.string.accounts_context_menu_title);
getMenuInflater().inflate(R.menu.account_folder_list_context, menu);
} else {
// TODO child context menus (per mailbox)
}
}
@Override
@ -336,6 +428,50 @@ public class AccountFolderList extends ExpandableListActivity
return super.onKeyDown(keyCode, event);
}
/**
* Handler for UI-thread operations (when called from callbacks or any other threads)
*/
class MessageListHandler extends Handler {
private static final int MSG_PROGRESS = 1;
@Override
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case MSG_PROGRESS:
setProgressBarIndeterminateVisibility(msg.arg1 != 0);
break;
default:
super.handleMessage(msg);
}
}
/**
* Call from any thread to start/stop progress indicator(s)
* @param progress true to start, false to stop
*/
public void progress(boolean progress) {
android.os.Message msg = android.os.Message.obtain();
msg.what = MSG_PROGRESS;
msg.arg1 = progress ? 1 : 0;
sendMessage(msg);
}
}
/**
* Callback for async Controller results. This is all a placeholder until we figure out the
* final way to do this.
*/
private class ControllerResults implements Controller.Result {
public void updateMailboxListCallback(MessagingException result, long accountKey) {
mHandler.progress(false);
}
public void updateMailboxCallback(MessagingException result, long accountKey,
long mailboxKey, int totalMessagesInMailbox, int numNewMessages) {
mHandler.progress(false);
}
}
private static class AccountsAdapter extends CursorTreeAdapter {
Context mContext;
@ -350,8 +486,27 @@ public class AccountFolderList extends ExpandableListActivity
@Override
protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild)
{
// TODO Auto-generated method stub
String text = cursor.getString(EmailContent.Mailbox.CONTENT_DISPLAY_NAME_COLUMN);
if (text != null) {
TextView nameView = (TextView) view.findViewById(R.id.folder_name);
nameView.setText(text);
}
// TODO get/trach live folder status
text = null;
TextView statusView = (TextView) view.findViewById(R.id.folder_status);
if (text != null) {
statusView.setText(text);
statusView.setVisibility(View.VISIBLE);
} else {
statusView.setVisibility(View.GONE);
}
text = cursor.getString(EmailContent.Mailbox.CONTENT_UNREAD_COUNT_COLUMN);
if (text != null) {
TextView countView = (TextView) view.findViewById(R.id.new_message_count);
countView.setText(text);
}
}
@Override
@ -369,12 +524,14 @@ public class AccountFolderList extends ExpandableListActivity
emailView.setText(text);
}
// TODO get unread count from Account
int unreadMessageCount = 0;
TextView countView = (TextView) view.findViewById(R.id.new_message_count);
int unreadMessageCount = 0; // TODO get unread count from Account
if (unreadMessageCount <= 0) {
countView.setVisibility(View.GONE);
} else {
if (unreadMessageCount > 0) {
countView.setText(String.valueOf(unreadMessageCount));
countView.setVisibility(View.VISIBLE);
} else {
countView.setVisibility(View.GONE);
}
}
@ -398,8 +555,7 @@ public class AccountFolderList extends ExpandableListActivity
@Override
protected View newChildView(Context context, Cursor cursor, boolean isLastChild,
ViewGroup parent) {
// TODO Auto-generated method stub
return null;
return mInflater.inflate(R.layout.account_folder_list_child, parent, false);
}
@Override

View File

@ -418,6 +418,7 @@ public class FolderMessageList extends ExpandableListActivity {
* @param context
* @param id
*/
@Deprecated
public static void actionHandleAccount(Context context, long id) {
actionHandleAccount(context, id, null);
}
@ -428,6 +429,7 @@ public class FolderMessageList extends ExpandableListActivity {
* @param id
* @param initialFolder The folder to open, or null for none
*/
@Deprecated
public static void actionHandleAccount(Context context, long id, String initialFolder) {
Intent intent = new Intent(context, FolderMessageList.class);
intent.putExtra(EXTRA_ACCOUNT_ID, id);
@ -437,6 +439,7 @@ public class FolderMessageList extends ExpandableListActivity {
context.startActivity(intent);
}
@Deprecated
public static Intent actionHandleAccountIntent(Context context, long id, String initialFolder) {
Intent intent = new Intent(context, FolderMessageList.class);
intent.putExtra(EXTRA_ACCOUNT_ID, id);
@ -456,6 +459,7 @@ public class FolderMessageList extends ExpandableListActivity {
* @param initialFolder If non-null, can set the folder name to open (typically Email.INBOX)
* @return an Intent which can be used to view that account
*/
@Deprecated
public static Intent actionHandleAccountUriIntent(Context context, long id,
String initialFolder) {
Intent i = actionHandleAccountIntent(context, id, initialFolder);

View File

@ -61,6 +61,8 @@ import java.util.Set;
public class MessageList extends ListActivity implements OnItemClickListener, OnClickListener {
// Intent extras (internal to this activity)
private static final String EXTRA_ACCOUNT_ID = "com.android.email.activity._ACCOUNT_ID";
private static final String EXTRA_MAILBOX_TYPE = "com.android.email.activity.MAILBOX_TYPE";
private static final String EXTRA_MAILBOX_ID = "com.android.email.activity.MAILBOX_ID";
private static final String EXTRA_ACCOUNT_NAME = "com.android.email.activity.ACCOUNT_NAME";
private static final String EXTRA_MAILBOX_NAME = "com.android.email.activity.MAILBOX_NAME";
@ -99,6 +101,36 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
context.startActivity(intent);
}
/**
* Open a specific mailbox by account & type
*
* @param context The caller's context (for generating an intent)
* @param accountId The account to open
* @param mailboxType the type of mailbox to open (e.g. @see EmailContent.Mailbox.TYPE_INBOX)
*/
public static void actionHandleAccount(Context context, long accountId, int mailboxType) {
Intent intent = new Intent(context, MessageList.class);
intent.putExtra(EXTRA_ACCOUNT_ID, accountId);
intent.putExtra(EXTRA_MAILBOX_TYPE, mailboxType);
context.startActivity(intent);
}
/**
* Return an intent to open a specific mailbox by account & type. It will also clear
* notifications.
*
* @param context The caller's context (for generating an intent)
* @param accountId The account to open
* @param mailboxType the type of mailbox to open (e.g. @see EmailContent.Mailbox.TYPE_INBOX)
*/
public static Intent actionHandleAccountIntent(Context context, long accountId,
int mailboxType) {
Intent intent = new Intent(context, MessageList.class);
intent.putExtra(EXTRA_ACCOUNT_ID, accountId);
intent.putExtra(EXTRA_MAILBOX_TYPE, mailboxType);
return intent;
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@ -123,10 +155,30 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
mListAdapter = new MessageListAdapter(this);
setListAdapter(mListAdapter);
// TODO set title to "account > mailbox (#unread)"
// TODO extend this to properly deal with multiple mailboxes, cursor, etc.
mMailboxId = getIntent().getLongExtra(EXTRA_MAILBOX_ID, -1);
if (mMailboxId == -1) {
// Try account/type mode
long accountId = getIntent().getLongExtra(EXTRA_ACCOUNT_ID, -1);
int mailboxType = getIntent().getIntExtra(EXTRA_MAILBOX_TYPE, -1);
Cursor c = null;
try {
c = getContentResolver().query(EmailContent.Mailbox.CONTENT_URI,
EmailContent.Mailbox.CONTENT_PROJECTION,
EmailContent.MailboxColumns.ACCOUNT_KEY + "=? AND " +
EmailContent.MailboxColumns.TYPE + "=?",
new String[] { Long.toString(accountId), Integer.toString(mailboxType) },
null);
if (c.moveToFirst()) {
mMailboxId = c.getLong(EmailContent.Mailbox.CONTENT_ID_COLUMN);
}
} finally {
if (c != null) c.close();
}
}
// TODO set title to "account > mailbox (#unread)"
mLoadMessagesTask = (LoadMessagesTask) new LoadMessagesTask(mMailboxId).execute();
}
@ -300,7 +352,7 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
// TODO this should be a call to the controller, since it may possibly kick off
// more than just a DB update. Also, the DB update shouldn't be in the UI thread
// as it is here.
// as it is here. Also, it needs to update the read/unread count in the mailbox?
ContentValues cv = new ContentValues();
cv.put(EmailContent.MessageColumns.FLAG_READ, isRead);
Uri uri = ContentUris.withAppendedId(

View File

@ -16,11 +16,8 @@
package com.android.email.activity;
import com.android.email.Email;
import com.android.email.provider.EmailContent;
import com.android.email.provider.EmailContent;
import com.android.exchange.SyncManager;
//import com.android.exchange.SyncManager;
import android.app.Activity;
import android.content.Intent;
@ -62,8 +59,8 @@ public class Welcome extends Activity {
null, null, null);
if (c.getCount() == 1) {
c.moveToFirst();
long id = c.getLong(EmailContent.Account.CONTENT_ID_COLUMN);
FolderMessageList.actionHandleAccount(this, id, Email.INBOX);
long accountId = c.getLong(EmailContent.Account.CONTENT_ID_COLUMN);
MessageList.actionHandleAccount(this, accountId, EmailContent.Mailbox.TYPE_INBOX);
finish();
return;
}

View File

@ -16,10 +16,9 @@
package com.android.email.activity.setup;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.Utility;
import com.android.email.activity.FolderMessageList;
import com.android.email.activity.MessageList;
import com.android.email.provider.EmailContent;
import android.app.Activity;
@ -106,7 +105,7 @@ public class AccountSetupNames extends Activity implements OnClickListener {
}
mAccount.setName(mName.getText().toString());
mAccount.saveOrUpdate(this);
FolderMessageList.actionHandleAccount(this, mAccount.mId, Email.INBOX);
MessageList.actionHandleAccount(this, mAccount.mId, EmailContent.Mailbox.TYPE_INBOX);
finish();
}

View File

@ -22,7 +22,7 @@ import com.android.email.MessagingController;
import com.android.email.MessagingListener;
import com.android.email.R;
import com.android.email.activity.AccountFolderList;
import com.android.email.activity.FolderMessageList;
import com.android.email.activity.MessageList;
import com.android.email.mail.MessagingException;
import com.android.email.mail.Store;
import com.android.email.mail.store.LocalStore;
@ -282,8 +282,8 @@ public class MailService extends Service {
} else {
EmailContent.Account account1 = accountsWithNewMail.keySet().iterator().next();
int totalNewMails = accountsWithNewMail.get(account1);
Intent i = FolderMessageList.actionHandleAccountIntent(context,
account1.mId, Email.INBOX);
Intent i = MessageList.actionHandleAccountIntent(context,
account1.mId, EmailContent.Mailbox.TYPE_INBOX);
PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0);
notif.setLatestEventInfo(context, getString(R.string.notification_new_title),
getResources().

View File

@ -52,66 +52,66 @@ public class FolderMessageListUnitTests extends AndroidTestCase {
super.tearDown();
}
/**
* Test of actionHandleAccount() variants. Make sure they generate correct intents and
* then call startActivity() with them.
*/
public void testActionHandleAccount() {
// Create a dummy account
createTestAccount();
// Create a mock context to catch the startActivity calls
MyContext mockContext = new MyContext(getContext());
// First, try with no initial folder
FolderMessageList.actionHandleAccount(mockContext, mAccountId);
Intent i = mockContext.startActivityIntent;
assertNotNull(i);
checkIntent(i, null, mAccount, null);
// Next try with initial folder specified
FolderMessageList.actionHandleAccount(mockContext, mAccountId, "test-folder-name");
i = mockContext.startActivityIntent;
assertNotNull(i);
checkIntent(i, null, mAccount, "test-folder-name");
}
// /**
// * Test of actionHandleAccount() variants. Make sure they generate correct intents and
// * then call startActivity() with them.
// */
// public void testActionHandleAccount() {
// // Create a dummy account
// createTestAccount();
//
// // Create a mock context to catch the startActivity calls
// MyContext mockContext = new MyContext(getContext());
//
// // First, try with no initial folder
// FolderMessageList.actionHandleAccount(mockContext, mAccountId);
// Intent i = mockContext.startActivityIntent;
// assertNotNull(i);
// checkIntent(i, null, mAccount, null);
//
// // Next try with initial folder specified
// FolderMessageList.actionHandleAccount(mockContext, mAccountId, "test-folder-name");
// i = mockContext.startActivityIntent;
// assertNotNull(i);
// checkIntent(i, null, mAccount, "test-folder-name");
// }
/**
* Test of actionHandleAccountIntent(). Make sure it generates correct intents.
*/
public void testActionHandleAccountIntent() {
// Create a dummy account
createTestAccount();
// First try with no initial folder
Intent result = FolderMessageList.actionHandleAccountIntent(
getContext(), mAccountId, null);
checkIntent(result, null, mAccount, null);
// now try with a specified initial folder
result = FolderMessageList.actionHandleAccountIntent(
getContext(), mAccountId, "test-folder-name");
checkIntent(result, null, mAccount, "test-folder-name");
}
// public void testActionHandleAccountIntent() {
// // Create a dummy account
// createTestAccount();
//
// // First try with no initial folder
// Intent result = FolderMessageList.actionHandleAccountIntent(
// getContext(), mAccountId, null);
// checkIntent(result, null, mAccount, null);
//
// // now try with a specified initial folder
// result = FolderMessageList.actionHandleAccountIntent(
// getContext(), mAccountId, "test-folder-name");
// checkIntent(result, null, mAccount, "test-folder-name");
// }
/**
* Test of actionHandleAccountUriIntent(). Make sure it generates correct intents.
*/
public void testActionHandleAccountUriIntent() {
// Create a dummy account
createTestAccount();
Uri uri = ContentUris.withAppendedId(EmailContent.Account.CONTENT_URI, mAccountId);
// First try with no initial folder
Intent result = FolderMessageList.actionHandleAccountUriIntent(
getContext(), mAccountId, null);
checkIntent(result, uri, null, null);
// now try with a specified initial folder
result = FolderMessageList.actionHandleAccountUriIntent(
getContext(), mAccountId, "test-folder-name");
checkIntent(result, uri, null, "test-folder-name");
}
// public void testActionHandleAccountUriIntent() {
// // Create a dummy account
// createTestAccount();
// Uri uri = ContentUris.withAppendedId(EmailContent.Account.CONTENT_URI, mAccountId);
//
// // First try with no initial folder
// Intent result = FolderMessageList.actionHandleAccountUriIntent(
// getContext(), mAccountId, null);
// checkIntent(result, uri, null, null);
//
// // now try with a specified initial folder
// result = FolderMessageList.actionHandleAccountUriIntent(
// getContext(), mAccountId, "test-folder-name");
// checkIntent(result, uri, null, "test-folder-name");
// }
/**
* Check the values in a generated intent