Messaging: Add "Mark as read" quick action for message notifications

Signed-off-by: Luca Stefani <luca.stefani.ge1@gmail.com>
Change-Id: I7194dca022e5062926fa35709de282721ca64320
This commit is contained in:
Paul Keith
2020-03-16 15:14:40 +01:00
committed by Luca Stefani
parent 1dc43f0e09
commit f19e916a0d
8 changed files with 85 additions and 4 deletions
@@ -833,7 +833,8 @@ public class BugleNotifications {
maybeAddWearableConversationLog(wearableExtender,
(MultiMessageNotificationState) notificationState);
addDownloadMmsAction(notifBuilder, wearableExtender, notificationState);
addWearableVoiceReplyAction(wearableExtender, notificationState);
addReplyAction(notifBuilder, wearableExtender, notificationState);
addReadAction(notifBuilder, wearableExtender, notificationState);
}
// Apply the wearable options and build & post the notification
@@ -875,7 +876,7 @@ public class BugleNotifications {
}
}
private static void addWearableVoiceReplyAction(
private static void addReplyAction(final NotificationCompat.Builder notifBuilder,
final WearableExtender wearableExtender, final NotificationState notificationState) {
if (!(notificationState instanceof MultiMessageNotificationState)) {
return;
@@ -912,9 +913,25 @@ public class BugleNotifications {
setChoices(choices)
.build();
actionBuilder.addRemoteInput(remoteInput);
notifBuilder.addAction(actionBuilder.build());
// Support the action on a wearable device as well
wearableExtender.addAction(actionBuilder.build());
}
private static void addReadAction(final NotificationCompat.Builder notifBuilder,
final WearableExtender wearableExtender, final NotificationState notificationState) {
final Context context = Factory.get().getApplicationContext();
final PendingIntent readPendingIntent = notificationState.getReadIntent();
final NotificationCompat.Action.Builder readActionBuilder =
new NotificationCompat.Action.Builder(R.drawable.ic_wear_read,
context.getString(R.string.notification_mark_as_read), readPendingIntent);
notifBuilder.addAction(readActionBuilder.build());
// Support the action on a wearable device as well
wearableExtender.addAction(readActionBuilder.build());
}
private static void addDownloadMmsAction(final NotificationCompat.Builder notifBuilder,
final WearableExtender wearableExtender, final NotificationState notificationState) {
if (!(notificationState instanceof MultiMessageNotificationState)) {
@@ -350,6 +350,14 @@ public abstract class MessageNotificationState extends NotificationState {
getClearIntentRequestCode());
}
@Override
public PendingIntent getReadIntent() {
return UIIntents.get().getPendingIntentForMarkingAsRead(
Factory.get().getApplicationContext(),
mConversationIds,
getReadIntentRequestCode());
}
/**
* Notification for multiple messages in at least 2 different conversations.
*/
@@ -43,7 +43,8 @@ import java.util.HashSet;
public abstract class NotificationState {
private static final int CONTENT_INTENT_REQUEST_CODE_OFFSET = 0;
private static final int CLEAR_INTENT_REQUEST_CODE_OFFSET = 1;
private static final int NUM_REQUEST_CODES_NEEDED = 2;
private static final int READ_INTENT_REQUEST_CODE_OFFSET = 2;
private static final int NUM_REQUEST_CODES_NEEDED = 3;
public interface FailedMessageQuery {
static final String FAILED_MESSAGES_WHERE_CLAUSE =
@@ -78,6 +79,11 @@ public abstract class NotificationState {
*/
public abstract PendingIntent getClearIntent();
/**
* The intent to be triggered when mark as read is pressed.
*/
public abstract PendingIntent getReadIntent();
protected Uri getAttachmentUri() {
return null;
}
@@ -116,6 +122,10 @@ public abstract class NotificationState {
return mBaseRequestCode + CLEAR_INTENT_REQUEST_CODE_OFFSET;
}
public int getReadIntentRequestCode() {
return mBaseRequestCode + READ_INTENT_REQUEST_CODE_OFFSET;
}
/**
* Gets the appropriate icon needed for notifications.
*/