+ /**
+ * Request the synchronization of a file or folder with the OC server, including its contents.
+ *
+ * @param file The file or folder to synchronize
+ */
+ public void syncFile(OCFile file) {
+ if (!file.isFolder()){
+ Intent intent = new Intent(mFileActivity, OperationsService.class);
+ intent.setAction(OperationsService.ACTION_SYNC_FILE);
+ intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ intent.putExtra(OperationsService.EXTRA_SYNC_FILE_CONTENTS, true);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(intent);
+ mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
+ getString(R.string.wait_a_moment));
+
+ } else {
+ Intent intent = new Intent(mFileActivity, OperationsService.class);
+ intent.setAction(OperationsService.ACTION_SYNC_FOLDER);
+ intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ mFileActivity.startService(intent);
+
+ }
+ }
+
+ public void toggleFavorite(OCFile file, boolean isFavorite) {
+ file.setFavorite(isFavorite);
+ mFileActivity.getStorageManager().saveFile(file);
+
+ /// register the OCFile instance in the observer service to monitor local updates
+ Intent observedFileIntent = FileObserverService.makeObservedFileIntent(
+ mFileActivity,
+ file,
+ mFileActivity.getAccount(),
+ isFavorite);
+ mFileActivity.startService(observedFileIntent);
+
+ /// immediate content synchronization
+ if (file.isFavorite()) {
+ syncFile(file);
+ }
+ }
+
+ public void renameFile(OCFile file, String newFilename) {
+ // RenameFile
+ Intent service = new Intent(mFileActivity, OperationsService.class);
+ service.setAction(OperationsService.ACTION_RENAME);
+ service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ service.putExtra(OperationsService.EXTRA_NEWNAME, newFilename);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
+
+ mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
+ getString(R.string.wait_a_moment));
+ }
+
+
+ public void removeFile(OCFile file, boolean onlyLocalCopy) {
+ // RemoveFile
+ Intent service = new Intent(mFileActivity, OperationsService.class);
+ service.setAction(OperationsService.ACTION_REMOVE);
+ service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ service.putExtra(OperationsService.EXTRA_REMOVE_ONLY_LOCAL, onlyLocalCopy);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
+
+ mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
+ getString(R.string.wait_a_moment));
+ }
+
+
+ public void createFolder(String remotePath, boolean createFullPath) {
+ // Create Folder
+ Intent service = new Intent(mFileActivity, OperationsService.class);
+ service.setAction(OperationsService.ACTION_CREATE_FOLDER);
+ service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ service.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);
+ service.putExtra(OperationsService.EXTRA_CREATE_FULL_PATH, createFullPath);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
+
+ mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
+ getString(R.string.wait_a_moment));
+ }
+
+ /**
+ * Cancel the transference in downloads (files/folders) and file uploads
+ * @param file OCFile
+ */
+ public void cancelTransference(OCFile file) {
+ Account account = mFileActivity.getAccount();
+ if (file.isFolder()) {
+ OperationsService.OperationsServiceBinder opsBinder =
+ mFileActivity.getOperationsServiceBinder();
+ if (opsBinder != null) {
+ opsBinder.cancel(account, file);
+ }
+ }
+
+ // for both files and folders
+ FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder();
+ if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
+ downloaderBinder.cancel(account, file);
+ }
+ FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
+ if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
+ uploaderBinder.cancel(account, file);
+ }
+ }
+
+ /**
+ * Start move file operation
+ *
+ * @param newfile File where it is going to be moved
+ * @param currentFile File with the previous info
+ */
+ public void moveFile(OCFile newfile, OCFile currentFile) {
+ // Move files
+ Intent service = new Intent(mFileActivity, OperationsService.class);
+ service.setAction(OperationsService.ACTION_MOVE_FILE);
+ service.putExtra(OperationsService.EXTRA_NEW_PARENT_PATH, newfile.getRemotePath());
+ service.putExtra(OperationsService.EXTRA_REMOTE_PATH, currentFile.getRemotePath());
+ service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
+
+ mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
+ getString(R.string.wait_a_moment));
+ }
+
+ /**
+ * Start copy file operation
+ *
+ * @param newfile File where it is going to be moved
+ * @param currentFile File with the previous info
+ */
+ public void copyFile(OCFile newfile, OCFile currentFile) {
+ // Copy files
+ Intent service = new Intent(mFileActivity, OperationsService.class);
+ service.setAction(OperationsService.ACTION_COPY_FILE);
+ service.putExtra(OperationsService.EXTRA_NEW_PARENT_PATH, newfile.getRemotePath());
+ service.putExtra(OperationsService.EXTRA_REMOTE_PATH, currentFile.getRemotePath());
+ service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
+
+ mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
+ getString(R.string.wait_a_moment));
+ }
+
+ public long getOpIdWaitingFor() {
+ return mWaitingForOpId;
+ }
+
+
+ public void setOpIdWaitingFor(long waitingForOpId) {
+ mWaitingForOpId = waitingForOpId;
+ }
+
+ /**
+ * @return 'True' if the server doesn't need to check forbidden characters
+ */
+ public boolean isVersionWithForbiddenCharacters() {
+ if (mFileActivity.getAccount() != null) {
+ OwnCloudVersion serverVersion =
+ AccountUtils.getServerVersion(mFileActivity.getAccount());
+ return (serverVersion != null && serverVersion.isVersionWithForbiddenCharacters());
+ }
+ return false;
+ }