- /// create remote folder for instant uploads if necessary
- if (mIsInstant) {
- OCFile instantUploadDir = storageManager.getFileByPath(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR);
- if (instantUploadDir == null) {
- wc.createDirectory(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR); // fail could just mean that it already exists, but local database is not synchronized; the upload will be started anyway
- OCFile newDir = new OCFile(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR);
- newDir.setMimetype("DIR");
- newDir.setParentId(storageManager.getFileByPath(OCFile.PATH_SEPARATOR).getFileId());
- storageManager.saveFile(newDir);
- }
- }
-
- /// perform the upload
- File [] localFiles = new File[mLocalPaths.length];
- for (int i = 0; i < mLocalPaths.length; ++i) {
- localFiles[i] = new File(mLocalPaths[i]);
- mTotalDataToSend += localFiles[i].length();
- }
- Log.d(TAG, "Will upload " + mTotalDataToSend + " bytes, with " + mLocalPaths.length + " files");
- mSuccessCounter = 0;
- for (int i = 0; i < mLocalPaths.length; ++i) {
- String mimeType = (mMimeTypes != null) ? mMimeTypes[i] : null;
- if (mimeType == null) {
- try {
- mimeType = MimeTypeMap.getSingleton()
- .getMimeTypeFromExtension(
- mLocalPaths[i].substring(mLocalPaths[i]
- .lastIndexOf('.') + 1));
- } catch (IndexOutOfBoundsException e) {
- Log.e(TAG, "Trying to find out MIME type of a file without extension: " + mLocalPaths[i]);
- }
- }
- if (mimeType == null)
- mimeType = "application/octet-stream";
- mCurrentIndexUpload = i;
- long parentDirId = -1;
- boolean uploadResult = false;
- String availablePath = mRemotePaths[i];
- if (!force_override)
- availablePath = getAvailableRemotePath(wc, mRemotePaths[i]);
- try {
- File f = new File(mRemotePaths[i]);
- long size = localFiles[i].length();
- 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(size);
- new_file.setModificationTimestamp(System.currentTimeMillis());
- new_file.setLastSyncDate(0);
- new_file.setStoragePath(mLocalPaths[i]);
- new_file.setParentId(parentDirId);
- if (force_override)
- new_file.setKeepInSync(true);
- 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);
- }
-
- }
-
+
+ /**
+ * Notifies upload (or fail) of a file to activities interested
+ */
+ private void broadcastUploadEnd(UploadFileOperation upload, Account account, boolean success, long parentDirId) {
+ ///
+ Intent end = new Intent(UPLOAD_FINISH_MESSAGE);
+ end.putExtra(EXTRA_REMOTE_PATH, upload.getRemotePath());
+ end.putExtra(EXTRA_FILE_PATH, upload.getLocalPath());
+ end.putExtra(ACCOUNT_NAME, account.name);
+ end.putExtra(EXTRA_UPLOAD_RESULT, success);
+ end.putExtra(EXTRA_PARENT_DIR_ID, parentDirId);
+ sendBroadcast(end);
+ }
+
+
+ /**
+ * Updates the status notification with the results of a batch of uploads.
+ */
+ private void notifyUploadEndOverview() {