|
@@ -56,7 +56,9 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
|
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
|
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
|
|
+import com.owncloud.android.operations.CopyFileOperation;
|
|
import com.owncloud.android.operations.CreateFolderOperation;
|
|
import com.owncloud.android.operations.CreateFolderOperation;
|
|
|
|
+import com.owncloud.android.operations.MoveFileOperation;
|
|
import com.owncloud.android.operations.RefreshFolderOperation;
|
|
import com.owncloud.android.operations.RefreshFolderOperation;
|
|
import com.owncloud.android.operations.RemoveFileOperation;
|
|
import com.owncloud.android.operations.RemoveFileOperation;
|
|
import com.owncloud.android.operations.RenameFileOperation;
|
|
import com.owncloud.android.operations.RenameFileOperation;
|
|
@@ -146,7 +148,13 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
|
|
|
|
Account account = currentStorageManager.getAccount();
|
|
Account account = currentStorageManager.getAccount();
|
|
|
|
|
|
- if (Device.getNetworkType(getContext()).equals(JobRequest.NetworkType.UNMETERED)) {
|
|
|
|
|
|
+ Context context = getContext();
|
|
|
|
+
|
|
|
|
+ if (context == null) {
|
|
|
|
+ throw new FileNotFoundException("Context may not be null");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (Device.getNetworkType(context).equals(JobRequest.NetworkType.UNMETERED)) {
|
|
RemoteOperationResult result = new RefreshFolderOperation(browsedDir, System.currentTimeMillis(), false,
|
|
RemoteOperationResult result = new RefreshFolderOperation(browsedDir, System.currentTimeMillis(), false,
|
|
false, true, currentStorageManager, account,
|
|
false, true, currentStorageManager, account,
|
|
getContext()).execute(client);
|
|
getContext()).execute(client);
|
|
@@ -326,6 +334,82 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public String copyDocument(String sourceDocumentId, String targetParentDocumentId) throws FileNotFoundException {
|
|
|
|
+ long sourceId = Long.parseLong(sourceDocumentId);
|
|
|
|
+ long targetId = Long.parseLong(targetParentDocumentId);
|
|
|
|
+ updateCurrentStorageManagerIfNeeded(sourceId);
|
|
|
|
+
|
|
|
|
+ OCFile file = currentStorageManager.getFileById(sourceId);
|
|
|
|
+ OCFile targetFolder = currentStorageManager.getFileById(targetId);
|
|
|
|
+
|
|
|
|
+ if (file == null) {
|
|
|
|
+ throw new FileNotFoundException("File " + sourceDocumentId + " not found!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (targetFolder == null) {
|
|
|
|
+ throw new FileNotFoundException("File " + targetParentDocumentId + " not found!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ RemoteOperationResult result = new CopyFileOperation(file.getRemotePath(), targetFolder.getRemotePath())
|
|
|
|
+ .execute(client, currentStorageManager);
|
|
|
|
+
|
|
|
|
+ if (!result.isSuccess()) {
|
|
|
|
+ throw new FileNotFoundException("Failed to copy document with documentId " + sourceDocumentId
|
|
|
|
+ + " to " + targetParentDocumentId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Account account = currentStorageManager.getAccount();
|
|
|
|
+
|
|
|
|
+ RemoteOperationResult updateParent = new RefreshFolderOperation(targetFolder, System.currentTimeMillis(),
|
|
|
|
+ false, false, true, currentStorageManager,
|
|
|
|
+ account, getContext()).execute(client);
|
|
|
|
+
|
|
|
|
+ if (!updateParent.isSuccess()) {
|
|
|
|
+ throw new FileNotFoundException("Failed to copy document with documentId " + sourceDocumentId
|
|
|
|
+ + " to " + targetParentDocumentId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String newPath = targetFolder.getRemotePath() + file.getFileName();
|
|
|
|
+
|
|
|
|
+ if (file.isFolder()) {
|
|
|
|
+ newPath = newPath + "/";
|
|
|
|
+ }
|
|
|
|
+ OCFile newFile = currentStorageManager.getFileByPath(newPath);
|
|
|
|
+
|
|
|
|
+ return String.valueOf(newFile.getFileId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String moveDocument(String sourceDocumentId, String sourceParentDocumentId, String targetParentDocumentId)
|
|
|
|
+ throws FileNotFoundException {
|
|
|
|
+ long sourceId = Long.parseLong(sourceDocumentId);
|
|
|
|
+ long targetId = Long.parseLong(targetParentDocumentId);
|
|
|
|
+ updateCurrentStorageManagerIfNeeded(sourceId);
|
|
|
|
+
|
|
|
|
+ OCFile file = currentStorageManager.getFileById(sourceId);
|
|
|
|
+
|
|
|
|
+ if (file == null) {
|
|
|
|
+ throw new FileNotFoundException("File " + sourceDocumentId + " not found!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ OCFile targetFolder = currentStorageManager.getFileById(targetId);
|
|
|
|
+
|
|
|
|
+ if (targetFolder == null) {
|
|
|
|
+ throw new FileNotFoundException("File " + targetParentDocumentId + " not found!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ RemoteOperationResult result = new MoveFileOperation(file.getRemotePath(), targetFolder.getRemotePath())
|
|
|
|
+ .execute(client, currentStorageManager);
|
|
|
|
+
|
|
|
|
+ if (!result.isSuccess()) {
|
|
|
|
+ throw new FileNotFoundException("Failed to move document with documentId " + sourceDocumentId
|
|
|
|
+ + " to " + targetParentDocumentId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return String.valueOf(file.getFileId());
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Cursor querySearchDocuments(String rootId, String query, String[] projection) {
|
|
public Cursor querySearchDocuments(String rootId, String query, String[] projection) {
|
|
updateCurrentStorageManagerIfNeeded(rootId);
|
|
updateCurrentStorageManagerIfNeeded(rootId);
|