From 97b36b23359f29ee77e91c48ee79f11edb91c5c9 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 19 May 2014 10:35:49 +0200 Subject: [PATCH] Fixed restart of cancelled download --- .../android/files/FileOperationsHelper.java | 18 +++++++++++ .../android/ui/activity/FileActivity.java | 4 --- .../ui/activity/FileDisplayActivity.java | 31 +++++++++---------- .../ui/preview/FileDownloadFragment.java | 15 ++------- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 73d598cfd2..c473c0f086 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -19,6 +19,7 @@ package com.owncloud.android.files; import org.apache.http.protocol.HTTP; +import android.accounts.Account; import android.accounts.AccountManager; import android.content.Intent; import android.net.Uri; @@ -28,6 +29,8 @@ import android.widget.Toast; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; +import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.network.WebdavUtils; @@ -244,6 +247,19 @@ public class FileOperationsHelper { mFileActivity.showLoadingDialog(); } + + public void cancelTransference(OCFile file) { + Account account = mFileActivity.getAccount(); + FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder(); + if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) { + downloaderBinder.cancel(account, file); + + } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) { + uploaderBinder.cancel(account, file); + } + } + public long getOpIdWaitingFor() { return mWaitingForOpId; @@ -253,4 +269,6 @@ public class FileOperationsHelper { public void setOpIdWaitingFor(long waitingForOpId) { mWaitingForOpId = waitingForOpId; } + + } diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index eda47843ac..bebc14374d 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -18,15 +18,12 @@ package com.owncloud.android.ui.activity; -import org.apache.commons.httpclient.Credentials; - import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AccountManagerCallback; import android.accounts.AccountManagerFuture; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; -import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -51,7 +48,6 @@ import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; -import com.owncloud.android.lib.common.network.BearerCredentials; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 6cfa56c567..4ba06d10d7 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1430,12 +1430,17 @@ FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener */ @Override public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) { + refreshListOfFilesFragment(); FileFragment details = getSecondFragment(); if (details != null && details instanceof FileDetailFragment && file.equals(details.getFile()) ) { if (downloading || uploading) { ((FileDetailFragment)details).updateFileDetails(file, getAccount()); } else { - ((FileDetailFragment)details).updateFileDetails(false, true); + if (!file.fileExists()) { + cleanSecondFragment(); + } else { + ((FileDetailFragment)details).updateFileDetails(false, true); + } } } } @@ -1571,22 +1576,16 @@ FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener public void cancelTransference(OCFile file) { - Account account = getAccount(); - if (mDownloaderBinder != null && mDownloaderBinder.isDownloading(account, file)) { - mDownloaderBinder.cancel(account, file); - refreshListOfFilesFragment(); - onTransferStateChanged(file, false, false); - - } else if (mUploaderBinder != null && mUploaderBinder.isUploading(account, file)) { - mUploaderBinder.cancel(account, file); - refreshListOfFilesFragment(); - if (!file.fileExists()) { - cleanSecondFragment(); - - } else { - onTransferStateChanged(file, false, false); - } + getFileOperationsHelper().cancelTransference(file); + if (mWaitingToPreview != null && + mWaitingToPreview.getRemotePath().equals(file.getRemotePath())) { + mWaitingToPreview = null; } + if (mWaitingToSend != null && + mWaitingToSend.getRemotePath().equals(file.getRemotePath())) { + mWaitingToSend = null; + } + onTransferStateChanged(file, false, false); } } diff --git a/src/com/owncloud/android/ui/preview/FileDownloadFragment.java b/src/com/owncloud/android/ui/preview/FileDownloadFragment.java index 65c5d872fc..849afaf204 100644 --- a/src/com/owncloud/android/ui/preview/FileDownloadFragment.java +++ b/src/com/owncloud/android/ui/preview/FileDownloadFragment.java @@ -187,19 +187,8 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene public void onClick(View v) { switch (v.getId()) { case R.id.cancelBtn: { - FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); - if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) { - downloaderBinder.cancel(mAccount, getFile()); - getActivity().finish(); // :) - /* - leaveTransferProgress(); - if (mFile.isDown()) { - setButtonsForDown(); - } else { - setButtonsForRemote(); - } - */ - } + mContainerActivity.getFileOperationsHelper().cancelTransference(getFile()); + getActivity().finish(); break; } default: