diff options
author | Paul Keith <javelinanddart@gmail.com> | 2018-10-30 15:46:18 +0100 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2019-10-29 20:23:47 +0200 |
commit | 6c0d75d632472486303a78b28cc1021b2c00461c (patch) | |
tree | 9d80c4aaf44bcf62a688a86bd94730ab7a0ab1e9 /src | |
parent | a78341643041aa9fba68d311496fcf3156bd9285 (diff) | |
download | android_packages_apps_Messaging-6c0d75d632472486303a78b28cc1021b2c00461c.tar.gz android_packages_apps_Messaging-6c0d75d632472486303a78b28cc1021b2c00461c.tar.bz2 android_packages_apps_Messaging-6c0d75d632472486303a78b28cc1021b2c00461c.zip |
Messaging: Add "Mark as read" quick action for message notifications
Change-Id: I7194dca022e5062926fa35709de282721ca64320
Diffstat (limited to 'src')
6 files changed, 74 insertions, 4 deletions
diff --git a/src/com/android/messaging/datamodel/BugleNotifications.java b/src/com/android/messaging/datamodel/BugleNotifications.java index 6f8ba84..9358f14 100644 --- a/src/com/android/messaging/datamodel/BugleNotifications.java +++ b/src/com/android/messaging/datamodel/BugleNotifications.java @@ -842,7 +842,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 @@ -884,7 +885,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; @@ -921,9 +922,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)) { diff --git a/src/com/android/messaging/datamodel/MessageNotificationState.java b/src/com/android/messaging/datamodel/MessageNotificationState.java index ae50801..a7af329 100644 --- a/src/com/android/messaging/datamodel/MessageNotificationState.java +++ b/src/com/android/messaging/datamodel/MessageNotificationState.java @@ -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. */ diff --git a/src/com/android/messaging/datamodel/NotificationState.java b/src/com/android/messaging/datamodel/NotificationState.java index e19f70c..576a692 100644 --- a/src/com/android/messaging/datamodel/NotificationState.java +++ b/src/com/android/messaging/datamodel/NotificationState.java @@ -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. */ diff --git a/src/com/android/messaging/receiver/NotificationReceiver.java b/src/com/android/messaging/receiver/NotificationReceiver.java index bbb847d..f87779c 100644 --- a/src/com/android/messaging/receiver/NotificationReceiver.java +++ b/src/com/android/messaging/receiver/NotificationReceiver.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.Intent; import com.android.messaging.datamodel.BugleNotifications; +import com.android.messaging.datamodel.action.MarkAsReadAction; import com.android.messaging.datamodel.action.MarkAsSeenAction; import com.android.messaging.ui.UIIntents; import com.android.messaging.util.ConversationIdSet; @@ -52,6 +53,15 @@ public class NotificationReceiver extends BroadcastReceiver { BugleNotifications.resetLastMessageDing(conversationId); } } + } else if (intent.getAction().equals(UIIntents.ACTION_MARK_AS_READ)) { + final String conversationIdSetString = + intent.getStringExtra(UIIntents.UI_INTENT_EXTRA_CONVERSATION_ID_SET); + if (conversationIdSetString != null) { + for (final String conversationId : + ConversationIdSet.createSet(conversationIdSetString)) { + MarkAsReadAction.markAsRead(conversationId); + } + } } } -}
\ No newline at end of file +} diff --git a/src/com/android/messaging/ui/UIIntents.java b/src/com/android/messaging/ui/UIIntents.java index e5f8a52..3eabbdc 100644 --- a/src/com/android/messaging/ui/UIIntents.java +++ b/src/com/android/messaging/ui/UIIntents.java @@ -66,6 +66,9 @@ public abstract class UIIntents { public static final String ACTION_RESET_NOTIFICATIONS = "com.android.messaging.reset_notifications"; + public static final String ACTION_MARK_AS_READ = + "com.android.messaging.mark_as_read"; + // Sending VCard uri to VCard detail activity public static final String UI_INTENT_EXTRA_VCARD_URI = "vcard_uri"; @@ -323,6 +326,14 @@ public abstract class UIIntents { final int requestCode); /** + * Get a PendingIntent for marking a conversation as read. + * + * <p>This is intended to be used by notifications. + */ + public abstract PendingIntent getPendingIntentForMarkingAsRead(final Context context, + final ConversationIdSet conversationIdSet, final int requestCode); + + /** * Get a PendingIntent for showing low storage notifications. */ public abstract PendingIntent getPendingIntentForLowStorageNotifications(final Context context); diff --git a/src/com/android/messaging/ui/UIIntentsImpl.java b/src/com/android/messaging/ui/UIIntentsImpl.java index fb624ad..90eb376 100644 --- a/src/com/android/messaging/ui/UIIntentsImpl.java +++ b/src/com/android/messaging/ui/UIIntentsImpl.java @@ -418,6 +418,20 @@ public class UIIntentsImpl extends UIIntents { PendingIntent.FLAG_UPDATE_CURRENT); } + @Override + public PendingIntent getPendingIntentForMarkingAsRead(final Context context, + final ConversationIdSet conversationIdSet, final int requestCode) { + final Intent intent = new Intent(context, NotificationReceiver.class); + intent.setAction(ACTION_MARK_AS_READ); + if (conversationIdSet != null) { + intent.putExtra(UI_INTENT_EXTRA_CONVERSATION_ID_SET, + conversationIdSet.getDelimitedString()); + } + return PendingIntent.getBroadcast(context, + requestCode, intent, + PendingIntent.FLAG_UPDATE_CURRENT); + } + /** * Gets a PendingIntent associated with an Intent to start an Activity. All notifications * that starts an Activity must use this method to get a PendingIntent, which achieves two |