+ }
+
+ /**
+ * Create remote folder for instant uploads if necessary.
+ *
+ * @param client WebdavClient to the ownCloud server.
+ * @param storageManager Interface to the local database caching the data in the server.
+ * @return 'True' if the folder exists when the methods finishes.
+ */
+ private boolean createRemoteFolderForInstantUploads(WebdavClient client, FileDataStorageManager storageManager) {
+ boolean result = true;
+ OCFile instantUploadDir = storageManager.getFileByPath(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR);
+ if (instantUploadDir == null) {
+ result = client.createDirectory(InstantUploadBroadcastReceiver.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(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR);
+ newDir.setMimetype("DIR");
+ newDir.setParentId(storageManager.getFileByPath(OCFile.PATH_SEPARATOR).getFileId());
+ storageManager.saveFile(newDir);
+ }
+ return result;
+ }
+
+ /**
+ * Saves a new OC File after a successful upload.
+ *
+ * @param upload Upload operation completed.
+ * @param storageManager Interface to the database where the new OCFile has to be stored.
+ * @param parentDirId Id of the parent OCFile.
+ * @param size Size of the file.
+ */
+ private void saveNewOCFile(UploadFileOperation upload, FileDataStorageManager storageManager, long parentDirId, long size) {
+ OCFile newFile = new OCFile(upload.getRemotePath());
+ newFile.setMimetype(upload.getMimeType());
+ newFile.setFileLength(size);
+ newFile.setModificationTimestamp(System.currentTimeMillis());
+ newFile.setLastSyncDate(0);
+ newFile.setStoragePath(upload.getLocalPath());
+ newFile.setParentId(parentDirId);
+ if (upload.getForceOverwrite())
+ newFile.setKeepInSync(true);
+ storageManager.saveFile(newFile);
+ }
+
+ /**
+ * Creates a status notification to show the upload progress
+ *
+ * @param upload Upload operation starting.
+ */
+ private void notifyUploadStart(UploadFileOperation upload) {
+ /// create status notification with a progress bar
+ mLastPercent = 0;
+ mNotification = new Notification(R.drawable.icon, getString(R.string.uploader_upload_in_progress_ticker), System.currentTimeMillis());
+ mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
+ mDefaultNotificationContentView = mNotification.contentView;
+ mNotification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.progressbar_layout);
+ mNotification.contentView.setProgressBar(R.id.status_progress, 100, 0, false);
+ mNotification.contentView.setTextViewText(R.id.status_text, String.format(getString(R.string.uploader_upload_in_progress_content), 0, new File(upload.getLocalPath()).getName()));
+ mNotification.contentView.setImageViewResource(R.id.status_icon, R.drawable.icon);
+
+ /// includes a pending intent in the notification showing the details view of the file
+ /* TODO
+ 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(), 0, showDetailsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ */
+
+ mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotification);
+ }
+
+
+ /**
+ * Callback method to update the progress bar in the status notification
+ */
+ @Override
+ public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String fileName) {
+ int percent = (int)(100.0*((double)totalTransferredSoFar)/((double)totalToTransfer));
+ if (percent != mLastPercent) {
+ mNotification.contentView.setProgressBar(R.id.status_progress, 100, percent, false);
+ String text = String.format(getString(R.string.uploader_upload_in_progress_content), percent, fileName);
+ mNotification.contentView.setTextViewText(R.id.status_text, text);
+ mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotification);
+ }
+ mLastPercent = percent;
+ }
+
+
+ /**
+ * Callback method to update the progress bar in the status notification (old version)
+ */
+ @Override
+ public void onTransferProgress(long progressRate) {
+ // NOTHING TO DO HERE ANYMORE
+ }
+
+
+ /**
+ * 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