Browse Source

create new folder

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 6 years ago
parent
commit
3d6c57abbe

+ 30 - 0
src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -53,6 +53,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.operations.CreateFolderOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.ui.activity.ConflictsResolveActivity;
 import com.owncloud.android.ui.activity.Preferences;
@@ -270,6 +271,35 @@ public class DocumentsStorageProvider extends DocumentsProvider {
         return result;
     }
 
+    @Override
+    public String createDocument(String documentId, String mimeType, String displayName) throws FileNotFoundException {
+        long docId = Long.parseLong(documentId);
+        updateCurrentStorageManagerIfNeeded(docId);
+
+        OCFile parent = currentStorageManager.getFileById(docId);
+        Account account = currentStorageManager.getAccount();
+
+        if (parent == null) {
+            throw new FileNotFoundException("Parent file not found");
+        }
+
+        CreateFolderOperation createFolderOperation = new CreateFolderOperation(parent.getRemotePath() + displayName
+                                                                                    + "/", true);
+        RemoteOperationResult result = createFolderOperation.execute(client, currentStorageManager);
+
+
+        if (!result.isSuccess()) {
+            throw new FileNotFoundException("Failed to create document with name " +
+                                                displayName + " and documentId " + documentId);
+        }
+
+
+        String newDirPath = parent.getRemotePath() + displayName + "/";
+        OCFile newFolder = currentStorageManager.getFileByPath(newDirPath);
+
+        return String.valueOf(newFolder.getFileId());
+    }
+
     @SuppressLint("LongLogTag")
     private void updateCurrentStorageManagerIfNeeded(long docId) {
         if (rootIdToStorageManager == null) {

+ 4 - 0
src/main/java/org/nextcloud/providers/cursors/FileCursor.java

@@ -51,6 +51,10 @@ public class FileCursor extends MatrixCursor {
         final String imagePath = MimeTypeUtil.isImage(file) && file.isDown() ? file.getStoragePath() : null;
         int flags = imagePath != null ? Document.FLAG_SUPPORTS_THUMBNAIL : 0;
 
+        if (file.isFolder()) {
+            flags = flags | Document.FLAG_DIR_SUPPORTS_CREATE;
+        }
+
         newRow().add(Document.COLUMN_DOCUMENT_ID, Long.toString(file.getFileId()))
                 .add(Document.COLUMN_DISPLAY_NAME, file.getFileName())
                 .add(Document.COLUMN_LAST_MODIFIED, file.getModificationTimestamp())

+ 8 - 8
src/main/java/org/nextcloud/providers/cursors/RootCursor.java

@@ -1,4 +1,4 @@
-/**
+/*
  *   nextCloud Android client application
  *
  *   @author Bartosz Przybylski
@@ -49,13 +49,13 @@ public class RootCursor extends MatrixCursor {
         final FileDataStorageManager manager =
                 new FileDataStorageManager(account, context.getContentResolver());
         final OCFile mainDir = manager.getFileByPath("/");
-        newRow().add(Root.COLUMN_ROOT_ID, account.name)
-                .add(Root.COLUMN_DOCUMENT_ID, mainDir.getFileId())
-                .add(Root.COLUMN_SUMMARY, account.name)
-                .add(Root.COLUMN_TITLE, context.getString(R.string.app_name))
-                .add(Root.COLUMN_ICON, R.mipmap.ic_launcher)
-                .add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_SEARCH);
 
+        newRow().add(Root.COLUMN_ROOT_ID, account.name)
+            .add(Root.COLUMN_DOCUMENT_ID, mainDir.getFileId())
+            .add(Root.COLUMN_SUMMARY, account.name)
+            .add(Root.COLUMN_TITLE, context.getString(R.string.app_name))
+            .add(Root.COLUMN_ICON, R.mipmap.ic_launcher)
+            .add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_RECENTS |
+                Root.FLAG_SUPPORTS_SEARCH);
     }
-
 }