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

Group download notifications + remove seekbar #285

Merged
merged 6 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use named version code here instead of 30? Perhaps with <= if latest is not available.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDK 28 is used so latest version listed there is api 28 / Android 9. I think the only way to get new consts is to unlink compileSdk and targetSdk in gradle scripts and switch to compile 30 + target 28. This way it shouldn't break anything, though sdk update is entirely different matter anyway

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see, lets leave this as is then.

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";
}