1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-14 21:45:14 -05:00

Rather than doing a full count of all the unread messages in each and

every folder for each message downloaded in a session, factor the
"unread messages" count out into the calling code.  It's slightly less
clean, but a pretty huge performance gain.

Fixes issue 1443
This commit is contained in:
Jesse Vincent 2010-07-15 03:42:13 +00:00
parent 1bea931ed0
commit d3cc1fdfdc

View File

@ -1681,6 +1681,21 @@ public class MessagingController implements Runnable
final Date earliestDate = account.getEarliestPollDate(); final Date earliestDate = account.getEarliestPollDate();
int tmpRead = 0;
try
{
AccountStats stats = account.getStats(mApplication);
tmpRead = stats.unreadMessageCount;
}
catch (MessagingException e)
{
Log.e(K9.LOG_TAG, "Unable to getUnreadMessageCount for account: " + account, e);
}
final int unreadBeforeStart = tmpRead;
if (K9.DEBUG) if (K9.DEBUG)
Log.d(K9.LOG_TAG, "SYNC: Fetching small messages for folder " + folder); Log.d(K9.LOG_TAG, "SYNC: Fetching small messages for folder " + folder);
@ -1723,11 +1738,12 @@ public class MessagingController implements Runnable
} }
} }
// Send a notification of this message // Send a notification of this message
if (notifyAccount(mApplication, account, message) == true)
if (notifyAccount(mApplication, account, message, (unreadBeforeStart + newMessages.get())) == true)
{ {
newMessages.incrementAndGet(); newMessages.incrementAndGet();
} }
}
} }
@ -1763,6 +1779,20 @@ public class MessagingController implements Runnable
final String folder = remoteFolder.getName(); final String folder = remoteFolder.getName();
final Date earliestDate = account.getEarliestPollDate(); final Date earliestDate = account.getEarliestPollDate();
int unreadBeforeStart = 0;
try
{
AccountStats stats = account.getStats(mApplication);
unreadBeforeStart = stats.unreadMessageCount;
}
catch (MessagingException e)
{
Log.e(K9.LOG_TAG, "Unable to getUnreadMessageCount for account: " + account, e);
}
if (K9.DEBUG) if (K9.DEBUG)
Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder); Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder);
@ -1868,7 +1898,7 @@ public class MessagingController implements Runnable
} }
// Send a notification of this message // Send a notification of this message
if (notifyAccount(mApplication, account, message) == true) if (notifyAccount(mApplication, account, message, (unreadBeforeStart+newMessages.get())) == true)
{ {
newMessages.incrementAndGet(); newMessages.incrementAndGet();
} }
@ -4511,19 +4541,8 @@ public class MessagingController implements Runnable
/** Creates a notification of new email messages /** Creates a notification of new email messages
* ringtone, lights, and vibration to be played * ringtone, lights, and vibration to be played
*/ */
private boolean notifyAccount(Context context, Account account, Message message) private boolean notifyAccount(Context context, Account account, Message message, int unreadMessageCount)
{ {
int unreadMessageCount = 0;
try
{
AccountStats stats = account.getStats(context);
unreadMessageCount = stats.unreadMessageCount;
}
catch (MessagingException e)
{
Log.e(K9.LOG_TAG, "Unable to getUnreadMessageCount for account: " + account, e);
}
// Do not notify if the user does not have notifications // Do not notify if the user does not have notifications
// enabled or if the message has been read // enabled or if the message has been read
if (!account.isNotifyNewMail() || message.isSet(Flag.SEEN)) if (!account.isNotifyNewMail() || message.isSet(Flag.SEEN))
@ -4531,6 +4550,7 @@ public class MessagingController implements Runnable
return false; return false;
} }
Folder folder = message.getFolder(); Folder folder = message.getFolder();
if (folder != null) if (folder != null)
{ {
@ -4596,6 +4616,8 @@ public class MessagingController implements Runnable
{ {
Log.e(K9.LOG_TAG, "Unable to get message information for notification.", e); Log.e(K9.LOG_TAG, "Unable to get message information for notification.", e);
} }
// If we could not set a per-message notification, revert to a default message // If we could not set a per-message notification, revert to a default message
if (messageNotice.length() == 0) if (messageNotice.length() == 0)
{ {
@ -4606,12 +4628,12 @@ public class MessagingController implements Runnable
NotificationManager notifMgr = NotificationManager notifMgr =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = new Notification(R.drawable.stat_notify_email_generic, messageNotice, System.currentTimeMillis()); Notification notif = new Notification(R.drawable.stat_notify_email_generic, messageNotice, System.currentTimeMillis());
notif.number = unreadMessageCount; notif.number = unreadMessageCount+1;
Intent i = FolderList.actionHandleNotification(context, account, account.getAutoExpandFolderName()); Intent i = FolderList.actionHandleNotification(context, account, account.getAutoExpandFolderName());
PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0); PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0);
String accountNotice = context.getString(R.string.notification_new_one_account_fmt, unreadMessageCount, account.getDescription()); String accountNotice = context.getString(R.string.notification_new_one_account_fmt, (unreadMessageCount+1), account.getDescription());
notif.setLatestEventInfo(context, accountNotice, messageNotice, pi); notif.setLatestEventInfo(context, accountNotice, messageNotice, pi);
// Only ring or vibrate if we have not done so already on this // Only ring or vibrate if we have not done so already on this