1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

. Added silent 'on going' notification when checking email

This commit is contained in:
Bao-Long Nguyen-Trong 2008-12-19 22:30:55 +00:00
parent b9dec4064e
commit 56d1ede846
3 changed files with 73 additions and 45 deletions

View File

@ -69,6 +69,9 @@
<string name="notification_new_multi_account_fmt">in <xliff:g id="number_accounts">%d</xliff:g> accounts</string> <string name="notification_new_multi_account_fmt">in <xliff:g id="number_accounts">%d</xliff:g> accounts</string>
<string name="notification_unsent_title">Message not sent</string> <string name="notification_unsent_title">Message not sent</string>
<string name="notification_bg_sync_ticker">Checking email: <xliff:g id="account">%s</xliff:g></string>
<string name="notification_bg_sync_title">Checking email</string>
<string name="special_mailbox_name_inbox">Inbox</string> <string name="special_mailbox_name_inbox">Inbox</string>
<string name="special_mailbox_name_outbox">Outbox</string> <string name="special_mailbox_name_outbox">Outbox</string>
<!-- The following mailbox names will be used if the user has not specified one from the server --> <!-- The following mailbox names will be used if the user has not specified one from the server -->

View File

@ -120,7 +120,8 @@ public class Email extends Application {
*/ */
public static final int NOTIFICATION_LED_OFF_TIME = 2000; public static final int NOTIFICATION_LED_OFF_TIME = 2000;
public static final int NEW_EMAIL_NOTIFICATION_ID = 1; public static final int NEW_EMAIL_NOTIFICATION_ID = 1;
public static final int FETCHING_EMAIL_NOTIFICATION_ID = 2;
/** /**
* Called throughout the application when the number of accounts has changed. This method * Called throughout the application when the number of accounts has changed. This method

View File

@ -10,11 +10,16 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import android.app.Application; import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.Process; import android.os.Process;
import android.util.Config; import android.util.Config;
import android.util.Log; import android.util.Log;
import com.android.email.activity.FolderMessageList;
import com.android.email.mail.FetchProfile; import com.android.email.mail.FetchProfile;
import com.android.email.mail.Flag; import com.android.email.mail.Flag;
import com.android.email.mail.Folder; import com.android.email.mail.Folder;
@ -1432,33 +1437,52 @@ s * critical data as fast as possible, and then we'll fill in the de
} }
put("checkMail", listener, new Runnable() { put("checkMail", listener, new Runnable() {
public void run() { public void run() {
Account[] accounts; NotificationManager notifMgr = (NotificationManager)context
if (account != null) { .getSystemService(Context.NOTIFICATION_SERVICE);
accounts = new Account[] { try {
account Account[] accounts;
}; if (account != null) {
} else { accounts = new Account[] {
accounts = Preferences.getPreferences(context).getAccounts(); account
} };
for (Account account : accounts) { } else {
//We do the math in seconds and not millis accounts = Preferences.getPreferences(context).getAccounts();
//since timers are not that accurate }
long now = (long)Math.floor(System.currentTimeMillis() / 1000); for (Account account : accounts) {
long autoCheckIntervalTime = account.getAutomaticCheckIntervalMinutes() * 60; //We do the math in seconds and not millis
long lastAutoCheckTime = (long)Math.ceil(account.getLastAutomaticCheckTime() / 1000); //since timers are not that accurate
if (autoCheckIntervalTime>0 long now = (long)Math.floor(System.currentTimeMillis() / 1000);
&& (now-lastAutoCheckTime)>autoCheckIntervalTime) { long autoCheckIntervalTime = account.getAutomaticCheckIntervalMinutes() * 60;
sendPendingMessagesSynchronous(account); long lastAutoCheckTime = (long)Math.ceil(account.getLastAutomaticCheckTime() / 1000);
synchronizeMailboxSynchronous(account, Email.INBOX); if (autoCheckIntervalTime>0
//This saves the last auto check time even if sync fails && (now-lastAutoCheckTime)>autoCheckIntervalTime) {
//TODO: Listen for both send and sync success and failures Notification notif = new Notification(R.drawable.ic_menu_refresh, context.getString(R.string.notification_bg_sync_ticker, account.getDescription()), System.currentTimeMillis());
//and only save last auto check time is not errors Intent intent = FolderMessageList.actionHandleAccountIntent(context, account, Email.INBOX);
account.setLastAutomaticCheckTime(now*1000); PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
account.save(Preferences.getPreferences(context)); notif.setLatestEventInfo(context, context.getString(R.string.notification_bg_sync_title), account.getDescription(), pi);
notif.flags = Notification.FLAG_ONGOING_EVENT;
notifMgr.notify(Email.FETCHING_EMAIL_NOTIFICATION_ID, notif);
sendPendingMessagesSynchronous(account);
synchronizeMailboxSynchronous(account, Email.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);
} }
} }
for (MessagingListener l : mListeners) { catch (Exception e) {
l.checkMailFinished(context, account); for (MessagingListener l : mListeners) {
l.checkMailFailed(context, account, e.getMessage());
}
}
finally {
notifMgr.cancel(Email.FETCHING_EMAIL_NOTIFICATION_ID);
} }
} }
}); });