Support for ShortcutBadger

// FREEBIE

Closes #1574
Closes #1952

Fixes #1526
Fixes #321
This commit is contained in:
Jabro 2014-12-11 17:12:10 -08:00 committed by Moxie Marlinspike
parent 3c4ac4b105
commit 1d0c9536fc
2 changed files with 21 additions and 0 deletions

View File

@ -27,9 +27,13 @@ repositories {
maven { maven {
url "https://raw.github.com/whispersystems/maven/master/smil/releases/" url "https://raw.github.com/whispersystems/maven/master/smil/releases/"
} }
maven {
url "https://raw.github.com/whispersystems/maven/master/shortcutbadger/releases/"
}
} }
dependencies { dependencies {
compile 'me.leolin:ShortcutBadger:1.0.2'
compile 'se.emilsjolander:stickylistheaders:2.2.0' compile 'se.emilsjolander:stickylistheaders:2.2.0'
compile 'com.google.android.gms:play-services:6.1.71' compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1' compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
@ -57,6 +61,7 @@ dependencies {
dependencyVerification { dependencyVerification {
verify = [ verify = [
'me.leolin:ShortcutBadger:8fa86a47712d785f01a33dd157ae07209973224061bc1cf2f1cd1715585d196a',
'se.emilsjolander:stickylistheaders:89146b46c96fea0e40200474a2625cda10fe94891e4128f53cdb42375091b9b6', 'se.emilsjolander:stickylistheaders:89146b46c96fea0e40200474a2625cda10fe94891e4128f53cdb42375091b9b6',
'com.google.android.gms:play-services:32e7d1834a1cf8fa4b17e8d359db580c286e26c1eefbf84fdb9996eac8d74919', 'com.google.android.gms:play-services:32e7d1834a1cf8fa4b17e8d359db580c286e26c1eefbf84fdb9996eac8d74919',
'com.astuetz:pagerslidingtabstrip:f1641396732c7132a7abb837e482e5ee2b0ebb8d10813fc52bbaec2c15c184c2', 'com.astuetz:pagerslidingtabstrip:f1641396732c7132a7abb837e482e5ee2b0ebb8d10813fc52bbaec2c15c184c2',

View File

@ -56,6 +56,9 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import me.leolin.shortcutbadger.ShortcutBadgeException;
import me.leolin.shortcutbadger.ShortcutBadger;
/** /**
* Handles posting system notifications for new messages. * Handles posting system notifications for new messages.
* *
@ -134,6 +137,7 @@ public class MessageNotifier {
{ {
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)) ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
.cancel(NOTIFICATION_ID); .cancel(NOTIFICATION_ID);
updateBadge(context, 0);
return; return;
} }
@ -146,6 +150,8 @@ public class MessageNotifier {
} else { } else {
sendSingleThreadNotification(context, masterSecret, notificationState, signal); sendSingleThreadNotification(context, masterSecret, notificationState, signal);
} }
updateBadge(context, notificationState.getMessageCount());
} finally { } finally {
if (telcoCursor != null) telcoCursor.close(); if (telcoCursor != null) telcoCursor.close();
if (pushCursor != null) pushCursor.close(); if (pushCursor != null) pushCursor.close();
@ -384,4 +390,14 @@ public class MessageNotifier {
return blinkPattern.split(","); 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);
}
}
} }