From 042c3758acddc976313a4192af7c133bc0b5dbd1 Mon Sep 17 00:00:00 2001 From: Chris Narkiewicz Date: Sun, 17 Apr 2022 21:48:10 +0100 Subject: [PATCH] Remove account use from ManageAccountsActivity Signed-off-by: Chris Narkiewicz --- .../files/services/FileDownloader.java | 32 ++++------------- .../android/files/services/FileUploader.java | 36 +++++++++---------- .../ui/activity/ManageAccountsActivity.java | 22 ++++++------ 3 files changed, 35 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/files/services/FileDownloader.java b/app/src/main/java/com/owncloud/android/files/services/FileDownloader.java index 7ea1f04057..7f035f8a47 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileDownloader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileDownloader.java @@ -314,20 +314,13 @@ public class FileDownloader extends Service /** * Cancels all the downloads for an account - * - * @param account ownCloud account. */ - public void cancel(Account account) { - Log_OC.d(TAG, "Account= " + account.name); - - if (mCurrentDownload != null) { - Log_OC.d(TAG, "Current Download Account= " + mCurrentDownload.getAccount().name); - if (mCurrentDownload.getAccount().name.equals(account.name)) { - mCurrentDownload.cancel(); - } + public void cancel(String accountName) { + if (mCurrentDownload != null && mCurrentDownload.getUser().nameEquals(accountName)) { + mCurrentDownload.cancel(); } // Cancel pending downloads - cancelDownloadsForAccount(account); + cancelPendingDownloads(accountName); } public void clearListeners() { @@ -491,15 +484,10 @@ public class FileDownloader extends Service /// notify result notifyDownloadResult(mCurrentDownload, downloadResult); - sendBroadcastDownloadFinished(mCurrentDownload, downloadResult, removeResult.second); } - } else { - // Cancel the transfer - Log_OC.d(TAG, "Account " + mCurrentDownload.getAccount() + " doesn't exist"); - cancelDownloadsForAccount(mCurrentDownload.getAccount()); - + cancelPendingDownloads(mCurrentDownload.getUser().getAccountName()); } } } @@ -741,13 +729,7 @@ public class FileDownloader extends Service localBroadcastManager.sendBroadcast(added); } - /** - * Remove downloads of an account - * - * @param account Downloads account to remove - */ - private void cancelDownloadsForAccount(Account account) { - // Cancel pending downloads - mPendingDownloads.remove(account.name); + private void cancelPendingDownloads(String accountName) { + mPendingDownloads.remove(accountName); } } diff --git a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java index f90c8891c8..2c467925e5 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -602,7 +602,7 @@ public class FileUploader extends Service if (!accountManager.exists(mCurrentUpload.getAccount())) { Log_OC.w(TAG, "Account " + mCurrentUpload.getAccount().name + " does not exist anymore -> cancelling all its uploads"); - cancelUploadsForAccount(mCurrentUpload.getAccount()); + cancelPendingUploads(mCurrentUpload.getUser().getAccountName()); return; } @@ -917,16 +917,15 @@ public class FileUploader extends Service } /** - * Remove and 'forgets' pending uploads of an account. + * Remove and 'forgets' pending uploads of a user. * - * @param account Account which uploads will be cancelled + * @param accountName User which uploads will be cancelled */ - private void cancelUploadsForAccount(Account account) { - mPendingUploads.remove(account.name); - mUploadsStorageManager.removeUploads(account.name); + private void cancelPendingUploads(String accountName) { + mPendingUploads.remove(accountName); + mUploadsStorageManager.removeUploads(accountName); } - /** * Upload a new file */ @@ -1187,22 +1186,21 @@ public class FileUploader extends Service } /** - * Cancels all the uploads for an account. + * Cancels all the uploads for a user, both running and pending. * - * @param account ownCloud account. + * @param user Nextcloud user */ - public void cancel(Account account) { - Log_OC.d(TAG, "Account= " + account.name); - - if (mCurrentUpload != null) { - Log_OC.d(TAG, "Current Upload Account= " + mCurrentUpload.getAccount().name); - if (mCurrentUpload.getAccount().name.equals(account.name)) { - mCurrentUpload.cancel(ResultCode.CANCELLED); - } + public void cancel(User user) { + if (mCurrentUpload != null && mCurrentUpload.getUser().nameEquals(user)) { + mCurrentUpload.cancel(ResultCode.CANCELLED); } + cancelPendingUploads(user.getAccountName()); + } - // Cancel pending uploads - cancelUploadsForAccount(account); + public void cancel(String accountName) { + if (mCurrentUpload != null && mCurrentUpload.getUser().nameEquals(accountName)) { + mCurrentUpload.cancel(ResultCode.CANCELLED); + } } public void clearListeners() { diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java index b13e340019..58cf2294f6 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java @@ -330,23 +330,23 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap public void run(AccountManagerFuture future) { if (future.isDone()) { // after remove account - Account account = new Account(accountName, MainApp.getAccountType(this)); - if (!accountManager.exists(account)) { + Optional user = accountManager.getUser(accountName); + if (!user.isPresent()) { // Cancel transfers of the removed account if (mUploaderBinder != null) { - mUploaderBinder.cancel(account); + mUploaderBinder.cancel(accountName); } if (mDownloaderBinder != null) { - mDownloaderBinder.cancel(account); + mDownloaderBinder.cancel(accountName); } } - User user = getUserAccountManager().getUser(); - if (user.isAnonymous()) { + User currentUser = getUserAccountManager().getUser(); + if (currentUser.isAnonymous()) { String accountName = ""; - Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this)); - if (accounts.length != 0) { - accountName = accounts[0].name; + List users = accountManager.getAllUsers(); + if (users.size() > 0) { + accountName = users.get(0).getAccountName(); } accountManager.setCurrentOwnCloudAccount(accountName); } @@ -426,10 +426,10 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap // Cancel transfers if (mUploaderBinder != null) { - mUploaderBinder.cancel(user.toPlatformAccount()); + mUploaderBinder.cancel(user); } if (mDownloaderBinder != null) { - mDownloaderBinder.cancel(user.toPlatformAccount()); + mDownloaderBinder.cancel(user.getAccountName()); } backgroundJobManager.startAccountRemovalJob(user.getAccountName(), false);