);
Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
"Removing download of " + file.getRemotePath());*/
- Pair<DownloadFileOperation, String> removeResult = mPendingDownloads.remove(account, file.getRemotePath());
+ Pair<DownloadFileOperation, String> removeResult =
+ mPendingDownloads.remove(account, file.getRemotePath());
DownloadFileOperation download = removeResult.first;
if (download != null) {
/*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
boundListener.onTransferProgress(progressRate, totalTransferredSoFar, totalToTransfer, fileName);
}
}
+
+ /**
+ * Review downloads and cancel it if its account doesn't exist
+ */
+ public void reviewDownloads() {
+ if (mCurrentDownload != null &&
+ !AccountUtils.exists(mCurrentDownload.getAccount(), getApplicationContext())) {
+ mCurrentDownload.cancel();
+ }
+ // The rest of downloads are cancelled when they try to start
+ }
}
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
+import android.accounts.OnAccountsUpdateListener;
import android.accounts.OperationCanceledException;
import android.content.ComponentName;
import android.content.Context;
*
* @author David A. Velasco
*/
-public class FileActivity extends SherlockFragmentActivity
-implements OnRemoteOperationListener, ComponentsGetter {
+public class FileActivity extends SherlockFragmentActivity
+ implements OnRemoteOperationListener, ComponentsGetter, OnAccountsUpdateListener {
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
public static final String TAG = FileActivity.class.getSimpleName();
private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
- private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";;
+ private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";
protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200;
if (mUploadServiceConnection != null) {
bindService(new Intent(this, FileUploader.class), mUploadServiceConnection, Context.BIND_AUTO_CREATE);
}
+
+ // add AccountsUpdatedListener
+ AccountManager am = AccountManager.get(getApplicationContext());
+ am.addOnAccountsUpdatedListener(this, null, false);
}
unbindService(mUploadServiceConnection);
mUploadServiceConnection = null;
}
+
+ // remove AccountsUpdatedListener
+ AccountManager am = AccountManager.get(getApplicationContext());
+ am.removeOnAccountsUpdatedListener(this);
+
super.onDestroy();
}
* to create a new ownCloud {@link Account}.
*
* POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}.
- *
- * @return 'True' if the checked {@link Account} was valid.
*/
private void swapToDefaultAccount() {
// default to the most recently used account
this,
new AccountCreationCallback(),
null);
+ am.addOnAccountsUpdatedListener(this, null, true);
}
protected ServiceConnection newTransferenceServiceConnection() {
return null;
}
-
+
+ @Override
+ public void onAccountsUpdated(Account[] accounts) {
+ // detect a change in the list of accounts
+ Log_OC.d(TAG, "onAccountsUpdated");
+ mDownloaderBinder.reviewDownloads();
+ mUploaderBinder.reviewUploads();
+ }
+
/**
* Helper class handling a callback from the {@link AccountManager} after the creation of