mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 06:05:42 +03:00
Fixed restart of cancelled download
This commit is contained in:
parent
8417810079
commit
97b36b2335
4 changed files with 35 additions and 33 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue