Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Group download notifications + remove seekbar (#285)
Browse files Browse the repository at this point in the history
* remove seekbar

* group download notifications

* put success notifications in a separate group

* changelog

* workaround for Android 11

Co-authored-by: Łukasz Rutkowski <lukus178@gmail.com>
  • Loading branch information
AbsurdlySuspicious and Tunous authored Jul 26, 2020
1 parent fd9bd49 commit 3cf87bc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 26 additions & 3 deletions app/src/main/java/me/saket/dank/notifs/MediaDownloadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -407,7 +424,7 @@ public void onResourceReady(Bitmap imageBitmap, Transition<? super Bitmap> 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)
Expand All @@ -418,9 +435,13 @@ public void onResourceReady(Bitmap imageBitmap, Transition<? super Bitmap> 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
Expand All @@ -443,7 +464,9 @@ public void onResourceReady(Bitmap imageBitmap, Transition<? super Bitmap> 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);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

0 comments on commit 3cf87bc

Please sign in to comment.