synchronization for notification

This commit is contained in:
iNPUTmice 2014-10-15 14:33:13 +02:00
parent 1428628a5d
commit f063b1c063
1 changed files with 17 additions and 11 deletions

View File

@ -43,34 +43,40 @@ public class NotificationService {
.getSystemService(Context.NOTIFICATION_SERVICE); .getSystemService(Context.NOTIFICATION_SERVICE);
} }
public synchronized void push(Message message) { public void push(Message message) {
PowerManager pm = (PowerManager) mXmppConnectionService PowerManager pm = (PowerManager) mXmppConnectionService
.getSystemService(Context.POWER_SERVICE); .getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn(); boolean isScreenOn = pm.isScreenOn();
if (this.mIsInForeground && isScreenOn if (this.mIsInForeground && isScreenOn
&& this.mOpenConversation == message.getConversation()) { && this.mOpenConversation == message.getConversation()) {
return; return;
} }
String conversationUuid = message.getConversationUuid(); synchronized (notifications) {
if (notifications.containsKey(conversationUuid)) { String conversationUuid = message.getConversationUuid();
notifications.get(conversationUuid).add(message); if (notifications.containsKey(conversationUuid)) {
} else { notifications.get(conversationUuid).add(message);
ArrayList<Message> mList = new ArrayList<Message>(); } else {
mList.add(message); ArrayList<Message> mList = new ArrayList<Message>();
notifications.put(conversationUuid, mList); mList.add(message);
notifications.put(conversationUuid, mList);
}
} }
updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn) updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
&& !inGracePeriod()); && !inGracePeriod());
} }
public void clear() { public void clear() {
notifications.clear(); synchronized (notifications) {
notifications.clear();
}
updateNotification(false); updateNotification(false);
} }
public void clear(Conversation conversation) { public void clear(Conversation conversation) {
notifications.remove(conversation.getUuid()); synchronized (notifications) {
notifications.remove(conversation.getUuid());
}
updateNotification(false); updateNotification(false);
} }