Procházet zdrojové kódy

Start MoveFileOperation when 'Choose' button is clicked [Work In
Progress!]

David A. Velasco před 10 roky
rodič
revize
7d0e39f730

+ 44 - 21
src/com/owncloud/android/operations/MoveFileOperation.java

@@ -24,6 +24,7 @@ import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation;
 import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.utils.FileStorageUtils;
@@ -45,6 +46,7 @@ public class MoveFileOperation extends SyncOperation {
     private Account mAccount;
     private String mNewParentPath;
     private OCFile mFile;
+    private String mNewPath;
 
     
     
@@ -59,7 +61,9 @@ public class MoveFileOperation extends SyncOperation {
         mPath = path;
         mNewParentPath = newParentPath;
         mAccount = account;
+        
         mFile = null;
+        mNewPath = "";
     }
   
     public OCFile getFile() {
@@ -75,46 +79,59 @@ public class MoveFileOperation extends SyncOperation {
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
         RemoteOperationResult result = null;
+
         
         mFile = getStorageManager().getFileByPath(mPath);
         
-        // check if the new name is valid in the local file system
         try {
-            String parentPath = (new File(mFile.getRemotePath())).getParent();
-            parentPath = (parentPath.endsWith(OCFile.PATH_SEPARATOR)) 
-                    ? parentPath 
-                    : parentPath + OCFile.PATH_SEPARATOR;
+            /// 1. check move validity
             
-            String mNewPath = mNewParentPath + mFile.getFileName();
-            if (mFile.isFolder() && !mNewPath.endsWith(OCFile.PATH_SEPARATOR)) {
-                mNewPath += OCFile.PATH_SEPARATOR;
-            }
-
-            // check local overwrite
-            if (getStorageManager().getFileByPath(mPath) != null) {
-                return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
-            }
             
+            /// 2. remove move 
             MoveRemoteFileOperation operation = new MoveRemoteFileOperation(
                     mFile.getRemotePath(), 
                     mNewPath, 
-                    mFile.isFolder()
+                    false
             );
             result = operation.execute(client);
 
+            
+            /// 3. local move
             if (result.isSuccess()) {
+                //moveLocaly();
+                /*
                 if (mFile.isFolder()) {
                     saveLocalDirectory();
 
                 } else {
                     saveLocalFile();
                 }
+                */
+            }
+            
+            
+            String parentPath = (new File(mFile.getRemotePath())).getParent();
+            parentPath = (parentPath.endsWith(OCFile.PATH_SEPARATOR)) 
+                    ? parentPath 
+                    : parentPath + OCFile.PATH_SEPARATOR;
+            
+            mNewPath = mNewParentPath + mFile.getFileName();
+            if (mFile.isFolder() && !mNewPath.endsWith(OCFile.PATH_SEPARATOR)) {
+                mNewPath += OCFile.PATH_SEPARATOR;
+            }
+
+            // check local overwrite
+            if (getStorageManager().getFileByPath(mPath) != null) {
+                return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
             }
             
+            /*
         } catch (IOException e) {
             Log_OC.e(TAG, "Move " + mFile.getRemotePath() + " to " + 
                     (mNewParentPath==null) + ": " + 
-                    ((result!= null) ? result.getLogMessage() : ""), e);
+                    ((result!= null) ? result.getLogMessage() : ""), e);*/
+        } finally {
+            
         }
 
         return result;
@@ -122,25 +139,26 @@ public class MoveFileOperation extends SyncOperation {
 
     
     private void saveLocalDirectory() {
-        getStorageManager().moveFolder(mFile, mNewParentPath);
+        getStorageManager().moveFolder(mFile, mNewPath);
         String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
         File localDir = new File(localPath);
         if (localDir.exists()) {
-            localDir.renameTo(new File(FileStorageUtils.getSavePath(mAccount.name) + mNewParentPath));
+            localDir.renameTo(new File(FileStorageUtils.getSavePath(mAccount.name) + mNewPath));
             // TODO - if renameTo fails, children files that are already down will result unlinked
         }
     }
 
     private void saveLocalFile() {
-        mFile.setFileName(mNewName);
+        /*
+        mFile.setRFileName(mNewName);   <<< NO >
         
-        // try to rename the local copy of the file
+        // try to move the local copy of the file
         if (mFile.isDown()) {
             File f = new File(mFile.getStoragePath());
             String parentStoragePath = f.getParent();
             if (!parentStoragePath.endsWith(File.separator))
                 parentStoragePath += File.separator;
-            if (f.renameTo(new File(parentStoragePath + mNewName))) {
+            if (f.renameTo(new File())) {
                 mFile.setStoragePath(parentStoragePath + mNewName);
             }
             // else - NOTHING: the link to the local file is kept although the local name can't be updated
@@ -148,6 +166,7 @@ public class MoveFileOperation extends SyncOperation {
         }
         
         getStorageManager().saveFile(mFile);
+        */
     }
 
     /**
@@ -166,6 +185,9 @@ public class MoveFileOperation extends SyncOperation {
      * @throws IOException  When the temporal folder can not be created.
      */
     private boolean isValidNewName() throws IOException {
+        
+        return true;
+        /*
         // check tricky names
         if (mNewName == null || mNewName.length() <= 0 || mNewName.contains(File.separator) || mNewName.contains("%")) { 
             return false;
@@ -190,6 +212,7 @@ public class MoveFileOperation extends SyncOperation {
         testFile.delete();
         
         return result;
+        */
     }
 
 }

+ 7 - 6
src/com/owncloud/android/ui/activity/MoveActivity.java

@@ -44,6 +44,7 @@ import com.actionbarsherlock.view.MenuInflater;
 import com.actionbarsherlock.view.MenuItem;
 import com.actionbarsherlock.view.Window;
 import com.owncloud.android.R;
+import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudAccount;
 import com.owncloud.android.lib.common.OwnCloudClient;
@@ -364,12 +365,12 @@ public class MoveActivity extends HookActivity implements FileFragment.Container
         if (v == mCancelBtn) {
             finish();
         } else if (v == mChooseBtn) {
-            // TODO request to move, OR save selected folder as a result and let request for caller
-            Toast.makeText( MoveActivity.this, 
-                            "TODO: MOVE IMPLEMENTATION", 
-                            Toast.LENGTH_LONG)
-                .show();
-            finish();
+            ComponentsGetter cg = (ComponentsGetter)getSherlockActivity();
+            FileDataStorageManager storageManager = cg.getStorageManager();
+            if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
+                cg.getFileOperationsHelper().removeFile(mTargetFile, false);
+            }
+            cg.getFileOperationsHelper.moveFile(m)
         }
     }