ソースを参照

Changes from code review comments

masensio 9 年 前
コミット
531615c077

+ 3 - 3
src/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -25,6 +25,7 @@ package com.owncloud.android.authentication;
 
 import android.accounts.Account;
 import android.accounts.AccountManager;
+import android.app.Activity;
 import android.app.Dialog;
 import android.content.ComponentName;
 import android.content.Context;
@@ -83,7 +84,6 @@ import com.owncloud.android.operations.GetServerInfoOperation;
 import com.owncloud.android.operations.OAuth2GetAccessToken;
 import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
-import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.dialog.CredentialsDialogFragment;
 import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;
 import com.owncloud.android.ui.dialog.SamlWebViewDialog;
@@ -1028,7 +1028,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         }
 
         if (result.isSuccess() && mAction == ACTION_UPDATE_EXPIRED_TOKEN) {
-            setResult(FileActivity.RESULT_OK);
+            setResult(Activity.RESULT_OK);
         }
 
     }
@@ -1426,7 +1426,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
             if (success) {
                 if (mAction == ACTION_UPDATE_EXPIRED_TOKEN) {
-                    setResult(FileActivity.RESULT_OK);
+                    setResult(Activity.RESULT_OK);
                 }
                 finish();
             }

+ 0 - 11
src/com/owncloud/android/files/FileOperationsHelper.java

@@ -543,17 +543,6 @@ public class FileOperationsHelper {
         }
     }
 
-    public void retryUploadsForAccount(Account account) {
-        UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mFileActivity.getContentResolver());
-        OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
-        for ( OCUpload upload: failedUploads){
-            if (upload.getAccountName().equals(account.name) &&
-                    upload.getLastResult() == UploadResult.CREDENTIAL_ERROR ) {
-                retryUpload(upload);
-            }
-        }
-    }
-
     /**
      * Cancel the transference in downloads (files/folders) and file uploads
      * @param file OCFile

+ 12 - 0
src/com/owncloud/android/files/services/FileUploader.java

@@ -51,6 +51,7 @@ import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;
 import com.owncloud.android.db.OCUpload;
 import com.owncloud.android.db.PreferenceReader;
+import com.owncloud.android.db.UploadResult;
 import com.owncloud.android.lib.common.OwnCloudAccount;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
@@ -257,6 +258,17 @@ public class FileUploader extends Service
         context.startService(i);
     }
 
+    public static void retryUploadsForAccount(Account account, Context context) {
+        UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver());
+        OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
+        for ( OCUpload upload: failedUploads){
+            if (upload.getAccountName().equals(account.name) &&
+                    upload.getLastResult() == UploadResult.CREDENTIAL_ERROR ) {
+                retry(context, account, upload);
+            }
+        }
+    }
+
     /**
      * Call to upload several new files
      */

+ 1 - 4
src/com/owncloud/android/ui/activity/FileActivity.java

@@ -113,9 +113,6 @@ public class FileActivity extends AppCompatActivity
 
     protected static final long DELAY_TO_REQUEST_OPERATIONS_LATER = 200;
 
-    public static final int UPDATE_CREDENTIALS_REQUEST_CODE = 100;
-
-
     /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
     private Account mAccount;
 
@@ -834,7 +831,7 @@ public class FileActivity extends AppCompatActivity
                     AuthenticatorActivity.EXTRA_ACTION,
                     AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
             updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-            startActivityForResult(updateAccountCredentials, UPDATE_CREDENTIALS_REQUEST_CODE);
+            startActivity(updateAccountCredentials);
 
         } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
             Toast.makeText(context, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();

+ 3 - 1
src/com/owncloud/android/ui/activity/UploadListActivity.java

@@ -61,6 +61,8 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
 
     private static final String TAG_UPLOAD_LIST_FRAGMENT = "UPLOAD_LIST_FRAGMENT";
 
+    public static final int UPDATE_CREDENTIALS_REQUEST_CODE = 100;
+
     private UploadMessagesReceiver mUploadMessagesReceiver;
 
     @Override
@@ -220,7 +222,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
         Log_OC.e(TAG, "onActivityResult " + resultCode);
         if (requestCode == UPDATE_CREDENTIALS_REQUEST_CODE && resultCode == FileActivity.RESULT_OK) {
             // Retry uploads of this account
-            getFileOperationsHelper().retryUploadsForAccount(getAccount());
+            FileUploader.retryUploadsForAccount(getAccount(), this);
         }
     }
 

+ 2 - 1
src/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java

@@ -47,6 +47,7 @@ import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.activity.FileActivity;
+import com.owncloud.android.ui.activity.UploadListActivity;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimetypeIconUtil;
 
@@ -298,7 +299,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                                         updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                                         updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
                                         mParentActivity.startActivityForResult(updateAccountCredentials,
-                                                FileActivity.UPDATE_CREDENTIALS_REQUEST_CODE);
+                                                UploadListActivity.UPDATE_CREDENTIALS_REQUEST_CODE);
                                     }
                                 });
                                 break;