+
+
+ /**
+ * Updates the status notification with the result of an upload operation.
+ *
+ * @param uploadResult Result of the upload operation.
+ * @param upload Finished upload operation
+ */
+ private void notifyUploadResult(RemoteOperationResult uploadResult, UploadFileOperation upload) {
+ if (uploadResult.isCancelled()) {
+ /// cancelled operation -> silent removal of progress notification
+ mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
+
+ } else if (uploadResult.isSuccess()) {
+ /// success -> silent update of progress notification to success message
+ mNotification.flags ^= Notification.FLAG_ONGOING_EVENT; // remove the ongoing flag
+ mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
+ mNotification.contentView = mDefaultNotificationContentView;
+
+ /// includes a pending intent in the notification showing the details view of the file
+ Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
+ showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, upload.getFile());
+ showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, upload.getAccount());
+ showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), showDetailsIntent, 0);
+
+ mNotification.setLatestEventInfo( getApplicationContext(),
+ getString(R.string.uploader_upload_succeeded_ticker),
+ String.format(getString(R.string.uploader_upload_succeeded_content_single), (new File(upload.getStoragePath())).getName()),
+ mNotification.contentIntent);
+
+ mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotification); // NOT AN ERROR; uploader_upload_in_progress_ticker is the target, not a new notification
+
+ /* Notification about multiple uploads: pending of update
+ mNotification.setLatestEventInfo( getApplicationContext(),
+ getString(R.string.uploader_upload_succeeded_ticker),
+ String.format(getString(R.string.uploader_upload_succeeded_content_multiple), mSuccessCounter),
+ mNotification.contentIntent);
+ */
+
+ } else {
+ /// fail -> explicit failure notification
+ mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
+ Notification finalNotification = new Notification(R.drawable.icon, getString(R.string.uploader_upload_failed_ticker), System.currentTimeMillis());
+ finalNotification.flags |= Notification.FLAG_AUTO_CANCEL;
+ // TODO put something smart in the contentIntent below
+ finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
+ finalNotification.setLatestEventInfo( getApplicationContext(),
+ getString(R.string.uploader_upload_failed_ticker),
+ String.format(getString(R.string.uploader_upload_failed_content_single), (new File(upload.getStoragePath())).getName()),
+ finalNotification.contentIntent);
+
+ mNotificationManager.notify(R.string.uploader_upload_failed_ticker, finalNotification);
+
+ /* Notification about multiple uploads failure: pending of update
+ finalNotification.setLatestEventInfo( getApplicationContext(),
+ getString(R.string.uploader_upload_failed_ticker),
+ String.format(getString(R.string.uploader_upload_failed_content_multiple), mSuccessCounter, mTotalFilesToSend),
+ finalNotification.contentIntent);
+ } */
+ }
+
+ }
+
+
+ /**
+ * Sends a broadcast in order to the interested activities can update their view
+ *
+ * @param upload Finished upload operation
+ * @param uploadResult Result of the upload operation
+ */
+ private void sendFinalBroadcast(UploadFileOperation upload, RemoteOperationResult uploadResult) {
+ Intent end = new Intent(UPLOAD_FINISH_MESSAGE);
+ end.putExtra(EXTRA_REMOTE_PATH, upload.getRemotePath()); // real remote path, after possible automatic renaming
+ end.putExtra(EXTRA_FILE_PATH, upload.getStoragePath());
+ end.putExtra(ACCOUNT_NAME, upload.getAccount().name);
+ end.putExtra(EXTRA_UPLOAD_RESULT, uploadResult.isSuccess());
+ end.putExtra(EXTRA_PARENT_DIR_ID, upload.getFile().getParentId());
+ sendBroadcast(end);
+ }
+
+