From dd7c264483bfd8ff4dba81343b167d267957826a Mon Sep 17 00:00:00 2001 From: Philipp Neumann Date: Wed, 28 Apr 2021 09:54:05 +0200 Subject: [PATCH 1/3] Added shortcut for conversation notifications --- vector/build.gradle | 2 +- .../NotificationDrawerManager.kt | 20 +++++++++++++++++++ .../notifications/NotificationUtils.kt | 8 ++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/vector/build.gradle b/vector/build.gradle index 69d2037255..5dcaf7dae1 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -325,7 +325,7 @@ dependencies { implementation "androidx.fragment:fragment-ktx:$fragment_version" implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation "androidx.sharetarget:sharetarget:1.1.0" - implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.core:core-ktx:1.5.0-rc01' implementation "androidx.media:media:1.3.0" implementation "org.threeten:threetenbp:1.4.0:no-tzdb" diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt index 7ac9b28b9a..54065597bc 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt @@ -17,16 +17,21 @@ package im.vector.app.features.notifications import android.content.Context import android.graphics.Bitmap +import android.os.Build import android.os.Handler import android.os.HandlerThread import androidx.annotation.WorkerThread import androidx.core.app.NotificationCompat import androidx.core.app.Person +import androidx.core.content.pm.ShortcutInfoCompat +import androidx.core.content.pm.ShortcutManagerCompat +import androidx.core.graphics.drawable.IconCompat import im.vector.app.ActiveSessionDataSource import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.resources.StringProvider import im.vector.app.core.utils.FirstThrottler +import im.vector.app.features.home.room.detail.RoomDetailActivity import im.vector.app.features.settings.VectorPreferences import me.gujun.android.span.span import org.matrix.android.sdk.api.session.Session @@ -319,6 +324,21 @@ class NotificationDrawerManager @Inject constructor(private val context: Context .setKey(event.senderId) .build() + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + val openRoomIntent = RoomDetailActivity.shortcutIntent(context, roomId) + + val shortcut = ShortcutInfoCompat.Builder(context, roomId) + .setLongLived(true) + .setIntent(openRoomIntent) + .setShortLabel(roomName) + .setIcon(largeBitmap?.let{IconCompat.createWithAdaptiveBitmap(it)}?: iconLoader.getUserIcon(event.senderAvatarPath)) + .setCategories() + .build() + + ShortcutManagerCompat.pushDynamicShortcut(context, shortcut) + } + if (event.outGoingMessage && event.outGoingMessageFailed) { style.addMessage(stringProvider.getString(R.string.notification_inline_reply_failed), event.timestamp, senderPerson) roomEventGroupInfo.hasSmartReplyError = true diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt index e7cafc6a9b..416d168928 100755 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt @@ -38,10 +38,8 @@ import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat -import androidx.core.app.RemoteInput import androidx.core.app.TaskStackBuilder import androidx.core.content.ContextCompat -import androidx.core.content.getSystemService import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.drawable.IconCompat import androidx.fragment.app.Fragment @@ -500,6 +498,8 @@ class NotificationUtils @Inject constructor(private val context: Context, // that can be displayed in not disturb mode if white listed (the later will need compat28.x) .setCategory(NotificationCompat.CATEGORY_MESSAGE) + .setShortcutId(roomInfo.roomId) + // Title for API < 16 devices. .setContentTitle(roomInfo.roomDisplayName) // Content for API < 16 devices. @@ -559,7 +559,7 @@ class NotificationUtils @Inject constructor(private val context: Context, NotificationCompat.Action.Builder(R.drawable.vector_notification_quick_reply, stringProvider.getString(R.string.action_quick_reply), replyPendingIntent) .addRemoteInput(remoteInput) - .build()?.let { + .build().let { addAction(it) } } @@ -863,7 +863,7 @@ class NotificationUtils @Inject constructor(private val context: Context, } // We cannot use NotificationManagerCompat here. - val setting = context.getSystemService()!!.currentInterruptionFilter + val setting = context.getSystemService(NotificationManager::class.java)!!.currentInterruptionFilter return setting == NotificationManager.INTERRUPTION_FILTER_NONE || setting == NotificationManager.INTERRUPTION_FILTER_ALARMS From f1ba8b96c95684bda35620f4fb004533442d6e85 Mon Sep 17 00:00:00 2001 From: Philipp Neumann Date: Sat, 8 May 2021 14:12:20 +0200 Subject: [PATCH 2/3] added import --- .../im/vector/app/features/notifications/NotificationUtils.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt index 416d168928..c5731e7aa2 100755 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt @@ -38,6 +38,7 @@ import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.core.app.RemoteInput import androidx.core.app.TaskStackBuilder import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat From 1db2d05ee4520fa14dd9e3d8f6f22cc428026d1f Mon Sep 17 00:00:00 2001 From: Philipp Neumann Date: Sat, 8 May 2021 14:53:54 +0200 Subject: [PATCH 3/3] linter corrections and added line to changes --- CHANGES.md | 2 +- .../app/features/notifications/NotificationDrawerManager.kt | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b447b6e6e5..57ffff7191 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Features ✨: - Improvements 🙌: - - + - Priority conversations for Android 11+ (#2734) Bugfix 🐛: - Message states cosmetic changes (#3007) diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt index 54065597bc..b68f0422dd 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt @@ -324,7 +324,6 @@ class NotificationDrawerManager @Inject constructor(private val context: Context .setKey(event.senderId) .build() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { val openRoomIntent = RoomDetailActivity.shortcutIntent(context, roomId) @@ -332,8 +331,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context .setLongLived(true) .setIntent(openRoomIntent) .setShortLabel(roomName) - .setIcon(largeBitmap?.let{IconCompat.createWithAdaptiveBitmap(it)}?: iconLoader.getUserIcon(event.senderAvatarPath)) - .setCategories() + .setIcon(largeBitmap?.let { IconCompat.createWithAdaptiveBitmap(it) } ?: iconLoader.getUserIcon(event.senderAvatarPath)) .build() ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)