Prechádzať zdrojové kódy

Retry all failed uploads when option item 'retry failed' is tapped

David A. Velasco 9 rokov pred
rodič
commit
7980afbef8

+ 1 - 1
src/com/owncloud/android/files/services/ConnectivityActionReceiver.java

@@ -163,7 +163,7 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
                 ) {
             Log_OC.d(TAG, "Requesting retry of instant uploads (& friends)");
             FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
-            requester.retryUploads(
+            requester.retryFailedUploads(
                     context,
                     null,
                     UploadResult.NETWORK_CONNECTION

+ 18 - 13
src/com/owncloud/android/files/services/FileUploader.java

@@ -275,23 +275,28 @@ public class FileUploader extends Service
         }
 
         /**
-         * TODO - improve interface, but now just recovering basic auto-retry of instant uploads on Wifi connection
+         * Retry a subset of all the stored failed uploads.
          *
-         * @param context
-         * @param account           Null to retry uploads in current account
-         * @param uploadResult
+         * @param context           Caller {@link Context}
+         * @param account           If not null, only failed uploads to this OC account will be retried; otherwise,
+         *                          uploads of all accounts will be retried.
+         * @param uploadResult      If not null, only failed uploads with the result specified will be retried;
+         *                          otherwise, failed uploads due to any result will be retried.
          */
-        public void retryUploads(Context context, Account account, UploadResult uploadResult) {
+        public void retryFailedUploads(Context context, Account account, UploadResult uploadResult) {
             UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver());
             OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
-            if (account == null) {
-                account = AccountUtils.getCurrentOwnCloudAccount(context);
-            }
-            for ( OCUpload upload: failedUploads){
-                if (upload.getAccountName().equals(account.name) &&
-                        upload.getLastResult() == uploadResult ) {
-
-                    retry(context, account, upload);
+            Account currentAccount = null;
+            boolean resultMatch, accountMatch;
+            for ( OCUpload failedUpload: failedUploads) {
+                accountMatch = (account == null || account.name.equals(failedUpload.getAccountName()));
+                resultMatch = (uploadResult == null || uploadResult.equals(failedUpload.getLastResult()));
+                if (accountMatch && resultMatch) {
+                    if (currentAccount == null ||
+                            !currentAccount.name.equals(failedUpload.getAccountName())) {
+                        currentAccount = failedUpload.getAccount(context);
+                    }
+                    retry(context, currentAccount, failedUpload);
                 }
             }
         }

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

@@ -183,10 +183,10 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
                     mDrawerLayout.openDrawer(GravityCompat.START);
                 }
                 break;
-//            case R.id.action_retry_uploads:
-//                Log_OC.d(TAG, "FileUploader.retry() called by onMenuItemSelected()");
-//                FileUploader.retry(this);
-//                break;
+            case R.id.action_retry_uploads:
+                FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
+                requester.retryFailedUploads(this, null, null);
+                break;
 
             case R.id.action_clear_failed_uploads:
                 storageManager = new UploadsStorageManager(getContentResolver());
@@ -227,7 +227,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
         if (requestCode == UPDATE_CREDENTIALS_REQUEST_CODE && resultCode == FileActivity.RESULT_OK) {
             // Retry uploads of this account
             FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
-            requester.retryUploads(this, getAccount(), UploadResult.CREDENTIAL_ERROR);
+            requester.retryFailedUploads(this, getAccount(), UploadResult.CREDENTIAL_ERROR);
         }
     }