diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index c58a28e0e0..04d5766bbe 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/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; @@ -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(); } diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 758a2573f1..44661817e8 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/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; diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 75e6eed69a..1387f88ce7 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/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 */ @@ -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); // } - } diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 4e5d0744c8..f1cfd061e1 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/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,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 } } } + } diff --git a/src/com/owncloud/android/ui/activity/UploadListActivity.java b/src/com/owncloud/android/ui/activity/UploadListActivity.java index fdf25b45f7..c50caf50c4 100755 --- a/src/com/owncloud/android/ui/activity/UploadListActivity.java +++ b/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 @@ -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)) { @@ -214,7 +215,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 + FileUploader.retryUploadsForAccount(getAccount(), this); + } + } + @Override protected ServiceConnection newTransferenceServiceConnection() { return new UploadListServiceConnection(); diff --git a/src/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java b/src/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java index 72ec3856a2..c012444870 100755 --- a/src/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java @@ -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) { diff --git a/src/com/owncloud/android/ui/fragment/UploadListFragment.java b/src/com/owncloud/android/ui/fragment/UploadListFragment.java index fe9dafa2d5..8fb3e150dc 100755 --- a/src/com/owncloud/android/ui/fragment/UploadListFragment.java +++ b/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;