diff --git a/vector/build.gradle b/vector/build.gradle index d48d3bd61d..f119765cc3 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -336,7 +336,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.1" 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..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 @@ -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,19 @@ 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)) + .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 1b72793f89..1ccdbd26e4 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 @@ -41,7 +41,6 @@ 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 +499,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. @@ -865,7 +866,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