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

backport trunk changes to MessagingController to (hopefully) improve our

unread-counter situation
This commit is contained in:
Jesse Vincent 2010-08-08 19:59:18 +00:00
parent e390fdf183
commit dfeced4879

View File

@ -1352,6 +1352,18 @@ public class MessagingController implements Runnable
}
final String folder = remoteFolder.getName();
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);
}
ArrayList<Message> syncFlagMessages = new ArrayList<Message>();
List<Message> unsyncedMessages = new ArrayList<Message>();
final AtomicInteger newMessages = new AtomicInteger(0);
@ -1507,10 +1519,7 @@ public class MessagingController implements Runnable
// fp.add(FetchProfile.Item.FLAGS);
// fp.add(FetchProfile.Item.ENVELOPE);
downloadSmallMessages(account, remoteFolder, localFolder, smallMessages, progress, newMessages, todo, fp);
downloadSmallMessages(account, remoteFolder, localFolder, smallMessages, progress, unreadBeforeStart, newMessages, todo, fp);
smallMessages.clear();
@ -1523,7 +1532,7 @@ public class MessagingController implements Runnable
downloadLargeMessages(account, remoteFolder, localFolder, largeMessages, progress, newMessages, todo, fp);
downloadLargeMessages(account, remoteFolder, localFolder, largeMessages, progress, unreadBeforeStart, newMessages, todo, fp);
largeMessages.clear();
/*
@ -1689,6 +1698,7 @@ public class MessagingController implements Runnable
final LocalFolder localFolder,
ArrayList<Message> smallMessages,
final AtomicInteger progress,
final int unreadBeforeStart,
final AtomicInteger newMessages,
final int todo,
FetchProfile fp) throws MessagingException
@ -1697,22 +1707,6 @@ public class MessagingController implements Runnable
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)
Log.d(K9.LOG_TAG, "SYNC: Fetching small messages for folder " + folder);
@ -1755,13 +1749,12 @@ public class MessagingController implements Runnable
}
// Send a notification of this message
if (notifyAccount(mApplication, account, message, (unreadBeforeStart + newMessages.get())) == true)
if (shouldNotifyForMessage(account, message))
{
newMessages.incrementAndGet();
notifyAccount(mApplication, account, message, unreadBeforeStart, newMessages);
}
}
catch (MessagingException me)
{
@ -1788,6 +1781,7 @@ public class MessagingController implements Runnable
final LocalFolder localFolder,
ArrayList<Message> largeMessages,
final AtomicInteger progress,
final int unreadBeforeStart,
final AtomicInteger newMessages,
final int todo,
FetchProfile fp) throws MessagingException
@ -1796,19 +1790,6 @@ public class MessagingController implements Runnable
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)
Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder);
@ -1914,12 +1895,12 @@ public class MessagingController implements Runnable
}
// Send a notification of this message
if (notifyAccount(mApplication, account, message, (unreadBeforeStart+newMessages.get())) == true)
if (shouldNotifyForMessage(account, message))
{
newMessages.incrementAndGet();
notifyAccount(mApplication, account, message, unreadBeforeStart, newMessages);
}
}//for large messsages
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "SYNC: Done fetching large messages for folder " + folder);
@ -4401,9 +4382,7 @@ public class MessagingController implements Runnable
account.setRingNotified(false);
try
{
AccountStats stats = account.getStats(context);
int unreadMessageCount = stats.unreadMessageCount;
if (unreadMessageCount == 0)
if (account.getStats(context).unreadMessageCount == 0)
{
notifyAccountCancel(context, account);
}
@ -4550,10 +4529,8 @@ public class MessagingController implements Runnable
});
}
/** Creates a notification of new email messages
* ringtone, lights, and vibration to be played
*/
private boolean notifyAccount(Context context, Account account, Message message, int unreadMessageCount)
private boolean shouldNotifyForMessage(Account account, Message message)
{
// Do not notify if the user does not have notifications
// enabled or if the message has been read
@ -4578,6 +4555,17 @@ public class MessagingController implements Runnable
}
}
return true;
}
/** Creates a notification of new email messages
* ringtone, lights, and vibration to be played
*/
private boolean notifyAccount(Context context, Account account, Message message, int previousUnreadMessageCount, AtomicInteger newMessageCount)
{
// If we have a message, set the notification to "<From>: <Subject>"
StringBuffer messageNotice = new StringBuffer();
try
@ -4602,7 +4590,6 @@ public class MessagingController implements Runnable
// show To: if the message was sent from me
else
{
// Do not notify of mail from self if !isNotifySelfNewMail
if (!account.isNotifySelfNewMail())
{
return false;
@ -4636,16 +4623,15 @@ public class MessagingController implements Runnable
messageNotice.append(context.getString(R.string.notification_new_title));
}
NotificationManager notifMgr =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = new Notification(R.drawable.stat_notify_email_generic, messageNotice, System.currentTimeMillis());
notif.number = unreadMessageCount;
notif.number = previousUnreadMessageCount + newMessageCount.get();
Intent i = FolderList.actionHandleNotification(context, account, account.getAutoExpandFolderName());
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, notif.number, account.getDescription());
notif.setLatestEventInfo(context, accountNotice, messageNotice, pi);
// Only ring or vibrate if we have not done so already on this