From 1d0c9536fc5bb4954501b763f81e0c5a7d1995e0 Mon Sep 17 00:00:00 2001 From: Jabro Date: Thu, 11 Dec 2014 17:12:10 -0800 Subject: [PATCH] Support for ShortcutBadger // FREEBIE Closes #1574 Closes #1952 Fixes #1526 Fixes #321 --- build.gradle | 5 +++++ .../securesms/notifications/MessageNotifier.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/build.gradle b/build.gradle index 287dc397b9..865ac7cd75 100644 --- a/build.gradle +++ b/build.gradle @@ -27,9 +27,13 @@ repositories { maven { url "https://raw.github.com/whispersystems/maven/master/smil/releases/" } + maven { + url "https://raw.github.com/whispersystems/maven/master/shortcutbadger/releases/" + } } dependencies { + compile 'me.leolin:ShortcutBadger:1.0.2' compile 'se.emilsjolander:stickylistheaders:2.2.0' compile 'com.google.android.gms:play-services:6.1.71' compile 'com.astuetz:pagerslidingtabstrip:1.0.1' @@ -57,6 +61,7 @@ dependencies { dependencyVerification { verify = [ + 'me.leolin:ShortcutBadger:8fa86a47712d785f01a33dd157ae07209973224061bc1cf2f1cd1715585d196a', 'se.emilsjolander:stickylistheaders:89146b46c96fea0e40200474a2625cda10fe94891e4128f53cdb42375091b9b6', 'com.google.android.gms:play-services:32e7d1834a1cf8fa4b17e8d359db580c286e26c1eefbf84fdb9996eac8d74919', 'com.astuetz:pagerslidingtabstrip:f1641396732c7132a7abb837e482e5ee2b0ebb8d10813fc52bbaec2c15c184c2', diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 5594beb3d6..c850f7c7fc 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -56,6 +56,9 @@ import java.io.IOException; import java.util.List; import java.util.ListIterator; +import me.leolin.shortcutbadger.ShortcutBadgeException; +import me.leolin.shortcutbadger.ShortcutBadger; + /** * Handles posting system notifications for new messages. * @@ -134,6 +137,7 @@ public class MessageNotifier { { ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(NOTIFICATION_ID); + updateBadge(context, 0); return; } @@ -146,6 +150,8 @@ public class MessageNotifier { } else { sendSingleThreadNotification(context, masterSecret, notificationState, signal); } + + updateBadge(context, notificationState.getMessageCount()); } finally { if (telcoCursor != null) telcoCursor.close(); if (pushCursor != null) pushCursor.close(); @@ -384,4 +390,14 @@ public class MessageNotifier { return blinkPattern.split(","); } + + private static void updateBadge(Context context, int count) { + try { + ShortcutBadger.setBadge(context, count); + } catch (Throwable t) { + // NOTE :: I don't totally trust this thing, so I'm catching + // everything. + Log.w("MessageNotifier", t); + } + } }