Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ 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))
- Fix downloaded media not appearing in gallery ([#288](https://github.com/Tunous/Dawn/pull/288))

## [0.9.2] - 2020-06-13

Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ dependencies {
kapt "com.github.bumptech.glide:compiler:$versions.glide"
implementation "com.github.bumptech.glide:okhttp3-integration:$versions.glide"
implementation 'com.squareup.sqlbrite2:sqlbrite:2.0.0'
implementation 'androidx.room:room-runtime:2.2.3'
kapt 'androidx.room:room-compiler:2.2.3'
implementation 'androidx.room:room-rxjava2:2.2.5'
implementation "androidx.room:room-runtime:$versions.room"
kapt "androidx.room:room-compiler:$versions.room"
implementation "androidx.room:room-rxjava2:$versions.room"
implementation 'com.google.android:flexbox:2.0.1'
implementation 'com.github.zagum:Android-ExpandIcon:1.1.1'
implementation 'me.saket:better-link-movement-method:2.2.0'
Expand Down
61 changes: 54 additions & 7 deletions app/src/main/java/me/saket/dank/notifs/MediaDownloadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.media.MediaMetadata;
import android.media.MediaScannerConnection;
import android.media.session.MediaSession;
import android.net.Uri;
import android.os.Build;
Expand Down Expand Up @@ -353,6 +356,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 +426,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 +437,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 +466,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 Expand Up @@ -593,12 +618,34 @@ private Function<MediaDownloadJob, MediaDownloadJob> moveFileToUserSpaceOnDownlo
String mediaFileName = Urls.parseFileNameWithExtension(downloadedMediaLink.highQualityUrl());
//noinspection LambdaParameterTypeCanBeSpecified,ConstantConditions
File userAccessibleFile = Files2.INSTANCE.copyFileToPicturesDirectory(getResources(), downloadJobUpdate.downloadedFile(), mediaFileName);
String userFilePath = userAccessibleFile.getAbsolutePath();

ContentResolver resolver = getContentResolver();

Uri contentUri = downloadedMediaLink.isVideo() ?
MediaStore.Video.Media.EXTERNAL_CONTENT_URI :
MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

//broadcast file
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, mediaFileName);
values.put(MediaStore.Images.Media.DISPLAY_NAME, mediaFileName);
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);
values.put(MediaStore.MediaColumns.DATE_MODIFIED, System.currentTimeMillis() / 1000);

// try to update mtime on already indexed file
int updatedCount = resolver.update(contentUri, values,
MediaStore.MediaColumns.DATA + "=?",
new String[]{ userFilePath });

if (updatedCount <= 0) {
// broadcast new file
values.put(MediaStore.MediaColumns.DATA, userFilePath);
values.put(MediaStore.MediaColumns.TITLE, mediaFileName);
values.put(MediaStore.MediaColumns.DISPLAY_NAME, mediaFileName);
resolver.insert(contentUri, values);
}

MediaScannerConnection.scanFile(
MediaDownloadService.this,
new String[]{ userFilePath },
null, null);

return MediaDownloadJob.downloaded(downloadedMediaLink, userAccessibleFile, downloadJobUpdate.timestamp());

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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.Instant;
import org.threeten.bp.ZonedDateTime;

import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -91,7 +92,7 @@ public void onSaveDraft_shouldSaveDraft_shouldCallRecycleDrafts() throws Excepti
@Test
public void onRecycleOldDrafts_shouldCorrectlyRecycleStaleDrafts() {
Map<String, ReplyDraft> savedDrafts = new HashMap<>();
LocalDateTime twoWeeksOldDate = LocalDateTime.now(UTC).minusDays(RECYCLE_DRAFTS_IN_DAYS + 1);
ZonedDateTime twoWeeksOldDate = Instant.ofEpochMilli(System.currentTimeMillis()).atZone(UTC).minusDays(RECYCLE_DRAFTS_IN_DAYS + 1);
long twoWeeksOldTimeMillis = twoWeeksOldDate.getNano() / 1000000;
savedDrafts.put("oldKey", ReplyDraft.create("oldDraft", twoWeeksOldTimeMillis));
savedDrafts.put("newKey", ReplyDraft.create("newDraft", System.currentTimeMillis()));
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ buildscript {
deeplinkDispatch: '4.1.0',
androidTest : '1.0.2',
kotlin : '1.3.61',
room : '1.1.0',
room : '2.2.5',
jsoup : '1.13.1',
rxjava : '2.2.19',
]
Expand Down