mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-19 19:18:27 +00:00
Add a 'mark as read' button to expanded notifications.
This commit is contained in:
parent
8c1ca6c9e0
commit
dda5bc8838
@ -204,6 +204,14 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".notifications.MarkReadReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="org.thoughtcrime.securesms.notifications.CLEAR"></action>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<provider android:name=".providers.PartProvider"
|
||||
android:authorities="org.thoughtcrime.provider.securesms" />
|
||||
|
||||
|
@ -259,8 +259,10 @@
|
||||
<string name="MessageNotifier_no_subject">(No Subject)</string>
|
||||
<string name="MessageNotifier_message_delivery_failed">Message delivery failed.</string>
|
||||
<string name="MessageNotifier_failed_to_deliver_message">Failed to deliver message.</string>
|
||||
<string name="MessageNotifier_error_delivering_message">Error delivering message.</string>
|
||||
|
||||
<string name="MessageNotifier_error_delivering_message">Error delivering message.</string>
|
||||
<string name="MessageNotifier_mark_all_as_read">Mark all as read</string>
|
||||
<string name="MessageNotifier_mark_as_read">Mark as read</string>
|
||||
|
||||
<!-- SmsReceiver -->
|
||||
<string name="SmsReceiver_currently_unable_to_send_your_sms_message">Currently unable to send your SMS message. It will be sent once service becomes available.</string>
|
||||
|
||||
|
@ -0,0 +1,45 @@
|
||||
package org.thoughtcrime.securesms.notifications;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
|
||||
public class MarkReadReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR";
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
if (!intent.getAction().equals(CLEAR_ACTION))
|
||||
return;
|
||||
|
||||
final long[] threadIds = intent.getLongArrayExtra("thread_ids");
|
||||
final MasterSecret masterSecret = intent.getParcelableExtra("master_secret");
|
||||
|
||||
if (threadIds != null && masterSecret != null) {
|
||||
Log.w("MarkReadReceiver", "threadIds length: " + threadIds.length);
|
||||
|
||||
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
|
||||
.cancel(MessageNotifier.NOTIFICATION_ID);
|
||||
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
for (long threadId : threadIds) {
|
||||
Log.w("MarkReadReceiver", "Marking as read: " + threadId);
|
||||
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
|
||||
}
|
||||
|
||||
MessageNotifier.updateNotification(context, masterSecret);
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
}
|
@ -136,9 +136,9 @@ public class MessageNotifier {
|
||||
NotificationState notificationState = constructNotificationState(context, masterSecret, cursor);
|
||||
|
||||
if (notificationState.hasMultipleThreads()) {
|
||||
sendMultipleThreadNotification(context, notificationState, signal);
|
||||
sendMultipleThreadNotification(context, masterSecret, notificationState, signal);
|
||||
} else {
|
||||
sendSingleThreadNotification(context, notificationState, signal);
|
||||
sendSingleThreadNotification(context, masterSecret, notificationState, signal);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
@ -147,6 +147,7 @@ public class MessageNotifier {
|
||||
}
|
||||
|
||||
private static void sendSingleThreadNotification(Context context,
|
||||
MasterSecret masterSecret,
|
||||
NotificationState notificationState,
|
||||
boolean signal)
|
||||
{
|
||||
@ -160,6 +161,11 @@ public class MessageNotifier {
|
||||
builder.setContentText(notifications.get(0).getText());
|
||||
builder.setContentIntent(notifications.get(0).getPendingIntent(context));
|
||||
|
||||
if (masterSecret != null) {
|
||||
builder.addAction(R.drawable.check, context.getString(R.string.MessageNotifier_mark_as_read),
|
||||
notificationState.getMarkAsReadIntent(context, masterSecret));
|
||||
}
|
||||
|
||||
SpannableStringBuilder content = new SpannableStringBuilder();
|
||||
|
||||
for (NotificationItem item : notifications) {
|
||||
@ -180,6 +186,7 @@ public class MessageNotifier {
|
||||
}
|
||||
|
||||
private static void sendMultipleThreadNotification(Context context,
|
||||
MasterSecret masterSecret,
|
||||
NotificationState notificationState,
|
||||
boolean signal)
|
||||
{
|
||||
@ -195,6 +202,11 @@ public class MessageNotifier {
|
||||
notifications.get(0).getIndividualRecipientName()));
|
||||
builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, RoutingActivity.class), 0));
|
||||
|
||||
if (masterSecret != null) {
|
||||
builder.addAction(R.drawable.check, context.getString(R.string.MessageNotifier_mark_all_as_read),
|
||||
notificationState.getMarkAsReadIntent(context, masterSecret));
|
||||
}
|
||||
|
||||
InboxStyle style = new InboxStyle();
|
||||
|
||||
for (NotificationItem item : notifications) {
|
||||
|
@ -1,6 +1,12 @@
|
||||
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;
|
||||
@ -36,4 +42,26 @@ public class NotificationState {
|
||||
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, 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user