Merge pull request #1486 from owncloud/reliable_uploads_actions_uploads_view__credentials_error

Fix problems with Credentials error in uploads
This commit is contained in:
David A. Velasco 2016-02-24 10:46:37 +01:00
commit fcf107005f
7 changed files with 44 additions and 10 deletions

View file

@ -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;
@ -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(Activity.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(Activity.RESULT_OK);
}
finish();
}

View file

@ -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;

View file

@ -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
*/
@ -1128,6 +1140,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 +1184,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 +1279,4 @@ public class FileUploader extends Service
// retry(context, null);
// }
}

View file

@ -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,7 +113,6 @@ public class FileActivity extends AppCompatActivity
protected static final long DELAY_TO_REQUEST_OPERATIONS_LATER = 200;
/** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
private Account mAccount;
@ -1062,4 +1060,5 @@ public class FileActivity extends AppCompatActivity
}
}
}
}

View file

@ -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
@ -169,7 +171,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)) {
@ -215,6 +216,16 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
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
FileUploader.retryUploadsForAccount(getAccount(), this);
}
}
@Override
protected ServiceConnection newTransferenceServiceConnection() {
return new UploadListServiceConnection();

View file

@ -43,10 +43,12 @@ 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;
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;
@ -297,7 +299,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,
UploadListActivity.UPDATE_CREDENTIALS_REQUEST_CODE);
}
});
break;
@ -412,7 +415,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) {

View file

@ -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;