aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/services/NotificationService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/services/NotificationService.java')
-rw-r--r--src/eu/siacs/conversations/services/NotificationService.java36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java
index 831ce51f..9428aa15 100644
--- a/src/eu/siacs/conversations/services/NotificationService.java
+++ b/src/eu/siacs/conversations/services/NotificationService.java
@@ -12,12 +12,11 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
+import android.os.PowerManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.text.Html;
-import android.util.Log;
-import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
@@ -41,12 +40,14 @@ public class NotificationService {
}
public synchronized void push(Message message) {
- if (this.mIsInForeground
+
+ PowerManager pm = (PowerManager) mXmppConnectionService
+ .getSystemService(Context.POWER_SERVICE);
+ boolean isScreenOn = pm.isScreenOn();
+
+ if (this.mIsInForeground && isScreenOn
&& this.mOpenConversation == message.getConversation()) {
- Log.d(Config.LOGTAG,"ignoring notification because foreground and conv matches");
return; // simply ignore
- } else {
- Log.d(Config.LOGTAG,"pushed new notification");
}
String conversationUuid = message.getConversationUuid();
if (notifications.containsKey(conversationUuid)) {
@@ -56,7 +57,8 @@ public class NotificationService {
mList.add(message);
notifications.put(conversationUuid, mList);
}
- updateNotification(!(this.mIsInForeground && this.mOpenConversation == null));
+ updateNotification(!(this.mIsInForeground && this.mOpenConversation == null)
+ || !isScreenOn);
}
public void clear() {
@@ -120,10 +122,11 @@ public class NotificationService {
+ mXmppConnectionService
.getString(R.string.unread_conversations));
StringBuilder names = new StringBuilder();
+ Conversation conversation = null;
for (ArrayList<Message> messages : notifications.values()) {
if (messages.size() > 0) {
- String name = messages.get(0).getConversation()
- .getName();
+ conversation = messages.get(0).getConversation();
+ String name = conversation.getName();
style.addLine(Html.fromHtml("<b>"
+ name
+ "</b> "
@@ -142,6 +145,10 @@ public class NotificationService {
.getString(R.string.unread_conversations));
mBuilder.setContentText(names.toString());
mBuilder.setStyle(style);
+ if (conversation != null) {
+ mBuilder.setContentIntent(createContentIntent(conversation
+ .getUuid()));
+ }
}
if (notify) {
if (vibrate) {
@@ -153,6 +160,7 @@ public class NotificationService {
mBuilder.setSound(Uri.parse(ringtone));
}
}
+ mBuilder.setDeleteIntent(createDeleteIntent());
mBuilder.setLights(0xffffffff, 2000, 4000);
Notification notification = mBuilder.build();
mNotificationManager.notify(NOTIFICATION_ID, notification);
@@ -178,9 +186,19 @@ public class NotificationService {
return resultPendingIntent;
}
+ private PendingIntent createDeleteIntent() {
+ Intent intent = new Intent(mXmppConnectionService,
+ XmppConnectionService.class);
+ intent.setAction("clear_notification");
+ return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
+ }
+
public static boolean wasHighlightedOrPrivate(Message message) {
String nick = message.getConversation().getMucOptions().getActualNick();
Pattern highlight = generateNickHighlightPattern(nick);
+ if (message.getBody() == null || nick == null) {
+ return false;
+ }
Matcher m = highlight.matcher(message.getBody());
return (m.find() || message.getType() == Message.TYPE_PRIVATE);
}