mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 06:25:14 +01:00
Notification shortcut update
Remove notification shortcuts after notification is sent as per 3rd item under https://github.com/android/user-interface-samples/tree/master/People#shortcuts, to allow shortcuts to be cached. Q: Will my shortcuts appear in the long press app launcher context menu? A: They can depending on their rank, but if you prefer not having shortcuts appear on launcher you can remove the shortcut with ShortcutManager#removeDynamicShortcuts() or #removeAllDynamicShortcuts() after sending the notification. You can also rank other app shortcuts with higher ranking, so only those dynamic shortcuts appear on launcher. Thanks for all your great work on this. I will push for making the API better for this. Thanks again and note that this pull request can be a throwaway and I just wanted to show at what point the shortcuts can be removed. I checked out the codebase, made these changes and was able to get this working on a flashed Android 11 device. Thanks again.
This commit is contained in:
parent
320710366d
commit
b8f17ead8f
1 changed files with 12 additions and 5 deletions
|
@ -2373,10 +2373,14 @@ public class NotificationsController extends BaseController {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean unsupportedNotificationShortcut() {
|
||||
return Build.VERSION.SDK_INT < 29 || !SharedConfig.chatBubbles;
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
private void createNotificationShortcut(NotificationCompat.Builder builder, int did, String name, TLRPC.User user, TLRPC.Chat chat, Person person) {
|
||||
if (Build.VERSION.SDK_INT < 29 || ChatObject.isChannel(chat) && !chat.megagroup || !SharedConfig.chatBubbles) {
|
||||
if (unsupportedNotificationShortcut() || ChatObject.isChannel(chat) && !chat.megagroup) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -2397,10 +2401,7 @@ public class NotificationsController extends BaseController {
|
|||
}
|
||||
ArrayList<ShortcutInfoCompat> arrayList = new ArrayList<>(1);
|
||||
arrayList.add(shortcutBuilder.build());
|
||||
ArrayList<String> ids = new ArrayList<>(1);
|
||||
ids.add(id);
|
||||
ShortcutManagerCompat.addDynamicShortcuts(ApplicationLoader.applicationContext, arrayList);
|
||||
ShortcutManagerCompat.removeDynamicShortcuts(ApplicationLoader.applicationContext, ids);
|
||||
builder.setShortcutId(id);
|
||||
NotificationCompat.BubbleMetadata.Builder bubbleBuilder = new NotificationCompat.BubbleMetadata.Builder();
|
||||
Intent intent = new Intent(ApplicationLoader.applicationContext, BubbleActivity.class);
|
||||
|
@ -3737,8 +3738,14 @@ public class NotificationsController extends BaseController {
|
|||
notificationManager.cancel(notificationId);
|
||||
}
|
||||
}
|
||||
ArrayList<String> ids = new ArrayList<>(holders.size());
|
||||
for (int a = 0, size = holders.size(); a < size; a++) {
|
||||
holders.get(a).call();
|
||||
NotificationHolder holder = holders.get(a);
|
||||
holder.call();
|
||||
ids.add(holder.notification.getShortcutId());
|
||||
}
|
||||
if (!unsupportedNotificationShortcut()) {
|
||||
ShortcutManagerCompat.removeDynamicShortcuts(ApplicationLoader.applicationContext, ids);
|
||||
}
|
||||
|
||||
for (int a = 0; a < oldIdsWear.size(); a++) {
|
||||
|
|
Loading…
Reference in a new issue