mirror of
https://github.com/moparisthebest/k-9
synced 2024-10-31 15:45:08 -04:00
Fixes Issue 1343
Fixes Issue 1126 Apply skisters2's patch for the POP notifications. Also, add another setRingNotified at the beginning of each poll to make sure the account is in the right state.
This commit is contained in:
parent
0e45438234
commit
5d18781156
@ -79,6 +79,9 @@ public class Account
|
|||||||
private String mExpungePolicy = EXPUNGE_IMMEDIATELY;
|
private String mExpungePolicy = EXPUNGE_IMMEDIATELY;
|
||||||
private int mMaxPushFolders;
|
private int mMaxPushFolders;
|
||||||
private Map<String, Boolean> compressionMap = new ConcurrentHashMap<String, Boolean>();
|
private Map<String, Boolean> compressionMap = new ConcurrentHashMap<String, Boolean>();
|
||||||
|
// Tracks if we have sent a notification for this account for
|
||||||
|
// current set of fetched messages
|
||||||
|
private boolean mRingNotified;
|
||||||
|
|
||||||
private List<Identity> identities;
|
private List<Identity> identities;
|
||||||
|
|
||||||
@ -544,6 +547,19 @@ public class Account
|
|||||||
mVibrate = vibrate;
|
mVibrate = vibrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Have we sent a new mail notification on this account */
|
||||||
|
public boolean isRingNotified()
|
||||||
|
{
|
||||||
|
return mRingNotified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRingNotified(boolean ringNotified)
|
||||||
|
{
|
||||||
|
mRingNotified = ringNotified;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized String getRingtone()
|
public synchronized String getRingtone()
|
||||||
{
|
{
|
||||||
return mRingtoneUri;
|
return mRingtoneUri;
|
||||||
|
@ -35,6 +35,7 @@ import android.os.Process;
|
|||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.fsck.k9.activity.FolderList;
|
import com.fsck.k9.activity.FolderList;
|
||||||
import com.fsck.k9.activity.MessageList;
|
import com.fsck.k9.activity.MessageList;
|
||||||
import com.fsck.k9.mail.Address;
|
import com.fsck.k9.mail.Address;
|
||||||
@ -1330,10 +1331,8 @@ public class MessagingController implements Runnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send a notification of this message
|
// Send a notification of this message
|
||||||
if (!message.isSet(Flag.SEEN) &&
|
if (notifyAccount(mApplication, account, message) == true)
|
||||||
(account.isNotifySelfNewMail() || account.isAnIdentity(message.getFrom()) == false))
|
|
||||||
{
|
{
|
||||||
notifyAccount(mApplication, account, message);
|
|
||||||
newMessages.incrementAndGet();
|
newMessages.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1425,6 +1424,7 @@ public class MessagingController implements Runnable
|
|||||||
l.synchronizeMailboxNewMessage(account, folder, localMessage);
|
l.synchronizeMailboxNewMessage(account, folder, localMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
notifyAccount(mApplication, account, message);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (MessagingException me)
|
catch (MessagingException me)
|
||||||
@ -1552,6 +1552,7 @@ public class MessagingController implements Runnable
|
|||||||
l.synchronizeMailboxNewMessage(account, folder, localMessage);
|
l.synchronizeMailboxNewMessage(account, folder, localMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
notifyAccount(mApplication, account, message);
|
||||||
}//for large messsages
|
}//for large messsages
|
||||||
if (K9.DEBUG)
|
if (K9.DEBUG)
|
||||||
Log.d(K9.LOG_TAG, "SYNC: Done fetching large messages for folder " + folder);
|
Log.d(K9.LOG_TAG, "SYNC: Done fetching large messages for folder " + folder);
|
||||||
@ -3901,14 +3902,14 @@ public class MessagingController implements Runnable
|
|||||||
{
|
{
|
||||||
if (K9.DEBUG)
|
if (K9.DEBUG)
|
||||||
Log.i(K9.LOG_TAG, "Skipping synchronizing account " + account.getDescription());
|
Log.i(K9.LOG_TAG, "Skipping synchronizing account " + account.getDescription());
|
||||||
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (K9.DEBUG)
|
if (K9.DEBUG)
|
||||||
Log.i(K9.LOG_TAG, "Synchronizing account " + account.getDescription());
|
Log.i(K9.LOG_TAG, "Synchronizing account " + account.getDescription());
|
||||||
|
|
||||||
|
account.setRingNotified(false);
|
||||||
|
|
||||||
putBackground("sendPending " + account.getDescription(), null, new Runnable()
|
putBackground("sendPending " + account.getDescription(), null, new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
@ -4077,6 +4078,20 @@ public class MessagingController implements Runnable
|
|||||||
Log.e(K9.LOG_TAG, "Unable to synchronize account " + account.getName(), e);
|
Log.e(K9.LOG_TAG, "Unable to synchronize account " + account.getName(), e);
|
||||||
addErrorMessage(account, e);
|
addErrorMessage(account, e);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
putBackground("clear notification flag for " + account.getDescription(), null, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (K9.DEBUG)
|
||||||
|
Log.v(K9.LOG_TAG, "Clearing notification flag for " + account.getDescription());
|
||||||
|
account.setRingNotified(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4171,10 +4186,14 @@ 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 void notifyAccount(Context context, Account account, Message message)
|
private boolean notifyAccount(Context context, Account account, Message message)
|
||||||
{
|
{
|
||||||
if (!account.isNotifyNewMail())
|
// Do not notify if the user does not have notifications
|
||||||
return;
|
// enabled or if the message has been read
|
||||||
|
if (!account.isNotifyNewMail() || message.isSet(Flag.SEEN))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// If we have a message, set the notification to "<From>: <Subject>"
|
// If we have a message, set the notification to "<From>: <Subject>"
|
||||||
StringBuffer messageNotice = new StringBuffer();
|
StringBuffer messageNotice = new StringBuffer();
|
||||||
@ -4182,8 +4201,8 @@ public class MessagingController implements Runnable
|
|||||||
{
|
{
|
||||||
if (message != null && message.getFrom() != null)
|
if (message != null && message.getFrom() != null)
|
||||||
{
|
{
|
||||||
Address[] addrs = message.getFrom();
|
Address[] fromAddrs = message.getFrom();
|
||||||
String from = addrs.length > 0 ? addrs[0].toFriendly() : null;
|
String from = fromAddrs.length > 0 ? fromAddrs[0].toFriendly() : null;
|
||||||
String subject = message.getSubject();
|
String subject = message.getSubject();
|
||||||
if (subject == null)
|
if (subject == null)
|
||||||
{
|
{
|
||||||
@ -4192,13 +4211,20 @@ public class MessagingController implements Runnable
|
|||||||
|
|
||||||
if (from != null)
|
if (from != null)
|
||||||
{
|
{
|
||||||
// Show From: address, except show To: if sent from me
|
// Show From: address by default
|
||||||
if (account.isAnIdentity(message.getFrom()) == false)
|
if (account.isAnIdentity(fromAddrs) == false)
|
||||||
{
|
{
|
||||||
messageNotice.append(from + ": " + subject);
|
messageNotice.append(from + ": " + subject);
|
||||||
}
|
}
|
||||||
|
// show To: if the message was sent from me
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Do not notify of mail from self if !isNotifySelfNewMail
|
||||||
|
if (!account.isNotifySelfNewMail())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Address[] rcpts = message.getRecipients(Message.RecipientType.TO);
|
Address[] rcpts = message.getRecipients(Message.RecipientType.TO);
|
||||||
String to = rcpts.length > 0 ? rcpts[0].toFriendly() : null;
|
String to = rcpts.length > 0 ? rcpts[0].toFriendly() : null;
|
||||||
if (to != null)
|
if (to != null)
|
||||||
@ -4247,23 +4273,29 @@ public class MessagingController implements Runnable
|
|||||||
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, 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
|
||||||
|
// account and fetch
|
||||||
|
if (!account.isRingNotified())
|
||||||
|
{
|
||||||
|
account.setRingNotified(true);
|
||||||
if (account.isRing())
|
if (account.isRing())
|
||||||
{
|
{
|
||||||
String ringtone = account.getRingtone();
|
String ringtone = account.getRingtone();
|
||||||
notif.sound = TextUtils.isEmpty(ringtone) ? null : Uri.parse(ringtone);
|
notif.sound = TextUtils.isEmpty(ringtone) ? null : Uri.parse(ringtone);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account.isVibrate())
|
if (account.isVibrate())
|
||||||
{
|
{
|
||||||
notif.defaults |= Notification.DEFAULT_VIBRATE;
|
notif.defaults |= Notification.DEFAULT_VIBRATE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
notif.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONLY_ALERT_ONCE;
|
notif.flags |= Notification.FLAG_SHOW_LIGHTS;
|
||||||
notif.ledARGB = K9.NOTIFICATION_LED_COLOR;
|
notif.ledARGB = K9.NOTIFICATION_LED_COLOR;
|
||||||
notif.ledOnMS = K9.NOTIFICATION_LED_ON_TIME;
|
notif.ledOnMS = K9.NOTIFICATION_LED_ON_TIME;
|
||||||
notif.ledOffMS = K9.NOTIFICATION_LED_OFF_TIME;
|
notif.ledOffMS = K9.NOTIFICATION_LED_OFF_TIME;
|
||||||
|
|
||||||
notifMgr.notify(account.getAccountNumber(), notif);
|
notifMgr.notify(account.getAccountNumber(), notif);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Cancel a notification of new email messages */
|
/** Cancel a notification of new email messages */
|
||||||
@ -4565,6 +4597,7 @@ public class MessagingController implements Runnable
|
|||||||
localFolder= localStore.getFolder(remoteFolder.getName());
|
localFolder= localStore.getFolder(remoteFolder.getName());
|
||||||
localFolder.open(OpenMode.READ_WRITE);
|
localFolder.open(OpenMode.READ_WRITE);
|
||||||
|
|
||||||
|
account.setRingNotified(false);
|
||||||
int newCount = downloadMessages(account, remoteFolder, localFolder, messages, flagSyncOnly);
|
int newCount = downloadMessages(account, remoteFolder, localFolder, messages, flagSyncOnly);
|
||||||
int unreadMessageCount = setLocalUnreadCountToRemote(localFolder, remoteFolder, messages.size());
|
int unreadMessageCount = setLocalUnreadCountToRemote(localFolder, remoteFolder, messages.size());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user