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 org.apache.http.protocol.HTTP;
import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
@ -28,6 +29,8 @@ import android.widget.Toast;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile; 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.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.network.WebdavUtils; 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() { public long getOpIdWaitingFor() {
return mWaitingForOpId; return mWaitingForOpId;
} }
@ -253,4 +269,6 @@ public class FileOperationsHelper {
public void setOpIdWaitingFor(long waitingForOpId) { public void setOpIdWaitingFor(long waitingForOpId) {
mWaitingForOpId = waitingForOpId; mWaitingForOpId = waitingForOpId;
} }
} }

View file

@ -18,15 +18,12 @@
package com.owncloud.android.ui.activity; package com.owncloud.android.ui.activity;
import org.apache.commons.httpclient.Credentials;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback; import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture; import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException; import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException; import android.accounts.OperationCanceledException;
import android.app.PendingIntent;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; 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.FileUploader;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; 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.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;

View file

@ -1430,12 +1430,17 @@ FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener
*/ */
@Override @Override
public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) { public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
refreshListOfFilesFragment();
FileFragment details = getSecondFragment(); FileFragment details = getSecondFragment();
if (details != null && details instanceof FileDetailFragment && file.equals(details.getFile()) ) { if (details != null && details instanceof FileDetailFragment && file.equals(details.getFile()) ) {
if (downloading || uploading) { if (downloading || uploading) {
((FileDetailFragment)details).updateFileDetails(file, getAccount()); ((FileDetailFragment)details).updateFileDetails(file, getAccount());
} else { } 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) { public void cancelTransference(OCFile file) {
Account account = getAccount(); getFileOperationsHelper().cancelTransference(file);
if (mDownloaderBinder != null && mDownloaderBinder.isDownloading(account, file)) { if (mWaitingToPreview != null &&
mDownloaderBinder.cancel(account, file); mWaitingToPreview.getRemotePath().equals(file.getRemotePath())) {
refreshListOfFilesFragment(); mWaitingToPreview = null;
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);
}
} }
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) { public void onClick(View v) {
switch (v.getId()) { switch (v.getId()) {
case R.id.cancelBtn: { case R.id.cancelBtn: {
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); mContainerActivity.getFileOperationsHelper().cancelTransference(getFile());
if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) { getActivity().finish();
downloaderBinder.cancel(mAccount, getFile());
getActivity().finish(); // :)
/*
leaveTransferProgress();
if (mFile.isDown()) {
setButtonsForDown();
} else {
setButtonsForRemote();
}
*/
}
break; break;
} }
default: default: