diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-01-05 13:14:48 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2015-01-05 13:14:48 +0100 |
commit | 8264474a0c7552368c4f0468b8c29977917eef30 (patch) | |
tree | 45708b374750ea0bc10100f57238f7aeb3f77197 /src/main/java/eu/siacs | |
parent | 07dc1627df2abd9a5e5fa8b562c8c2744cf39674 (diff) | |
parent | f1ebece8669768910707d3cc696b98390bddbfc0 (diff) |
Merge pull request #838 from shtrom/pebble-notifications-squash
Send notification to Pebble on new message
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/NotificationService.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index a30cf2f1..594b356f 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -21,11 +21,15 @@ import android.util.Log; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Calendar; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.json.JSONArray; +import org.json.JSONObject; + import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -65,6 +69,24 @@ public class NotificationService { ); } + public void notifyPebble(Message message) { + final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION"); + + final HashMap data = new HashMap(); + final Conversation conversation = message.getConversation(); + data.put("title", conversation.getName()); + data.put("body", message.getBody()); + final JSONObject jsonData = new JSONObject(data); + final String notificationData = new JSONArray().put(jsonData).toString(); + + i.putExtra("messageType", "PEBBLE_ALERT"); + i.putExtra("sender", "Conversations"); /* XXX: Shouldn't be hardcoded, e.g., AbstractGenerator.APP_NAME); */ + i.putExtra("notificationData", notificationData); + + mXmppConnectionService.sendBroadcast(i); + } + + public boolean notificationsEnabled() { return mXmppConnectionService.getPreferences().getBoolean("show_notification", true); } @@ -110,9 +132,13 @@ public class NotificationService { notifications.put(conversationUuid, mList); } final Account account = message.getConversation().getAccount(); - updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn) + final boolean doNotify = (!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn) && !account.inGracePeriod() - && !this.inMiniGracePeriod(account)); + && !this.inMiniGracePeriod(account); + updateNotification(doNotify); + if (doNotify) { + notifyPebble(message); + } } } |