mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 12:35:17 +00:00
a3f1d9cdfd
1) Break out appropriate components. 2) Switch the incoming pipeline from SendReceiveService to the JobManager.
68 lines
2.0 KiB
Java
68 lines
2.0 KiB
Java
package org.thoughtcrime.securesms.notifications;
|
|
|
|
import android.app.PendingIntent;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.util.Log;
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
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() {
|
|
return notifications.get(0).getIndividualRecipient().getContactPhoto();
|
|
}
|
|
|
|
public PendingIntent getMarkAsReadIntent(Context context, MasterSecret masterSecret) {
|
|
long[] threadArray = new long[threads.size()];
|
|
int index = 0;
|
|
|
|
for (long thread : threads) {
|
|
Log.w("NotificationState", "Added thread: " + thread);
|
|
threadArray[index++] = thread;
|
|
}
|
|
|
|
Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION);
|
|
intent.putExtra("thread_ids", threadArray);
|
|
intent.putExtra("master_secret", masterSecret);
|
|
intent.setPackage(context.getPackageName());
|
|
|
|
// 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);
|
|
|
|
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
}
|
|
}
|