Skip to content

Commit

Permalink
Merge pull request #190 from kaczmarkiewiczp/upload-download-notifica…
Browse files Browse the repository at this point in the history
…tion

Show file being uploaded/downloaded in notification
  • Loading branch information
patrykcoding authored Aug 1, 2018
2 parents b52e861 + d415277 commit caa9e29
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public void onCreate() {

@Override
protected void onHandleIntent(@Nullable Intent intent) {
if (intent == null) {
return;
}

final FileItem downloadItem = intent.getParcelableExtra(DOWNLOAD_ITEM_ARG);
final String downloadPath = intent.getStringExtra(DOWNLOAD_PATH_ARG);
final RemoteItem remote = intent.getParcelableExtra(REMOTE_ARG);

Intent foregroundIntent = new Intent(this, DownloadService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);

Expand All @@ -59,20 +67,13 @@ protected void onHandleIntent(@Nullable Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.stat_sys_download)
.setContentTitle(getString(R.string.download_service_notification_title))
.setContentText(downloadItem.getName())
.setPriority(NotificationCompat.PRIORITY_LOW)
.setContentIntent(pendingIntent)
.addAction(R.drawable.ic_cancel_download, getString(R.string.cancel), cancelPendingIntent);

startForeground(PERSISTENT_NOTIFICATION_ID, builder.build());

if (intent == null) {
return;
}

final FileItem downloadItem = intent.getParcelableExtra(DOWNLOAD_ITEM_ARG);
final String downloadPath = intent.getStringExtra(DOWNLOAD_PATH_ARG);
final RemoteItem remote = intent.getParcelableExtra(REMOTE_ARG);

currentProcess = rclone.downloadFile(remote, downloadItem, downloadPath);

if (currentProcess != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ public void onCreate() {

@Override
protected void onHandleIntent(@Nullable Intent intent) {
if (intent == null) {
return;
}
final String uploadPath = intent.getStringExtra(UPLOAD_PATH_ARG);
final String uploadFilePath = intent.getStringExtra(LOCAL_PATH_ARG);
final RemoteItem remote = intent.getParcelableExtra(REMOTE_ARG);

String uploadFileName;
int slashIndex = uploadFilePath.lastIndexOf("/");
if (slashIndex >= 0) {
uploadFileName = uploadFilePath.substring(slashIndex + 1);
} else {
uploadFileName = uploadFilePath;
}

Intent foregroundIntent = new Intent(this, UploadService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);

Expand All @@ -59,20 +74,14 @@ protected void onHandleIntent(@Nullable Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.stat_sys_upload)
.setContentTitle(getString(R.string.upload_service_notification_title))
.setContentText(uploadFileName)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setContentIntent(pendingIntent)
.addAction(R.drawable.ic_cancel_download, getString(R.string.cancel), cancelPendingIntent);

startForeground(PERSISTENT_NOTIFICATION_ID, builder.build());

if (intent == null) {
return;
}
final String uploadPath = intent.getStringExtra(UPLOAD_PATH_ARG);
final String uploadFile = intent.getStringExtra(LOCAL_PATH_ARG);
final RemoteItem remote = intent.getParcelableExtra(REMOTE_ARG);

currentProcess = rclone.uploadFile(remote, uploadPath, uploadFile);
currentProcess = rclone.uploadFile(remote, uploadPath, uploadFilePath);

if (currentProcess != null) {
try {
Expand All @@ -87,7 +96,7 @@ protected void onHandleIntent(@Nullable Intent intent) {
}

boolean result = currentProcess != null && currentProcess.exitValue() == 0;
onUploadFinished(remote.getName(), uploadPath, uploadFile, result);
onUploadFinished(remote.getName(), uploadPath, uploadFilePath, result);

stopForeground(true);
}
Expand Down

0 comments on commit caa9e29

Please sign in to comment.