2013-02-08 19:57:54 +00:00
|
|
|
package org.thoughtcrime.securesms.notifications;
|
|
|
|
|
2013-05-30 19:39:56 +00:00
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2013-02-08 19:57:54 +00:00
|
|
|
import android.graphics.Bitmap;
|
2014-01-19 02:25:51 +00:00
|
|
|
import android.util.Log;
|
2013-05-30 19:39:56 +00:00
|
|
|
|
2013-08-18 01:37:18 +00:00
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2013-02-08 19:57:54 +00:00
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
public class NotificationState {
|
|
|
|
|
|
|
|
private final LinkedList<NotificationItem> notifications = new LinkedList<NotificationItem>();
|
|
|
|
private final Set<Long> threads = new HashSet<Long>();
|
|
|
|
|
|
|
|
private int notificationCount = 0;
|
|
|
|
|
|
|
|
public void addNotification(NotificationItem item) {
|
|
|
|
notifications.addFirst(item);
|
|
|
|
threads.add(item.getThreadId());
|
|
|
|
notificationCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasMultipleThreads() {
|
|
|
|
return threads.size() > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMessageCount() {
|
|
|
|
return notificationCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<NotificationItem> getNotifications() {
|
|
|
|
return notifications;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Bitmap getContactPhoto() {
|
2013-04-26 01:59:49 +00:00
|
|
|
return notifications.get(0).getIndividualRecipient().getContactPhoto();
|
2013-02-08 19:57:54 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 19:39:56 +00:00
|
|
|
public PendingIntent getMarkAsReadIntent(Context context, MasterSecret masterSecret) {
|
2014-01-19 02:25:51 +00:00
|
|
|
long[] threadArray = new long[threads.size()];
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
for (long thread : threads) {
|
|
|
|
Log.w("NotificationState", "Added thread: " + thread);
|
|
|
|
threadArray[index++] = thread;
|
|
|
|
}
|
|
|
|
|
2013-05-30 19:39:56 +00:00
|
|
|
Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION);
|
2014-01-19 02:25:51 +00:00
|
|
|
intent.putExtra("thread_ids", threadArray);
|
2013-05-30 19:39:56 +00:00
|
|
|
intent.putExtra("master_secret", masterSecret);
|
|
|
|
intent.setPackage(context.getPackageName());
|
|
|
|
|
2014-01-19 02:25:51 +00:00
|
|
|
// XXX : This is an Android bug. If we don't pull off the extra
|
|
|
|
// once before handing off the PendingIntent, the array will be
|
|
|
|
// truncated to one element when the PendingIntent fires. Thanks guys!
|
|
|
|
Log.w("NotificationState", "Pending array off intent length: " +
|
|
|
|
intent.getLongArrayExtra("thread_ids").length);
|
|
|
|
|
2013-12-03 21:48:16 +00:00
|
|
|
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
2013-05-30 19:39:56 +00:00
|
|
|
}
|
2013-02-08 19:57:54 +00:00
|
|
|
}
|