mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 06:05:42 +03:00
Merge pull request #494 from owncloud/fixed_restart_of_cancelled_download_after_changing_device_orientation
Fixed restart of cancelled download after changing device orientation
This commit is contained in:
commit
fa97fe545f
3 changed files with 35 additions and 29 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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1433,12 +1433,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1576,22 +1581,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