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

Fix problems with Credentials error in uploads

masensio 9 жил өмнө
parent
commit
ae5605e55b

+ 9 - 0
src/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -83,6 +83,7 @@ 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;
@@ -925,6 +926,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         } else {
             checkBasicAuthorization();
         }
+
     }
 
 
@@ -1025,6 +1027,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             onGetUserNameFinish(result);
         }
 
+        if (result.isSuccess() && mAction == ACTION_UPDATE_EXPIRED_TOKEN) {
+            setResult(FileActivity.RESULT_OK);
+        }
+
     }
 
     private void onGetUserNameFinish(RemoteOperationResult result) {
@@ -1419,6 +1425,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             }
 
             if (success) {
+                if (mAction == ACTION_UPDATE_EXPIRED_TOKEN) {
+                    setResult(FileActivity.RESULT_OK);
+                }
                 finish();
             }
             

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

@@ -36,7 +36,9 @@ import android.widget.Toast;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.db.OCUpload;
+import com.owncloud.android.db.UploadResult;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.lib.common.network.WebdavUtils;
@@ -541,6 +543,17 @@ 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

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

@@ -1128,6 +1128,7 @@ public class FileUploader extends Service
                         AuthenticatorActivity.EXTRA_ACTION,
                         AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN
                 );
+
                 updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                 updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
@@ -1171,7 +1172,7 @@ public class FileUploader extends Service
 //                }
             }
 
-            if (!uploadResult.isSuccess()) {
+            if (!uploadResult.isSuccess() && !needsToUpdateCredentials ) {
                 //in case of failure, do not show details file view (because there is no file!)
                 Intent showUploadListIntent = new Intent(this, UploadListActivity.class);
                 showUploadListIntent.putExtra(FileActivity.EXTRA_FILE, upload.getFile());
@@ -1266,5 +1267,4 @@ public class FileUploader extends Service
 //        retry(context, null);
 //    }
 
-
 }

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

@@ -35,7 +35,6 @@ import android.content.res.Configuration;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
-
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
@@ -114,6 +113,8 @@ 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;
@@ -833,7 +834,7 @@ public class FileActivity extends AppCompatActivity
                     AuthenticatorActivity.EXTRA_ACTION,
                     AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
             updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-            startActivity(updateAccountCredentials);
+            startActivityForResult(updateAccountCredentials, UPDATE_CREDENTIALS_REQUEST_CODE);
 
         } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
             Toast.makeText(context, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();
@@ -1062,4 +1063,5 @@ public class FileActivity extends AppCompatActivity
             }
         }
     }
+
 }

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

@@ -169,7 +169,6 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
         UploadsStorageManager storageManager = null;
         UploadListFragment uploadListFragment =
                 (UploadListFragment) getSupportFragmentManager().findFragmentByTag(TAG_UPLOAD_LIST_FRAGMENT);
-
         switch (item.getItemId()) {
             case android.R.id.home:
                 if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
@@ -214,7 +213,17 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
         inflater.inflate(R.menu.upload_list_menu, menu);
         return true;
     }
-    
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        Log_OC.e(TAG, "onActivityResult " + resultCode);
+        if (requestCode == UPDATE_CREDENTIALS_REQUEST_CODE && resultCode == FileActivity.RESULT_OK) {
+            // Retry uploads of this account
+            getFileOperationsHelper().retryUploadsForAccount(getAccount());
+        }
+    }
+
     @Override
     protected ServiceConnection newTransferenceServiceConnection() {
         return new UploadListServiceConnection();

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

@@ -42,6 +42,7 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;
 import com.owncloud.android.db.OCUpload;
+import com.owncloud.android.db.UploadResult;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
 import com.owncloud.android.lib.common.utils.Log_OC;
@@ -296,7 +297,8 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                                                 AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
                                         updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                                         updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
-                                        mParentActivity.startActivity(updateAccountCredentials);
+                                        mParentActivity.startActivityForResult(updateAccountCredentials,
+                                                FileActivity.UPDATE_CREDENTIALS_REQUEST_CODE);
                                     }
                                 });
                                 break;
@@ -407,7 +409,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                 });
             }
 
-            if (upload.userCanRetryUpload()) {
+            if (upload.userCanRetryUpload() && upload.getLastResult()!= UploadResult.CREDENTIAL_ERROR) {
                 view.setOnClickListener(new OnClickListener() {
                     @Override
                     public void onClick(View v) {

+ 0 - 2
src/com/owncloud/android/ui/fragment/UploadListFragment.java

@@ -19,9 +19,7 @@
  */
 package com.owncloud.android.ui.fragment;
 
-import android.accounts.Account;
 import android.app.Activity;
-import android.content.Intent;
 import android.os.Bundle;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;