Fixed restart of cancelled download

This commit is contained in:
David A. Velasco 2014-05-19 10:35:49 +02:00
parent 8417810079
commit 97b36b2335
4 changed files with 35 additions and 33 deletions

View file

@ -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;
@ -245,6 +248,19 @@ public class FileOperationsHelper {
}
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;
}
}

View file

@ -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;

View file

@ -1430,15 +1430,20 @@ 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 {
if (!file.fileExists()) {
cleanSecondFragment();
} else {
((FileDetailFragment)details).updateFileDetails(false, true);
}
}
}
}
private void requestForDownload() {
@ -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 {
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);
}
}
}
}

View file

@ -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: