Remove from database uploads cancelled in batch when an account is removed while uplading

This commit is contained in:
David A. Velasco 2016-03-02 18:38:00 +01:00
parent c5825a4e07
commit 091985650b
2 changed files with 27 additions and 19 deletions

View file

@ -86,8 +86,6 @@ public class UploadsStorageManager extends Observable {
}
;
public UploadsStorageManager(ContentResolver contentResolver) {
if (contentResolver == null) {
throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver");
@ -308,6 +306,27 @@ public class UploadsStorageManager extends Observable {
return result;
}
/**
* Remove all the uploads of a given account from the uploads list.
*
* @param accountName Name of the OC account target of the uploads to remove.
* @return true when one or more upload entries were removed
*/
public int removeUploads(String accountName) {
int result = getDB().delete(
ProviderTableMeta.CONTENT_URI_UPLOADS,
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
new String[]{accountName}
);
Log_OC.d(TAG, "delete returns " + result + " for uploads in " + accountName);
if (result > 0) {
notifyObserversNow();
}
return result;
}
public OCUpload[] getAllStoredUploads() {
return getUploads(null, null);
}

View file

@ -204,7 +204,6 @@ public class FileUploader extends Service
Boolean createRemoteFolder,
int createdBy
) {
Log_OC.d(TAG, "FileUploader.uploadNewFile()");
Intent intent = new Intent(context, FileUploader.class);
intent.putExtra(FileUploader.KEY_ACCOUNT, account);
@ -241,7 +240,6 @@ public class FileUploader extends Service
*/
public void uploadUpdate(Context context, Account account, OCFile[] existingFiles, Integer behaviour,
Boolean forceOverwrite) {
Log_OC.d(TAG, "FileUploader.uploadUpdate()");
Intent intent = new Intent(context, FileUploader.class);
intent.putExtra(FileUploader.KEY_ACCOUNT, account);
@ -276,7 +274,6 @@ public class FileUploader extends Service
* Call to retry upload identified by remotePath
*/
public void retry(Context context, Account account, OCUpload upload) {
Log_OC.d(TAG, "FileUploader.retry()");
Intent i = new Intent(context, FileUploader.class);
i.putExtra(FileUploader.KEY_RETRY, true);
if (upload != null) {
@ -583,7 +580,7 @@ public class FileUploader extends Service
* @param file A file in the queue of pending uploads
*/
public void cancel(Account account, OCFile file) {
cancel(account.name, file.getRemotePath(), file.getStoragePath());
cancel(account.name, file.getRemotePath());
}
/**
@ -592,7 +589,7 @@ public class FileUploader extends Service
* @param storedUpload Upload operation persisted
*/
public void cancel(OCUpload storedUpload) {
cancel(storedUpload.getAccountName(), storedUpload.getRemotePath(), storedUpload.getLocalPath());
cancel(storedUpload.getAccountName(), storedUpload.getRemotePath());
}
/**
@ -600,9 +597,8 @@ public class FileUploader extends Service
*
* @param accountName Local name of an ownCloud account where the remote file will be stored.
* @param remotePath Remote target of the upload
* @param localPath Absolute local path to the source file
*/
private void cancel(String accountName, String remotePath, String localPath) {
private void cancel(String accountName, String remotePath) {
Pair<UploadFileOperation, String> removeResult =
mPendingUploads.remove(accountName, remotePath);
UploadFileOperation upload = removeResult.first;
@ -1115,20 +1111,13 @@ public class FileUploader extends Service
}
/**
* Remove uploads of an account
* Remove and 'forgets' pending uploads of an account.
*
* @param account Downloads account to remove
* @param account Account which uploads will be cancelled
*/
private void cancelUploadsForAccount(Account account) {
// Cancel pending uploads
mPendingUploads.remove(account.name);
mUploadsStorageManager.removeUploads(account.name);
}
/**
* Call if all pending uploads are to be retried.
*/
// public static void retry(Context context) {
// retry(context, null);
// }
}