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