commit ae15ad7ce9ca0b4e587836fdd9f7b8d56398b17f
parent d901cba8288986674db0acaf0474b4a1ae0403ce
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Wed,  5 Jun 2024 14:24:34 +0200

feat(notifications): smart replies

Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 4++++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt | 1+
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/Notifications.kt | 15+++++++++++++--
3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -685,6 +685,10 @@ "name": "Reply Button", "description": "Adds a reply button to the notification" }, + "smart_replies": { + "name": "Smart Replies", + "description": "Adds suggested replies to notifications (Android 10+). Use in combination with Reply Button" + }, "download_button": { "name": "Download Button", "description": "Allows you to download media from the notification" diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt @@ -45,6 +45,7 @@ class MessagingTweaks : ConfigContainer() { val stackedMediaMessages = boolean("stacked_media_messages") val friendAddSource = boolean("friend_add_source") val replyButton = boolean("reply_button") { addNotices(FeatureNotice.UNSTABLE) } + val smartReplies = boolean("smart_replies") val downloadButton = boolean("download_button") val markAsReadButton = boolean("mark_as_read_button") { addNotices(FeatureNotice.UNSTABLE) } val markAsReadAndSaveInChat = boolean("mark_as_read_and_save_in_chat") { addNotices(FeatureNotice.UNSTABLE) } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/Notifications.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/Notifications.kt @@ -8,6 +8,7 @@ import android.content.Context import android.content.Intent import android.graphics.Bitmap import android.graphics.BitmapFactory +import android.os.Build import android.os.Bundle import android.os.UserHandle import de.robv.android.xposed.XposedBridge @@ -139,6 +140,9 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN .setLabel(translations["button.reply"]) .build() it.addRemoteInput(chatReplyInput) + if (config.smartReplies.get()) { + it.setAllowGeneratedReplies(true) + } } newAction(translations["button.download"], ACTION_DOWNLOAD, { @@ -298,7 +302,15 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN } } - notificationData.copy(id = notificationId).also { + val builder = newNotificationBuilder(notificationData.notification).apply { + setGroup(SNAPCHAT_NOTIFICATION_GROUP) + setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && config.smartReplies.get()) { + setAllowSystemGeneratedContextualActions(true) + } + } + + notificationData.copy(id = notificationId, notification = builder.build()).also { setupNotificationActionButtons(message.messageContent!!.contentType!!, conversationId, message, it) }.send() } @@ -354,7 +366,6 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN setLargeIcon(bitmapPreview) style = Notification.BigPictureStyle().bigPicture(bitmapPreview).bigLargeIcon(null as Bitmap?) } - if (config.mediaCaption.get()) { message.serialize()?.let { notificationBuilder.setContentText(it)