1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

Hang onto our messaging controller rather than constantly reacquiring

it.
This commit is contained in:
Jesse Vincent 2009-12-20 06:14:10 +00:00
parent 2c9fc8b997
commit b8b9e20e81

View File

@ -105,6 +105,9 @@ public class MessageList
private LayoutInflater mInflater; private LayoutInflater mInflater;
private MessagingController mController;
private Account mAccount; private Account mAccount;
private int mUnreadMessageCount = 0; private int mUnreadMessageCount = 0;
@ -286,7 +289,7 @@ public class MessageList
// Debug.stopMethodTracing(); // Debug.stopMethodTracing();
if ((position+1) == (mAdapter.getCount())) if ((position+1) == (mAdapter.getCount()))
{ {
MessagingController.getInstance(getApplication()).loadMoreMessages( mController.loadMoreMessages(
mAccount, mAccount,
mFolderName, mFolderName,
mAdapter.mListener); mAdapter.mListener);
@ -380,6 +383,8 @@ public class MessageList
mCurrentFolder = mAdapter.getFolder(mFolderName); mCurrentFolder = mAdapter.getFolder(mFolderName);
mController = MessagingController.getInstance(getApplication());
mListView.setAdapter(mAdapter); mListView.setAdapter(mAdapter);
if (savedInstanceState != null) if (savedInstanceState != null)
@ -412,7 +417,7 @@ public class MessageList
{ {
super.onPause(); super.onPause();
//Debug.stopMethodTracing(); //Debug.stopMethodTracing();
MessagingController.getInstance(getApplication()).removeListener(mAdapter.mListener); mController.removeListener(mAdapter.mListener);
} }
/** /**
@ -425,22 +430,21 @@ public class MessageList
{ {
super.onResume(); super.onResume();
MessagingController controller = MessagingController.getInstance(getApplication());
sortType = controller.getSortType(); sortType = mController.getSortType();
sortAscending = controller.isSortAscending(sortType); sortAscending = mController.isSortAscending(sortType);
sortDateAscending = controller.isSortAscending(SORT_TYPE.SORT_DATE); sortDateAscending = mController.isSortAscending(SORT_TYPE.SORT_DATE);
controller.addListener(mAdapter.mListener); mController.addListener(mAdapter.mListener);
mAdapter.messages.clear(); mAdapter.messages.clear();
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
controller.listLocalMessagesSynchronous(mAccount, mFolderName, mAdapter.mListener); mController.listLocalMessagesSynchronous(mAccount, mFolderName, mAdapter.mListener);
NotificationManager notifMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notifMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notifMgr.cancel(mAccount.getAccountNumber()); notifMgr.cancel(mAccount.getAccountNumber());
notifMgr.cancel(-1000 - mAccount.getAccountNumber()); notifMgr.cancel(-1000 - mAccount.getAccountNumber());
controller.getFolderUnreadMessageCount(mAccount, mFolderName, mAdapter.mListener); mController.getFolderUnreadMessageCount(mAccount, mFolderName, mAdapter.mListener);
mHandler.refreshTitle(); mHandler.refreshTitle();
@ -780,9 +784,9 @@ public class MessageList
else else
{ {
sortType = newSortType; sortType = newSortType;
MessagingController.getInstance(getApplication()).setSortType(sortType); mController.setSortType(sortType);
sortAscending = MessagingController.getInstance(getApplication()).isSortAscending(sortType); sortAscending = mController.isSortAscending(sortType);
sortDateAscending = MessagingController.getInstance(getApplication()).isSortAscending(SORT_TYPE.SORT_DATE); sortDateAscending = mController.isSortAscending(SORT_TYPE.SORT_DATE);
reSort(); reSort();
} }
} }
@ -830,10 +834,10 @@ public class MessageList
private void onToggleSortAscending() private void onToggleSortAscending()
{ {
MessagingController.getInstance(getApplication()).setSortAscending(sortType, !sortAscending); mController.setSortAscending(sortType, !sortAscending);
sortAscending = MessagingController.getInstance(getApplication()).isSortAscending(sortType); sortAscending = mController.isSortAscending(sortType);
sortDateAscending = MessagingController.getInstance(getApplication()).isSortAscending(SORT_TYPE.SORT_DATE); sortDateAscending = mController.isSortAscending(SORT_TYPE.SORT_DATE);
reSort(); reSort();
} }
@ -841,7 +845,7 @@ public class MessageList
private void onDelete(MessageInfoHolder holder, int position) private void onDelete(MessageInfoHolder holder, int position)
{ {
mAdapter.removeMessage(holder); mAdapter.removeMessage(holder);
MessagingController.getInstance(getApplication()).deleteMessages(mAccount, holder.message.getFolder().getName(), new Message[] { holder.message }, null); mController.deleteMessages(mAccount, holder.message.getFolder().getName(), new Message[] { holder.message }, null);
mListView.setSelection(position); mListView.setSelection(position);
} }
@ -849,12 +853,12 @@ public class MessageList
private void onMove(MessageInfoHolder holder) private void onMove(MessageInfoHolder holder)
{ {
if (MessagingController.getInstance(getApplication()).isMoveCapable(mAccount) == false) if (mController.isMoveCapable(mAccount) == false)
{ {
return; return;
} }
if (MessagingController.getInstance(getApplication()).isMoveCapable(holder.message) == false) if (mController.isMoveCapable(holder.message) == false)
{ {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG); Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show(); toast.show();
@ -871,12 +875,12 @@ public class MessageList
private void onCopy(MessageInfoHolder holder) private void onCopy(MessageInfoHolder holder)
{ {
if (MessagingController.getInstance(getApplication()).isCopyCapable(mAccount) == false) if (mController.isCopyCapable(mAccount) == false)
{ {
return; return;
} }
if (MessagingController.getInstance(getApplication()).isCopyCapable(holder.message) == false) if (mController.isCopyCapable(holder.message) == false)
{ {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG); Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show(); toast.show();
@ -936,7 +940,7 @@ public class MessageList
private void onMoveChosen(MessageInfoHolder holder, String folderName) private void onMoveChosen(MessageInfoHolder holder, String folderName)
{ {
if (MessagingController.getInstance(getApplication()).isMoveCapable(mAccount) == false) if (mController.isMoveCapable(mAccount) == false)
{ {
return; return;
} }
@ -947,14 +951,14 @@ public class MessageList
} }
mAdapter.removeMessage(holder); mAdapter.removeMessage(holder);
MessagingController.getInstance(getApplication()).moveMessage(mAccount, holder.message.getFolder().getName(), holder.message, folderName, null); mController.moveMessage(mAccount, holder.message.getFolder().getName(), holder.message, folderName, null);
} }
private void onCopyChosen(MessageInfoHolder holder, String folderName) private void onCopyChosen(MessageInfoHolder holder, String folderName)
{ {
if (MessagingController.getInstance(getApplication()).isCopyCapable(mAccount) == false) if (mController.isCopyCapable(mAccount) == false)
{ {
return; return;
} }
@ -962,7 +966,7 @@ public class MessageList
{ {
return; return;
} }
MessagingController.getInstance(getApplication()).copyMessage(mAccount, mController.copyMessage(mAccount,
holder.message.getFolder().getName(), holder.message, folderName, null); holder.message.getFolder().getName(), holder.message, folderName, null);
} }
@ -1030,7 +1034,7 @@ public class MessageList
try try
{ {
MessagingController.getInstance(getApplication()).markAllMessagesRead(mAccount, mCurrentFolder.name); mController.markAllMessagesRead(mAccount, mCurrentFolder.name);
for (MessageInfoHolder holder : mAdapter.messages) for (MessageInfoHolder holder : mAdapter.messages)
{ {
@ -1061,7 +1065,7 @@ public class MessageList
private void onToggleRead(MessageInfoHolder holder) private void onToggleRead(MessageInfoHolder holder)
{ {
MessagingController.getInstance(getApplication()).setFlag(mAccount, holder.message.getFolder().getName(), new String[] { holder.uid }, Flag.SEEN, !holder.read); mController.setFlag(mAccount, holder.message.getFolder().getName(), new String[] { holder.uid }, Flag.SEEN, !holder.read);
holder.read = !holder.read; holder.read = !holder.read;
mHandler.sortMessages(); mHandler.sortMessages();
} }
@ -1069,20 +1073,20 @@ public class MessageList
private void onToggleFlag(MessageInfoHolder holder) private void onToggleFlag(MessageInfoHolder holder)
{ {
MessagingController.getInstance(getApplication()).setFlag(mAccount, holder.message.getFolder().getName(), new String[] { holder.uid }, Flag.FLAGGED, !holder.flagged); mController.setFlag(mAccount, holder.message.getFolder().getName(), new String[] { holder.uid }, Flag.FLAGGED, !holder.flagged);
holder.flagged = !holder.flagged; holder.flagged = !holder.flagged;
mHandler.sortMessages(); mHandler.sortMessages();
} }
private void checkMail(Account account, String folderName) private void checkMail(Account account, String folderName)
{ {
MessagingController.getInstance(getApplication()).synchronizeMailbox(account, folderName, mAdapter.mListener); mController.synchronizeMailbox(account, folderName, mAdapter.mListener);
sendMail(account); sendMail(account);
} }
private void sendMail(Account account) private void sendMail(Account account)
{ {
MessagingController.getInstance(getApplication()).sendPendingMessages(account, mAdapter.mListener); mController.sendPendingMessages(account, mAdapter.mListener);
} }
@Override @Override
@ -1362,7 +1366,7 @@ public class MessageList
public void onSendAlternate(Account account, MessageInfoHolder holder) public void onSendAlternate(Account account, MessageInfoHolder holder)
{ {
MessagingController.getInstance(getApplication()).sendAlternate(this, account, holder.message); mController.sendAlternate(this, account, holder.message);
} }
public void showProgressIndicator(boolean status) public void showProgressIndicator(boolean status)
@ -1413,12 +1417,12 @@ public class MessageList
menu.findItem(R.id.flag).setTitle(R.string.unflag_action); menu.findItem(R.id.flag).setTitle(R.string.unflag_action);
} }
if (MessagingController.getInstance(getApplication()).isCopyCapable(mAccount) == false) if (mController.isCopyCapable(mAccount) == false)
{ {
menu.findItem(R.id.copy).setVisible(false); menu.findItem(R.id.copy).setVisible(false);
} }
if (MessagingController.getInstance(getApplication()).isMoveCapable(mAccount) == false) if (mController.isMoveCapable(mAccount) == false)
{ {
menu.findItem(R.id.move).setVisible(false); menu.findItem(R.id.move).setVisible(false);
} }
@ -2439,13 +2443,13 @@ public class MessageList
{ {
if (mBatchDeleteButton == v) if (mBatchDeleteButton == v)
{ {
MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), null); mController.deleteMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), null);
mSelectedCount = 0; mSelectedCount = 0;
configureBatchButtons(); configureBatchButtons();
} }
else else
{ {
MessagingController.getInstance(getApplication()).setFlag(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), mController.setFlag(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]),
(v == mBatchReadButton ? Flag.SEEN : Flag.FLAGGED), newState); (v == mBatchReadButton ? Flag.SEEN : Flag.FLAGGED), newState);
} }
} }
@ -2487,7 +2491,7 @@ public class MessageList
} }
} }
} }
MessagingController.getInstance(getApplication()).setFlag(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), mController.setFlag(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]),
flag , newState); flag , newState);
mHandler.sortMessages(); mHandler.sortMessages();
} }
@ -2506,7 +2510,7 @@ public class MessageList
} }
mAdapter.removeMessages(removeHolderList); mAdapter.removeMessages(removeHolderList);
MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), null); mController.deleteMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), null);
mSelectedCount = 0; mSelectedCount = 0;
configureBatchButtons(); configureBatchButtons();
} }