diff --git a/CHANGELOG.md b/CHANGELOG.md index f0b15d396..0b14aaef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Show smaller Imgur images when data saving mode enabled ([#256](https://github.com/Tunous/Dawn/pull/256)) - Don't show too small reddit previews ([#264](https://github.com/Tunous/Dawn/pull/264)) - Fix sharing an image multiple times ([#280](https://github.com/Tunous/Dawn/pull/280)) +- Allow grouping of media download notifications ([#285](https://github.com/Tunous/Dawn/pull/285)) +- Workaround invisible download notifications on Android 11 ([#282](https://github.com/Tunous/Dawn/issues/282)) ## [0.9.2] - 2020-06-13 diff --git a/app/src/main/java/me/saket/dank/notifs/MediaDownloadService.java b/app/src/main/java/me/saket/dank/notifs/MediaDownloadService.java index 782d13c4f..f32e6d776 100644 --- a/app/src/main/java/me/saket/dank/notifs/MediaDownloadService.java +++ b/app/src/main/java/me/saket/dank/notifs/MediaDownloadService.java @@ -10,6 +10,7 @@ import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; +import android.media.MediaMetadata; import android.media.session.MediaSession; import android.net.Uri; import android.os.Build; @@ -353,6 +354,22 @@ private void displayErrorNotification(MediaDownloadJob failedDownloadJob, int no NotificationManagerCompat.from(this).notify(notificationId, errorNotification); } + private void displaySummaryNotification(NotificationManagerCompat nm, String channel) { + // No point in grouping download notifications on < Nougat since summary notification won't be exapndable + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Notification summaryNotification = new NotificationCompat.Builder(MediaDownloadService.this, channel) + .setSmallIcon(R.drawable.ic_done_24dp) + .setGroup(NotificationConstants.MEDIA_DOWNLOAD_SUCCESS_GROUP) + .setGroupSummary(true) + .setShowWhen(true) + .setDefaults(Notification.DEFAULT_ALL) + .setOnlyAlertOnce(true) + .setAutoCancel(true) + .build(); + nm.notify(NotificationConstants.ID_MEDIA_DOWNLOAD_SUCCESS_BUNDLE_SUMMARY, summaryNotification); + } + } + /** * Generate a notification with a preview of the media. Images and videos both work, thanks to Glide. */ @@ -407,7 +424,7 @@ public void onResourceReady(Bitmap imageBitmap, Transition trans .setSmallIcon(R.drawable.ic_done_24dp) .setOngoing(false) .setLocalOnly(true) - .setGroup(NotificationConstants.MEDIA_DOWNLOAD_GROUP) + .setGroup(NotificationConstants.MEDIA_DOWNLOAD_SUCCESS_GROUP) .setWhen(completedDownloadJob.timestamp()) .setContentIntent(viewImagePendingIntent) .addAction(shareImageAction) @@ -418,9 +435,13 @@ public void onResourceReady(Bitmap imageBitmap, Transition trans // Taking advantage of O's tinted media notifications! I feel bad for this. // Let's see if anyone from Google asks me to remove this. - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + // --- + // Android 11 finally broke this so we'll force it to use BigPicture style for now + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT < 30) { MediaSession poop = new MediaSession(getBaseContext(), "me.saket.Dank.dummyMediaSession"); MediaSessionCompat.Token dummyTokenCompat = MediaSessionCompat.Token.fromToken(poop.getSessionToken()); + MediaMetadata meta = new MediaMetadata.Builder().putLong(MediaMetadata.METADATA_KEY_DURATION, -1).build(); + poop.setMetadata(meta); poop.release(); notificationBuilder = notificationBuilder @@ -443,7 +464,9 @@ public void onResourceReady(Bitmap imageBitmap, Transition trans } Notification successNotification = notificationBuilder.build(); - NotificationManagerCompat.from(MediaDownloadService.this).notify(notificationId, successNotification); + NotificationManagerCompat nm = NotificationManagerCompat.from(MediaDownloadService.this); + displaySummaryNotification(nm, notificationChannelId); + nm.notify(notificationId, successNotification); } }); } diff --git a/app/src/main/java/me/saket/dank/notifs/NotificationConstants.java b/app/src/main/java/me/saket/dank/notifs/NotificationConstants.java index 4ff1f9c31..d772bd1f5 100644 --- a/app/src/main/java/me/saket/dank/notifs/NotificationConstants.java +++ b/app/src/main/java/me/saket/dank/notifs/NotificationConstants.java @@ -5,9 +5,11 @@ */ public class NotificationConstants { public static final int ID_UNREAD_MESSAGES_BUNDLE_SUMMARY = 100; + public static final int ID_MEDIA_DOWNLOAD_SUCCESS_BUNDLE_SUMMARY = 101; public static final String UNREAD_MESSAGE_BUNDLE_NOTIFS_GROUP_KEY = "unreadMessagesBundle"; public static final String UNREAD_MESSAGE_PREFIX_ = "unreadMessage_"; public static final String ID_MEDIA_DOWNLOAD_PROGRESS_PREFIX_ = "mediaDownloadProgress_"; public static final String MEDIA_DOWNLOAD_GROUP = "mediaDownloadNotifs"; + public static final String MEDIA_DOWNLOAD_SUCCESS_GROUP = "mediaDownloadSuccessNotifs"; }