OC-1990: Isolate code from RenameFileOperation to remove dependecies on local storage...
authormasensio <masensio@solidgear.es>
Thu, 14 Nov 2013 16:44:23 +0000 (17:44 +0100)
committermasensio <masensio@solidgear.es>
Thu, 14 Nov 2013 16:44:23 +0000 (17:44 +0100)
oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java
oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java
oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java
src/com/owncloud/android/files/services/FileUploader.java
src/com/owncloud/android/operations/RenameFileOperation.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

index 5ee07d7..f25c22e 100644 (file)
@@ -56,11 +56,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
         RemoteOperationResult result = null;
         MkColMethod mkcol = null;
         
-<<<<<<< HEAD
-        boolean noInvalidChars = FileUtils.validateName(mRemotePath, true);
-=======
         boolean noInvalidChars = FileUtils.validateName(mFolderName);
->>>>>>> refactor_remote_operation_to_create_folder
         if (noInvalidChars) {
                try {
                        mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
index 799ce2f..05a58e2 100644 (file)
@@ -29,7 +29,6 @@ public class RenameRemoteFileOperation extends RemoteOperation {
     private String mOldRemotePath;
     private String mNewName;
     private String mNewRemotePath;
-    private boolean mIsFolder;
     
     
     /**
@@ -40,12 +39,11 @@ public class RenameRemoteFileOperation extends RemoteOperation {
      * @param newName                  New name to set as the name of file.
      * @param newRemotePath            New remote path to move the file, for folders it starts and ends by "/"
      */
-       public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName, String newRemotePath, boolean isFolder) {
+       public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName, String newRemotePath) {
                mOldName = oldName;
                mOldRemotePath = oldRemotePath;
                mNewName = newName;
                mNewRemotePath = newRemotePath;
-               mIsFolder = isFolder;
        }
 
         /**
@@ -59,12 +57,7 @@ public class RenameRemoteFileOperation extends RemoteOperation {
                
                LocalMoveMethod move = null;
         
-        boolean noInvalidChars = true; 
-        
-        if (mIsFolder)
-               noInvalidChars = FileUtils.validateName(mNewRemotePath, mIsFolder);
-        else
-               noInvalidChars =  FileUtils.validateName(mNewName, mIsFolder);
+        boolean noInvalidChars = FileUtils.validateName(mNewName);
         
         if (noInvalidChars) {
         try {
index 1ba399b..75bd566 100644 (file)
@@ -20,15 +20,11 @@ public class FileUtils {
         * @param fileName
         * @return
         */
-       public static boolean validateName(String fileName, boolean isFolder) {
+       public static boolean validateName(String fileName) {
                boolean result = true;
                
                Log.d("FileUtils", "fileName ======= " + fileName);
-               String name = fileName.substring(1);
-               if (isFolder) {
-                       name = name.substring(0, name.length() - 1);
-               }
-               if (name.contains("/") || fileName.contains("\\") || fileName.contains("<") || 
+               if (fileName.contains("/") || fileName.contains("\\") || fileName.contains("<") || 
                                fileName.contains(">") || fileName.contains(":") || fileName.contains("\"") || 
                                fileName.contains("|") || fileName.contains("?") || fileName.contains("*")) {
                        result = false;
index 6e80fd5..e8dcf94 100644 (file)
@@ -33,9 +33,7 @@ import org.apache.jackrabbit.webdav.DavConstants;
 import org.apache.jackrabbit.webdav.MultiStatus;
 import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
 
-import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
-import com.owncloud.android.authentication.AccountAuthenticator;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
index 1eecfc2..69ca2f2 100644 (file)
@@ -100,7 +100,7 @@ public class RenameFileOperation extends RemoteOperation {
             }
         
         RenameRemoteFileOperation operation = new RenameRemoteFileOperation(mFile.getFileName(), mFile.getRemotePath(), mNewName, 
-                mNewRemotePath, mFile.isFolder());
+                mNewRemotePath);
         result = operation.execute(client);
 
         if (result.isSuccess()) {
index 199f8c2..2ec9f2e 100644 (file)
@@ -1375,6 +1375,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                 Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG); 
                 msg.show();
                 // TODO throw again the new rename dialog
+            } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
+                Toast msg = Toast.makeText(this, R.string.create_dir_fail_msg_invalid_characters, Toast.LENGTH_LONG); 
+                msg.show();
             } else {
                 Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG); 
                 msg.show();
index 01ef8d0..66febdf 100644 (file)
@@ -816,6 +816,9 @@ public class FileDetailFragment extends FileFragment implements
                 Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); 
                 msg.show();
                 // TODO throw again the new rename dialog
+            } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
+                Toast msg = Toast.makeText(getActivity(), R.string.create_dir_fail_msg_invalid_characters, Toast.LENGTH_LONG);
+                msg.show();
             } else {
                 Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); 
                 msg.show();