|
@@ -34,6 +34,7 @@ import android.app.Notification;
|
|
import android.app.NotificationManager;
|
|
import android.app.NotificationManager;
|
|
import android.app.PendingIntent;
|
|
import android.app.PendingIntent;
|
|
import android.app.Service;
|
|
import android.app.Service;
|
|
|
|
+import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.BitmapFactory;
|
|
@@ -127,6 +128,10 @@ public class FileUploader extends Service
|
|
public static final String EXTRA_LINKED_TO_PATH = "LINKED_TO";
|
|
public static final String EXTRA_LINKED_TO_PATH = "LINKED_TO";
|
|
public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
|
|
public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
|
|
|
|
|
|
|
|
+ public static final String EXTRA_ACCOUNT_NAME = "ACCOUNT_NAME";
|
|
|
|
+ public static final String ACTION_CANCEL_BROADCAST = "CANCEL";
|
|
|
|
+ public static final String ACTION_PAUSE_BROADCAST = "PAUSE";
|
|
|
|
+
|
|
private static final int FOREGROUND_SERVICE_ID = 411;
|
|
private static final int FOREGROUND_SERVICE_ID = 411;
|
|
|
|
|
|
public static final String KEY_FILE = "FILE";
|
|
public static final String KEY_FILE = "FILE";
|
|
@@ -197,7 +202,7 @@ public class FileUploader extends Service
|
|
private Notification mNotification;
|
|
private Notification mNotification;
|
|
private Looper mServiceLooper;
|
|
private Looper mServiceLooper;
|
|
private ServiceHandler mServiceHandler;
|
|
private ServiceHandler mServiceHandler;
|
|
- private IBinder mBinder;
|
|
|
|
|
|
+ private static IBinder mBinder;
|
|
private OwnCloudClient mUploadClient;
|
|
private OwnCloudClient mUploadClient;
|
|
private Account mCurrentAccount;
|
|
private Account mCurrentAccount;
|
|
private FileDataStorageManager mStorageManager;
|
|
private FileDataStorageManager mStorageManager;
|
|
@@ -703,6 +708,12 @@ public class FileUploader extends Service
|
|
*/
|
|
*/
|
|
private void notifyUploadStart(UploadFileOperation upload) {
|
|
private void notifyUploadStart(UploadFileOperation upload) {
|
|
// / create status notification with a progress bar
|
|
// / create status notification with a progress bar
|
|
|
|
+ Intent notificationActionIntent = new Intent(getApplicationContext(),UploadNotificationActionReceiver.class);
|
|
|
|
+ notificationActionIntent.putExtra(EXTRA_ACCOUNT_NAME,upload.getUser().getAccountName());
|
|
|
|
+ notificationActionIntent.putExtra(EXTRA_REMOTE_PATH,upload.getRemotePath());
|
|
|
|
+ notificationActionIntent.setAction(ACTION_CANCEL_BROADCAST);
|
|
|
|
+
|
|
|
|
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),new SecureRandom().nextInt(),notificationActionIntent, PendingIntent.FLAG_MUTABLE);
|
|
mLastPercent = 0;
|
|
mLastPercent = 0;
|
|
mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils);
|
|
mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils);
|
|
mNotificationBuilder
|
|
mNotificationBuilder
|
|
@@ -713,7 +724,10 @@ public class FileUploader extends Service
|
|
.setProgress(100, 0, false)
|
|
.setProgress(100, 0, false)
|
|
.setContentText(
|
|
.setContentText(
|
|
String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName())
|
|
String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName())
|
|
- );
|
|
|
|
|
|
+ )
|
|
|
|
+ .clearActions() // to make sure there is only one action
|
|
|
|
+ .addAction(R.drawable.ic_action_cancel_grey,getApplicationContext().getString(R.string.common_cancel),pendingIntent);
|
|
|
|
+
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
mNotificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD);
|
|
mNotificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD);
|
|
@@ -806,7 +820,8 @@ public class FileUploader extends Service
|
|
.setContentTitle(getString(tickerId))
|
|
.setContentTitle(getString(tickerId))
|
|
.setAutoCancel(true)
|
|
.setAutoCancel(true)
|
|
.setOngoing(false)
|
|
.setOngoing(false)
|
|
- .setProgress(0, 0, false);
|
|
|
|
|
|
+ .setProgress(0, 0, false)
|
|
|
|
+ .clearActions();
|
|
|
|
|
|
content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, upload, getResources());
|
|
content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, upload, getResources());
|
|
|
|
|
|
@@ -1403,4 +1418,32 @@ public class FileUploader extends Service
|
|
mService.stopSelf(msg.arg1);
|
|
mService.stopSelf(msg.arg1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * When cancel action in upload notification is pressed, cancel upload of item
|
|
|
|
+ */
|
|
|
|
+ public static class UploadNotificationActionReceiver extends BroadcastReceiver {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
|
+
|
|
|
|
+ String accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME);
|
|
|
|
+ String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);
|
|
|
|
+ String action = intent.getAction();
|
|
|
|
+
|
|
|
|
+ if (ACTION_CANCEL_BROADCAST.equals(action)) {
|
|
|
|
+ Log_OC.d(TAG, "Cancel broadcast received for file " + remotePath + " at " + System.currentTimeMillis());
|
|
|
|
+
|
|
|
|
+ if (accountName == null || remotePath == null) return;
|
|
|
|
+
|
|
|
|
+ FileUploaderBinder uploadBinder = (FileUploaderBinder) mBinder;
|
|
|
|
+ uploadBinder.cancel(accountName, remotePath, null);
|
|
|
|
+ }else if(ACTION_PAUSE_BROADCAST.equals(action)){
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|