aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2022-05-31 08:18:16 +0000
committerDocile-Alligator <chineseperson5@gmail.com>2022-05-31 08:18:16 +0000
commit7f91f895992383d1f1fb89124bd6f706cc6b24a3 (patch)
tree40f079251e2095bbeece0708f4d96b2174f74eec /app/src
parent3218ff10f1b27942615fa1dd0d0ea5347a5ea64e (diff)
downloadinfinity-for-reddit-7f91f895992383d1f1fb89124bd6f706cc6b24a3.tar
infinity-for-reddit-7f91f895992383d1f1fb89124bd6f706cc6b24a3.tar.gz
infinity-for-reddit-7f91f895992383d1f1fb89124bd6f706cc6b24a3.tar.bz2
infinity-for-reddit-7f91f895992383d1f1fb89124bd6f706cc6b24a3.tar.lz
infinity-for-reddit-7f91f895992383d1f1fb89124bd6f706cc6b24a3.tar.xz
infinity-for-reddit-7f91f895992383d1f1fb89124bd6f706cc6b24a3.tar.zst
infinity-for-reddit-7f91f895992383d1f1fb89124bd6f706cc6b24a3.zip
Share media file after downloading.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java34
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java30
2 files changed, 42 insertions, 22 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java
index a7059db9..770433d0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java
@@ -115,7 +115,7 @@ public class DownloadMediaService extends Service {
if (currentTime - time > 1000) {
time = currentTime;
updateNotification(mediaType, 0,
- (int) ((100 * bytesRead) / contentLength), randomNotificationIdOffset, null);
+ (int) ((100 * bytesRead) / contentLength), randomNotificationIdOffset, null, null);
}
}
}
@@ -316,15 +316,15 @@ public class DownloadMediaService extends Service {
switch (errorCode) {
case ERROR_CANNOT_GET_DESTINATION_DIRECTORY:
updateNotification(mediaType, R.string.downloading_image_or_gif_failed_cannot_get_destination_directory,
- -1, randomNotificationIdOffset, null);
+ -1, randomNotificationIdOffset, null, null);
break;
case ERROR_FILE_CANNOT_DOWNLOAD:
updateNotification(mediaType, R.string.downloading_media_failed_cannot_download_media,
- -1, randomNotificationIdOffset, null);
+ -1, randomNotificationIdOffset, null, null);
break;
case ERROR_FILE_CANNOT_SAVE:
updateNotification(mediaType, R.string.downloading_media_failed_cannot_save_to_destination_directory,
- -1, randomNotificationIdOffset, null);
+ -1, randomNotificationIdOffset, null, null);
break;
}
EventBus.getDefault().post(new DownloadMediaEvent(false));
@@ -332,13 +332,8 @@ public class DownloadMediaService extends Service {
MediaScannerConnection.scanFile(
DownloadMediaService.this, new String[]{destinationFileUri.toString()}, null,
(path, uri) -> {
- Intent intent = new Intent();
- intent.setAction(android.content.Intent.ACTION_VIEW);
- intent.setDataAndType(destinationFileUri, mimeType);
- intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- PendingIntent pendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(DownloadMediaService.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(DownloadMediaService.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
updateNotification(mediaType, R.string.downloading_media_finished, -1,
- randomNotificationIdOffset, pendingIntent);
+ randomNotificationIdOffset, destinationFileUri, mimeType);
EventBus.getDefault().post(new DownloadMediaEvent(true));
}
);
@@ -414,7 +409,7 @@ public class DownloadMediaService extends Service {
}
private void updateNotification(int mediaType, int contentStringResId, int progress, int randomNotificationIdOffset,
- PendingIntent pendingIntent) {
+ Uri mediaUri, String mimeType) {
if (notificationManager != null) {
if (progress < 0) {
builder.setProgress(0, 0, false);
@@ -424,8 +419,23 @@ public class DownloadMediaService extends Service {
if (contentStringResId != 0) {
builder.setContentText(getString(contentStringResId));
}
- if (pendingIntent != null) {
+ if (mediaUri != null) {
+ Intent intent = new Intent();
+ intent.setAction(android.content.Intent.ACTION_VIEW);
+ intent.setDataAndType(mediaUri, mimeType);
+ intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ PendingIntent pendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(DownloadMediaService.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(DownloadMediaService.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
builder.setContentIntent(pendingIntent);
+
+ Intent shareIntent = new Intent();
+ shareIntent.setAction(Intent.ACTION_SEND);
+ shareIntent.putExtra(Intent.EXTRA_STREAM, mediaUri);
+ shareIntent.setType(mimeType);
+ shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ Intent intentAction = Intent.createChooser(shareIntent, getString(R.string.share));
+ PendingIntent shareActionPendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(this, 1, intentAction, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(this, 1, intentAction, PendingIntent.FLAG_CANCEL_CURRENT);
+
+ builder.addAction(new NotificationCompat.Action(R.drawable.ic_notification, getString(R.string.share), shareActionPendingIntent));
}
notificationManager.notify(getNotificationId(mediaType, randomNotificationIdOffset), builder.build());
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
index 73f885b7..65949d19 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
@@ -202,7 +202,7 @@ public class DownloadRedditVideoService extends Service {
checkForDuplicates = dir.findFile(fileNameWithoutExtension + ".mp4");
num++;
}
- picFile = dir.createFile("video/*", fileNameWithoutExtension + ".mp4");
+ picFile = dir.createFile("video/mp4", fileNameWithoutExtension + ".mp4");
if (picFile == null) {
downloadFinished(null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
return;
@@ -414,7 +414,7 @@ public class DownloadRedditVideoService extends Service {
} else {
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, destinationFileName);
- contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "video/*");
+ contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "video/mp4");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, destinationFileUriString);
contentValues.put(MediaStore.Video.Media.IS_PENDING, 1);
@@ -567,12 +567,7 @@ public class DownloadRedditVideoService extends Service {
MediaScannerConnection.scanFile(
this, new String[]{destinationFileUri.toString()}, null,
(path, uri) -> {
- Intent intent = new Intent();
- intent.setAction(android.content.Intent.ACTION_VIEW);
- intent.setDataAndType(destinationFileUri, "video/*");
- intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- PendingIntent pendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
- updateNotification(R.string.downloading_reddit_video_finished, -1, randomNotificationIdOffset, pendingIntent);
+ updateNotification(R.string.downloading_reddit_video_finished, -1, randomNotificationIdOffset, destinationFileUri);
EventBus.getDefault().post(new DownloadRedditVideoEvent(true));
}
);
@@ -587,7 +582,7 @@ public class DownloadRedditVideoService extends Service {
.build();
}
- private void updateNotification(int contentStringResId, int progress, int randomNotificationIdOffset, PendingIntent pendingIntent) {
+ private void updateNotification(int contentStringResId, int progress, int randomNotificationIdOffset, Uri mediaUri) {
if (notificationManager != null) {
if (progress < 0) {
builder.setProgress(0, 0, false);
@@ -597,8 +592,23 @@ public class DownloadRedditVideoService extends Service {
if (contentStringResId != 0) {
builder.setContentText(getString(contentStringResId));
}
- if (pendingIntent != null) {
+ if (mediaUri != null) {
+ Intent intent = new Intent();
+ intent.setAction(android.content.Intent.ACTION_VIEW);
+ intent.setDataAndType(mediaUri, "video/mp4");
+ intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ PendingIntent pendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
+
builder.setContentIntent(pendingIntent);
+
+ Intent shareIntent = new Intent();
+ shareIntent.setAction(Intent.ACTION_SEND);
+ shareIntent.putExtra(Intent.EXTRA_STREAM, mediaUri);
+ shareIntent.setType("video/mp4");
+ shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ Intent intentAction = Intent.createChooser(shareIntent, getString(R.string.share));
+ PendingIntent shareActionPendingIntent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.getActivity(this, 1, intentAction, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE) : PendingIntent.getActivity(this, 1, intentAction, PendingIntent.FLAG_CANCEL_CURRENT);
+ builder.addAction(new NotificationCompat.Action(R.drawable.ic_notification, getString(R.string.share), shareActionPendingIntent));
}
notificationManager.notify(NotificationUtils.DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID + randomNotificationIdOffset, builder.build());
}