From 3217d4b772054c4067318d6a6110050fec775544 Mon Sep 17 00:00:00 2001 From: Bao-Long Nguyen-Trong Date: Sun, 14 Dec 2008 06:29:28 +0000 Subject: [PATCH] . fixed bug # 87: Acccounts all refresh at the same freqency --- src/com/fsck/k9/MessagingController.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/com/fsck/k9/MessagingController.java b/src/com/fsck/k9/MessagingController.java index 9b7a9f6d2..0390b6e39 100644 --- a/src/com/fsck/k9/MessagingController.java +++ b/src/com/fsck/k9/MessagingController.java @@ -1441,8 +1441,21 @@ s * critical data as fast as possible, and then we'll fill in the de accounts = Preferences.getPreferences(context).getAccounts(); } for (Account account : accounts) { - sendPendingMessagesSynchronous(account); - synchronizeMailboxSynchronous(account, k9.INBOX); + //We do the math in seconds and not millis + //since timers are not that accurate + long now = (long)Math.floor(System.currentTimeMillis() / 1000); + long autoCheckIntervalTime = account.getAutomaticCheckIntervalMinutes() * 60; + long lastAutoCheckTime = (long)Math.ceil(account.getLastAutomaticCheckTime() / 1000); + if (autoCheckIntervalTime>0 + && (now-lastAutoCheckTime)>autoCheckIntervalTime) { + sendPendingMessagesSynchronous(account); + synchronizeMailboxSynchronous(account, k9.INBOX); + //This saves the last auto check time even if sync fails + //TODO: Listen for both send and sync success and failures + //and only save last auto check time is not errors + account.setLastAutomaticCheckTime(now*1000); + account.save(Preferences.getPreferences(context)); + } } for (MessagingListener l : mListeners) { l.checkMailFinished(context, account);