+ if (mimeType == null)
+ mimeType = "application/octet-stream";
+ mCurrentIndexUpload = i;
+ long parentDirId = -1;
+ boolean uploadResult = false;
+ String availablePath = getAvailableRemotePath(wc, mRemotePaths[i]);
+ try {
+ File f = new File(mRemotePaths[i]);
+ parentDirId = storageManager.getFileByPath(f.getParent().endsWith("/")?f.getParent():f.getParent()+"/").getFileId();
+ if(availablePath != null) {
+ mRemotePaths[i] = availablePath;
+ mUploadsInProgress.put(buildRemoteName(mAccount.name, mRemotePaths[i]), mLocalPaths[i]);
+ if (wc.putFile(mLocalPaths[i], mRemotePaths[i], mimeType)) {
+ OCFile new_file = new OCFile(mRemotePaths[i]);
+ new_file.setMimetype(mimeType);
+ new_file.setFileLength(localFiles[i].length());
+ new_file.setModificationTimestamp(System.currentTimeMillis());
+ new_file.setLastSyncDate(0);
+ new_file.setStoragePath(mLocalPaths[i]);
+ new_file.setParentId(parentDirId);
+ storageManager.saveFile(new_file);
+ mSuccessCounter++;
+ uploadResult = true;
+ }
+ }
+ } finally {
+ mUploadsInProgress.remove(buildRemoteName(mAccount.name, mRemotePaths[i]));
+
+ /// notify upload (or fail) of EACH file to activities interested
+ Intent end = new Intent(UPLOAD_FINISH_MESSAGE);
+ end.putExtra(EXTRA_PARENT_DIR_ID, parentDirId);
+ end.putExtra(EXTRA_UPLOAD_RESULT, uploadResult);
+ end.putExtra(EXTRA_REMOTE_PATH, mRemotePaths[i]);
+ end.putExtra(EXTRA_FILE_PATH, mLocalPaths[i]);
+ end.putExtra(ACCOUNT_NAME, mAccount.name);
+ sendBroadcast(end);
+ }
+
+ }
+
+ /// notify final result
+ if (mSuccessCounter == mLocalPaths.length) { // success
+ //Notification finalNotification = new Notification(R.drawable.icon, getString(R.string.uploader_upload_succeeded_ticker), System.currentTimeMillis());
+ mNotification.flags ^= Notification.FLAG_ONGOING_EVENT; // remove the ongoing flag
+ mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
+ mNotification.contentView = oldContentView;
+ // TODO put something smart in the contentIntent below
+ mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
+ if (mLocalPaths.length == 1) {
+ mNotification.setLatestEventInfo( getApplicationContext(),
+ getString(R.string.uploader_upload_succeeded_ticker),
+ String.format(getString(R.string.uploader_upload_succeeded_content_single), localFiles[0].getName()),
+ mNotification.contentIntent);
+ } else {
+ mNotification.setLatestEventInfo( getApplicationContext(),
+ getString(R.string.uploader_upload_succeeded_ticker),
+ String.format(getString(R.string.uploader_upload_succeeded_content_multiple), mSuccessCounter),
+ 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
+
+ } else {
+ 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(), 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
+ if (mLocalPaths.length == 1) {
+ finalNotification.setLatestEventInfo( getApplicationContext(),
+ getString(R.string.uploader_upload_failed_ticker),
+ String.format(getString(R.string.uploader_upload_failed_content_single), localFiles[0].getName()),
+ finalNotification.contentIntent);
+ } else {
+ finalNotification.setLatestEventInfo( getApplicationContext(),
+ getString(R.string.uploader_upload_failed_ticker),
+ String.format(getString(R.string.uploader_upload_failed_content_multiple), mSuccessCounter, mLocalPaths.length),
+ finalNotification.contentIntent);
+ }
+ mNotificationManager.notify(R.string.uploader_upload_failed_ticker, finalNotification);
+ }
+
+ }