@@ -64,36 +64,55 @@ public class MessagePoller extends BroadcastReceiver {
final MergeCursor c = new MergeCursor(new Cursor[] { dmc, pmc });
if (c != null && c.moveToFirst()) {
- final CharSequence sender = c.getString(SENDER_COLUMN);
- final CharSequence body = c.getString(BODY_COLUMN);
-
- final Notification n = new Notification(R.drawable.stat_notify_blip, sender + ": " + body, System.currentTimeMillis());
- n.ledARGB = getLedColor(context);
- n.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_SHOW_LIGHTS;
- n.ledOffMS = 1000;
- n.ledOnMS = 200;
- n.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
- n.setLatestEventInfo(context, sender, body,
- PendingIntent.getActivity(context, 0, new Intent(context, Dashboard.class), Intent.FLAG_ACTIVITY_NEW_TASK));
+ int countDelta = 0;
+ final String myLogin = Blip.getUsername(context);
- NotificationManager nm = ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
+ int firstOther = -1;
+
+ do {
+ if (c.getString(SENDER_COLUMN).equals(myLogin))
+ countDelta++;
+ else
+ if (firstOther == -1)
+ firstOther = c.getPosition();
+ } while (c.moveToNext());
+ Notification n = null;
+ if (firstOther != -1) {
+ c.moveToPosition(firstOther);
+
+ final CharSequence sender = c.getString(SENDER_COLUMN);
+ final CharSequence body = c.getString(BODY_COLUMN);
+
+ n = new Notification(R.drawable.stat_notify_blip, sender + ": " + body, System.currentTimeMillis());
+ n.ledARGB = getLedColor(context);
+ n.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_SHOW_LIGHTS;
+ n.ledOffMS = 1000;
+ n.ledOnMS = 200;
+ n.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
+ n.setLatestEventInfo(context, sender, body,
+ PendingIntent.getActivity(context, 0, new Intent(context, Dashboard.class), Intent.FLAG_ACTIVITY_NEW_TASK));
+ }
+
final int oldCount = sharedPreferences.getInt(MESSAGE_COUNT_KEY, 0);
- final int count = oldCount + c.getCount();
-
- if (count > 1)
+ final int count = oldCount + c.getCount() - countDelta;
+
+ if (count > 1 && n != null)
n.number = count;
-
+
sharedPreferences.edit()
.putInt(LAST_SEEN_KEY, c.getInt(ID_COLUMN))
.putInt(FREQUENCY_KEY, INITIAL_FREQUENCY_MS)
.putInt(MESSAGE_COUNT_KEY, count)
.commit();
- if (oldCount == 1) // we need a new one to get the number displayed
- nm.cancel(NOTIFICATION_ID);
- nm.notify(NOTIFICATION_ID, n);
+ if (n != null) {
+ NotificationManager nm = ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
+ if (oldCount == 1) // we need a new one to get the number displayed
+ nm.cancel(NOTIFICATION_ID);
+ nm.notify(NOTIFICATION_ID, n);
+ }
}
scheduleNextPoll(context);