diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-10-07 13:37:50 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-10-07 13:37:50 +0200 |
commit | d5227e5c253658eb9d6bc1f7bf85397f072125d4 (patch) | |
tree | c87bfdf56479421086993fa9b900765281f28947 /src/eu/siacs/conversations/services/NotificationService.java | |
parent | 7f524352730edc630697c693a040ca570cbcedb3 (diff) |
refactored grace period
Diffstat (limited to '')
-rw-r--r-- | src/eu/siacs/conversations/services/NotificationService.java | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index 9428aa15..53c4707f 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -13,10 +13,12 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.PowerManager; +import android.os.SystemClock; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.text.Html; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; @@ -32,6 +34,8 @@ public class NotificationService { public int NOTIFICATION_ID = 0x2342; private Conversation mOpenConversation; private boolean mIsInForeground; + + private long mEndGracePeriod = 0L; public NotificationService(XmppConnectionService service) { this.mXmppConnectionService = service; @@ -44,10 +48,9 @@ public class NotificationService { PowerManager pm = (PowerManager) mXmppConnectionService .getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); - if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { - return; // simply ignore + return; } String conversationUuid = message.getConversationUuid(); if (notifications.containsKey(conversationUuid)) { @@ -57,8 +60,8 @@ public class NotificationService { mList.add(message); notifications.put(conversationUuid, mList); } - updateNotification(!(this.mIsInForeground && this.mOpenConversation == null) - || !isScreenOn); + updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) + || !isScreenOn) && !inGracePeriod()); } public void clear() { @@ -161,7 +164,9 @@ public class NotificationService { } } mBuilder.setDeleteIntent(createDeleteIntent()); - mBuilder.setLights(0xffffffff, 2000, 4000); + if (!inGracePeriod()) { + mBuilder.setLights(0xffffffff, 2000, 4000); + } Notification notification = mBuilder.build(); mNotificationManager.notify(NOTIFICATION_ID, notification); } @@ -221,4 +226,16 @@ public class NotificationService { this.mIsInForeground = foreground; } + + public void activateGracePeriod() { + this.mEndGracePeriod = SystemClock.elapsedRealtime() + (Config.CARBON_GRACE_PERIOD * 1000); + } + + public void deactivateGracePeriod() { + this.mEndGracePeriod = 0L; + } + + private boolean inGracePeriod() { + return SystemClock.elapsedRealtime() < this.mEndGracePeriod; + } } |