Browse Source

if source folder does not exist, still allow to move to new folder

tobiasKaminsky 8 years ago
parent
commit
8ccff56370

+ 5 - 3
src/main/java/com/owncloud/android/operations/DownloadFileOperation.java

@@ -81,9 +81,11 @@ public class DownloadFileOperation extends RemoteOperation {
     }
 
     public String getSavePath() {
-        String path = mFile.getStoragePath();  // re-downloads should be done over the original file
-        if (path != null && path.length() > 0) {
-            return path;
+        if (mFile.getStoragePath() != null) {
+            File path = new File(mFile.getStoragePath());  // re-downloads should be done over the original file
+            if (path.canWrite()) {
+                return path.getAbsolutePath();
+            }
         }
         return FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
     }

+ 31 - 2
src/main/java/com/owncloud/android/ui/activity/StorageMigration.java

@@ -205,8 +205,14 @@ public class StorageMigration {
             if (succeed) {
                 mProgressDialog.hide();
             } else {
-                mProgressDialog.getButton(ProgressDialog.BUTTON_POSITIVE).setVisibility(View.VISIBLE);
-                mProgressDialog.setIndeterminateDrawable(mContext.getResources().getDrawable(R.drawable.image_fail));
+
+                if (code == R.string.file_migration_failed_not_readable) {
+                    mProgressDialog.hide();
+                    askToStillMove();
+                } else {
+                    mProgressDialog.getButton(ProgressDialog.BUTTON_POSITIVE).setVisibility(View.VISIBLE);
+                    mProgressDialog.setIndeterminateDrawable(mContext.getResources().getDrawable(R.drawable.image_fail));
+                }
             }
 
             if (mListener != null) {
@@ -214,6 +220,29 @@ public class StorageMigration {
             }
         }
 
+        private void askToStillMove() {
+
+            new AlertDialog.Builder(mContext)
+                    .setMessage("Source directory not readable. Do you still want to change the storage path to "
+                            + mStorageTarget + "? Note: all data will have to be downloaded again.")
+                    .setNegativeButton(R.string.common_no, new OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialogInterface, int i) {
+                            dialogInterface.dismiss();
+                        }
+                    })
+                    .setPositiveButton(R.string.common_yes, new OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialogInterface, int i) {
+                            if (mListener != null) {
+                                mListener.onStorageMigrationFinished(mStorageTarget, true);
+                            }
+                        }
+                    })
+                    .create()
+                    .show();
+        }
+
         protected boolean[] saveAccountsSyncStatus() {
             boolean[] syncs = new boolean[mOcAccounts.length];
             for (int i = 0; i < mOcAccounts.length; ++i) {

+ 2 - 2
src/main/res/values/strings.xml

@@ -412,8 +412,8 @@
     <string name="file_migration_restoring_accounts_configuration">Restoring configuration of accounts&#8230;</string>
     <string name="file_migration_ok_finished">Finished</string>
     <string name="file_migration_failed_not_enough_space">ERROR: Insufficient space</string>
-    <string name="file_migration_failed_not_writable">ERROR: File not writable</string>
-    <string name="file_migration_failed_not_readable">ERROR: File not readable</string>
+    <string name="file_migration_failed_not_writable">ERROR: Destination file not writable</string>
+    <string name="file_migration_failed_not_readable">ERROR: Source file not readable</string>
     <string name="file_migration_failed_dir_already_exists">ERROR: Nextcloud directory already exists</string>
     <string name="file_migration_failed_while_coping">ERROR: Failed during migration</string>
     <string name="file_migration_failed_while_updating_index">ERROR: Failed to updating index</string>