Эх сурвалжийг харах

Merge pull request #7867 from nextcloud/ezaquarii/migrate-uri-uploader-to-user-model

Migrate UriUploader to User model
Andy Scherzinger 4 жил өмнө
parent
commit
49cb7f8318

+ 1 - 1
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -1025,7 +1025,7 @@ public class FileDisplayActivity extends FileActivity
                 this,
                 streamsToUpload,
                 remotePath,
-                getAccount(),
+                getUser().orElseThrow(RuntimeException::new),
                 behaviour,
                 false, // Not show waiting dialog while file is being copied from private storage
                 null  // Not needed copy temp task listener

+ 1 - 1
src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java

@@ -916,7 +916,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
             this,
             mStreamsToUpload,
             mUploadPath,
-            getAccount(),
+            getUser().orElseThrow(RuntimeException::new),
             FileUploader.LOCAL_BEHAVIOUR_DELETE,
             true, // Show waiting dialog while file is being copied from private storage
             this  // Copy temp task listener

+ 8 - 7
src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java

@@ -30,6 +30,7 @@ import android.os.AsyncTask;
 import android.provider.DocumentsContract;
 import android.widget.Toast;
 
+import com.nextcloud.client.account.User;
 import com.owncloud.android.R;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
@@ -69,7 +70,7 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
      *
      * Just packages the received parameters in correct order, doesn't check anything about them.
      *
-     * @param   account             OC account to upload the shared files.
+     * @param   user                user uploading shared files
      * @param   sourceUris          Array of "content://" URIs to the files to be uploaded.
      * @param   remotePaths         Array of absolute paths in the OC account to set to the uploaded files.
      * @param   behaviour           Indicates what to do with the local file once uploaded.
@@ -93,7 +94,7 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
      * @return  Correct array of parameters to be passed to {@link #execute(Object[])}
      */
     public static Object[] makeParamsToExecute(
-        Account account,
+        User user,
         Uri[] sourceUris,
         String[] remotePaths,
         int behaviour,
@@ -101,7 +102,7 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
     ) {
 
         return new Object[] {
-            account,
+            user,
             sourceUris,
             remotePaths,
             Integer.valueOf(behaviour),
@@ -119,7 +120,7 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
 
     /**
      * @param params    Params to execute the task; see
-     *                  {@link #makeParamsToExecute(Account, Uri[], String[], int, ContentResolver)}
+     *                  {@link #makeParamsToExecute(User, Uri[], String[], int, ContentResolver)}
      *                  for further details.
      */
     @Override
@@ -133,7 +134,7 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
         Uri currentUri = null;
 
         try {
-            Account account = (Account) params[0];
+            User user = (User) params[0];
             Uri[] uris = (Uri[]) params[1];
             String[] remotePaths = (String[]) params[2];
             int behaviour = (Integer) params[3];
@@ -160,7 +161,7 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
                     }
                 }
 
-                fullTempPath = FileStorageUtils.getTemporalPath(account.name) + currentRemotePath;
+                fullTempPath = FileStorageUtils.getTemporalPath(user.getAccountName()) + currentRemotePath;
                 inputStream = leakedContentResolver.openInputStream(currentUri);
                 File cacheFile = new File(fullTempPath);
                 File tempDir = cacheFile.getParentFile();
@@ -189,7 +190,7 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
                 }
 
                 requestUpload(
-                    account,
+                    user.toPlatformAccount(),
                     fullTempPath,
                     currentRemotePath,
                     behaviour,

+ 10 - 10
src/main/java/com/owncloud/android/ui/helpers/UriUploader.java

@@ -18,11 +18,11 @@
  */
 package com.owncloud.android.ui.helpers;
 
-import android.accounts.Account;
 import android.content.ContentResolver;
 import android.net.Uri;
 import android.os.Parcelable;
 
+import com.nextcloud.client.account.User;
 import com.owncloud.android.R;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.utils.Log_OC;
@@ -58,7 +58,7 @@ public class UriUploader {
     private final int mBehaviour;
 
     private final String mUploadPath;
-    private final Account mAccount;
+    private User user;
     private final boolean mShowWaitingDialog;
 
     private UriUploaderResultCode mCode = UriUploaderResultCode.OK;
@@ -74,7 +74,7 @@ public class UriUploader {
             FileActivity activity,
             List<Parcelable> uris,
             String uploadPath,
-            Account account,
+            User user,
             int behaviour,
             boolean showWaitingDialog,
             CopyAndUploadContentUrisTask.OnCopyTmpFilesTaskListener copyTmpTaskListener
@@ -82,7 +82,7 @@ public class UriUploader {
         mActivity = activity;
         mUrisToUpload = uris;
         mUploadPath = uploadPath;
-        mAccount = account;
+        this.user = user;
         mBehaviour = behaviour;
         mShowWaitingDialog = showWaitingDialog;
         mCopyTmpTaskListener = copyTmpTaskListener;
@@ -156,7 +156,7 @@ public class UriUploader {
     private void requestUpload(String localPath, String remotePath) {
         FileUploader.uploadNewFile(
             mActivity,
-            mAccount,
+            user.toPlatformAccount(),
             localPath,
             remotePath,
             mBehaviour,
@@ -195,11 +195,11 @@ public class UriUploader {
 
         copyTask.execute(
                 CopyAndUploadContentUrisTask.makeParamsToExecute(
-                        mAccount,
-                        sourceUris,
-                        remotePaths,
-                        mBehaviour,
-                        mActivity.getContentResolver()
+                    user,
+                    sourceUris,
+                    remotePaths,
+                    mBehaviour,
+                    mActivity.getContentResolver()
                 )
         );
     }