From 214deaa474855ec8ecfcaba0af4212c28106666a Mon Sep 17 00:00:00 2001 From: Philipp Neumann Date: Tue, 5 Oct 2021 12:54:22 +0200 Subject: [PATCH 1/3] added dynamic shortcut for priority conversations for Android 11+ --- newsfragment/3313.feature | 1 + .../notifications/NotificationDrawerManager.kt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 newsfragment/3313.feature diff --git a/newsfragment/3313.feature b/newsfragment/3313.feature new file mode 100644 index 0000000000..3d243fa1ef --- /dev/null +++ b/newsfragment/3313.feature @@ -0,0 +1 @@ +Priority conversations for Android 11+ 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 37de7b1a75..ac5f698750 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,11 +17,15 @@ 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 @@ -29,6 +33,7 @@ import im.vector.app.core.resources.StringProvider import im.vector.app.core.utils.FirstThrottler import im.vector.app.features.displayname.getBestName import im.vector.app.features.invite.AutoAcceptInvites +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 @@ -331,6 +336,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 From 95247f8b102fa8bada8d02ada9bbd4cf5f1edf9c Mon Sep 17 00:00:00 2001 From: Philipp Neumann Date: Tue, 5 Oct 2021 13:22:31 +0200 Subject: [PATCH 2/3] remove also LongLivedShortcuts --- .../java/im/vector/app/features/home/ShortcutsHandler.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt b/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt index c3249f5b26..2fbd90ace7 100644 --- a/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt +++ b/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt @@ -75,7 +75,11 @@ class ShortcutsHandler @Inject constructor( return } - ShortcutManagerCompat.removeAllDynamicShortcuts(context) + // according to https://developer.android.com/reference/androidx/core/content/pm/ShortcutManagerCompat#removeLongLivedShortcuts(android.content.Context,%20java.util.List%3Cjava.lang.String%3E) + // removeLongLivedShortcuts for API 29 and lower should behave like removeDynamicShortcuts(Context, List) + // getDynamicShortcuts: returns all dynamic shortcuts from the app. + val shortcuts = ShortcutManagerCompat.getDynamicShortcuts(context).map { it.id } + ShortcutManagerCompat.removeLongLivedShortcuts(context, shortcuts) // We can only disabled pinned shortcuts with the API, but at least it will prevent the crash if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) { From 2223e95f3371f1319c8e54d78381102040b4ef9b Mon Sep 17 00:00:00 2001 From: Philipp Neumann Date: Tue, 5 Oct 2021 14:59:21 +0200 Subject: [PATCH 3/3] fixed ordering and url linting error --- .../main/java/im/vector/app/features/home/ShortcutsHandler.kt | 2 +- .../app/features/notifications/NotificationDrawerManager.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt b/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt index 2fbd90ace7..7514d455aa 100644 --- a/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt +++ b/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt @@ -75,7 +75,7 @@ class ShortcutsHandler @Inject constructor( return } - // according to https://developer.android.com/reference/androidx/core/content/pm/ShortcutManagerCompat#removeLongLivedShortcuts(android.content.Context,%20java.util.List%3Cjava.lang.String%3E) + // according to Android documentation // removeLongLivedShortcuts for API 29 and lower should behave like removeDynamicShortcuts(Context, List) // getDynamicShortcuts: returns all dynamic shortcuts from the app. val shortcuts = ShortcutManagerCompat.getDynamicShortcuts(context).map { it.id } 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 ac5f698750..ecb1268892 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 @@ -32,8 +32,8 @@ import im.vector.app.R import im.vector.app.core.resources.StringProvider import im.vector.app.core.utils.FirstThrottler import im.vector.app.features.displayname.getBestName -import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.home.room.detail.RoomDetailActivity +import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.settings.VectorPreferences import me.gujun.android.span.span import org.matrix.android.sdk.api.session.Session