|
@@ -37,7 +37,6 @@ import android.os.Handler;
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
import android.view.MenuItem;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
-
|
|
|
|
import com.google.common.collect.Sets;
|
|
import com.google.common.collect.Sets;
|
|
import com.nextcloud.client.account.User;
|
|
import com.nextcloud.client.account.User;
|
|
import com.nextcloud.client.account.UserAccountManager;
|
|
import com.nextcloud.client.account.UserAccountManager;
|
|
@@ -45,8 +44,8 @@ import com.nextcloud.client.files.downloader.FileDownloadHelper;
|
|
import com.nextcloud.client.jobs.BackgroundJobManager;
|
|
import com.nextcloud.client.jobs.BackgroundJobManager;
|
|
import com.nextcloud.client.onboarding.FirstRunActivity;
|
|
import com.nextcloud.client.onboarding.FirstRunActivity;
|
|
import com.nextcloud.java.util.Optional;
|
|
import com.nextcloud.java.util.Optional;
|
|
-import com.nextcloud.model.WorkerState;
|
|
|
|
-import com.nextcloud.model.WorkerStateLiveData;
|
|
|
|
|
|
+import com.nextcloud.model.DownloadWorkerState;
|
|
|
|
+import com.nextcloud.model.DownloadWorkerStateLiveData;
|
|
import com.nextcloud.utils.extensions.BundleExtensionsKt;
|
|
import com.nextcloud.utils.extensions.BundleExtensionsKt;
|
|
import com.owncloud.android.MainApp;
|
|
import com.owncloud.android.MainApp;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.R;
|
|
@@ -115,8 +114,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
|
|
private ArbitraryDataProvider arbitraryDataProvider;
|
|
private ArbitraryDataProvider arbitraryDataProvider;
|
|
private boolean multipleAccountsSupported;
|
|
private boolean multipleAccountsSupported;
|
|
|
|
|
|
- private String workerAccountName;
|
|
|
|
- private DownloadFileOperation workerCurrentDownload;
|
|
|
|
|
|
+ private final ArrayList<DownloadWorkerState> downloadWorkerStates = new ArrayList<>();
|
|
|
|
|
|
@Inject BackgroundJobManager backgroundJobManager;
|
|
@Inject BackgroundJobManager backgroundJobManager;
|
|
@Inject UserAccountManager accountManager;
|
|
@Inject UserAccountManager accountManager;
|
|
@@ -165,7 +163,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
|
|
recyclerView.setAdapter(userListAdapter);
|
|
recyclerView.setAdapter(userListAdapter);
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
initializeComponentGetters();
|
|
initializeComponentGetters();
|
|
- observeWorkerState();
|
|
|
|
|
|
+ observeDownloadWorkerState();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -342,7 +340,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
|
|
mUploaderBinder.cancel(accountName);
|
|
mUploaderBinder.cancel(accountName);
|
|
}
|
|
}
|
|
|
|
|
|
- FileDownloadHelper.Companion.instance().cancelAllDownloadsForAccount(workerAccountName, workerCurrentDownload);
|
|
|
|
|
|
+ cancelAllDownloadsForAccount();
|
|
}
|
|
}
|
|
|
|
|
|
User currentUser = getUserAccountManager().getUser();
|
|
User currentUser = getUserAccountManager().getUser();
|
|
@@ -410,6 +408,17 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
|
|
return new ManageAccountsServiceConnection();
|
|
return new ManageAccountsServiceConnection();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void cancelAllDownloadsForAccount() {
|
|
|
|
+ for (DownloadWorkerState workerState : downloadWorkerStates) {
|
|
|
|
+ User currentUser = workerState.getUser();
|
|
|
|
+ DownloadFileOperation currentDownload = workerState.getCurrentDownload();
|
|
|
|
+
|
|
|
|
+ if (currentUser != null && currentDownload != null) {
|
|
|
|
+ FileDownloadHelper.Companion.instance().cancelAllDownloadsForAccount(currentUser.getAccountName(), currentDownload);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void performAccountRemoval(User user) {
|
|
private void performAccountRemoval(User user) {
|
|
// disable account in recycler view
|
|
// disable account in recycler view
|
|
for (int i = 0; i < userListAdapter.getItemCount(); i++) {
|
|
for (int i = 0; i < userListAdapter.getItemCount(); i++) {
|
|
@@ -432,8 +441,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
|
|
mUploaderBinder.cancel(user);
|
|
mUploaderBinder.cancel(user);
|
|
}
|
|
}
|
|
|
|
|
|
- FileDownloadHelper.Companion.instance().cancelAllDownloadsForAccount(workerAccountName, workerCurrentDownload);
|
|
|
|
-
|
|
|
|
|
|
+ cancelAllDownloadsForAccount();
|
|
backgroundJobManager.startAccountRemovalJob(user.getAccountName(), false);
|
|
backgroundJobManager.startAccountRemovalJob(user.getAccountName(), false);
|
|
|
|
|
|
// immediately select a new account
|
|
// immediately select a new account
|
|
@@ -517,13 +525,10 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void observeWorkerState() {
|
|
|
|
- WorkerStateLiveData.Companion.instance().observe(this, state -> {
|
|
|
|
- if (state instanceof WorkerState.Download) {
|
|
|
|
- Log_OC.d(TAG, "Download worker started");
|
|
|
|
- workerAccountName = ((WorkerState.Download) state).getUser().getAccountName();
|
|
|
|
- workerCurrentDownload = ((WorkerState.Download) state).getCurrentDownload();
|
|
|
|
- }
|
|
|
|
|
|
+ private void observeDownloadWorkerState() {
|
|
|
|
+ DownloadWorkerStateLiveData.Companion.instance().observe(this, state -> {
|
|
|
|
+ Log_OC.d(TAG, "Download worker started");
|
|
|
|
+ downloadWorkerStates.addAll(state);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|